-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(discover): add basic elastic-charts bar chart to discover
- Loading branch information
Emma Cunningham
committed
May 21, 2019
1 parent
d4c51ff
commit ef8310b
Showing
6 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/legacy/core_plugins/kibana/public/discover/components/histogram/directive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import 'ngreact'; | ||
import { uiModules } from 'ui/modules'; | ||
import { DiscoverHistogram } from './histogram'; | ||
|
||
import { wrapInI18nContext } from 'ui/i18n'; | ||
|
||
const app = uiModules.get('apps/discover', ['react']); | ||
|
||
app.directive('discoverHistogram', reactDirective => reactDirective(wrapInI18nContext(DiscoverHistogram))); |
133 changes: 133 additions & 0 deletions
133
src/legacy/core_plugins/kibana/public/discover/components/histogram/histogram.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
AnnotationDomainTypes, | ||
Axis, | ||
BarSeries, | ||
Chart, | ||
getAnnotationId, | ||
getAxisId, | ||
getSpecId, | ||
LineAnnotation, | ||
Position, | ||
ScaleType, | ||
Settings, | ||
RectAnnotation, | ||
} from '@elastic/charts'; | ||
|
||
export interface DiscoverHistogramProps { | ||
chartData: any; // TODO: make this unknown? | ||
} | ||
|
||
export class DiscoverHistogram extends Component<DiscoverHistogramProps> { | ||
static propTypes = { | ||
chartData: PropTypes.object, | ||
}; | ||
|
||
render() { | ||
if (!this.props.chartData || !this.props.chartData.series[0]) { | ||
return null; | ||
} | ||
|
||
const format = this.props.chartData.xAxisFormat.params.pattern; | ||
|
||
const formatter = (val: string) => { | ||
return moment(val).format(format); | ||
}; | ||
|
||
const currentTime = { | ||
dataValue: moment(), | ||
details: '', | ||
}; | ||
|
||
const lineAnnotationStyle = { | ||
line: { | ||
strokeWidth: 2, | ||
stroke: '#c80000', | ||
opacity: 0.3, | ||
}, | ||
}; | ||
|
||
const domain = this.props.chartData.ordered; | ||
const domainStart = domain.min; | ||
const domainEnd = domain.max; | ||
|
||
const rectAnnotations = [ | ||
{ | ||
coordinates: { | ||
x0: domainStart.valueOf(), | ||
}, | ||
details: 'This area may contain partial data', | ||
}, | ||
{ | ||
coordinates: { | ||
x1: domainEnd.valueOf(), | ||
}, | ||
details: 'This area may contain partial data', | ||
}, | ||
]; | ||
|
||
const xDomain = { | ||
min: domainStart.valueOf(), | ||
max: domainEnd.valueOf(), | ||
}; | ||
|
||
return ( | ||
<Chart className="escDiscoverHistogram"> | ||
<Settings debug={false} xDomain={xDomain} /> | ||
<Axis | ||
id={getAxisId('discover-histogram-left-axis')} | ||
position={Position.Left} | ||
title={this.props.chartData.yAxisLabel} | ||
/> | ||
<Axis | ||
id={getAxisId('discover-histogram-bottom-axis')} | ||
position={Position.Bottom} | ||
title={this.props.chartData.xAxisLabel} | ||
tickFormat={formatter} | ||
/> | ||
<LineAnnotation | ||
annotationId={getAnnotationId('line-annotation')} | ||
domainType={AnnotationDomainTypes.XDomain} | ||
dataValues={[currentTime]} | ||
hideTooltips={true} | ||
style={lineAnnotationStyle} | ||
/> | ||
<RectAnnotation | ||
dataValues={rectAnnotations} | ||
annotationId={getAnnotationId('rect-annotation')} | ||
/> | ||
|
||
<BarSeries | ||
id={getSpecId('discover-histogram')} | ||
xScaleType={ScaleType.Time} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor="x" | ||
yAccessors={['y']} | ||
data={this.props.chartData.series[0].values} | ||
/> | ||
</Chart> | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/legacy/core_plugins/kibana/public/discover/components/histogram/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import './directive'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters