-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Series Charts] Provide custom crosshair overlay time formatting #1429
Changes from 3 commits
8309686
5f893a5
5d03a69
7968372
53f284a
a36c74c
a744e0d
c8a97b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { | ||
EuiSeriesChart, | ||
EuiHistogramSeries, | ||
EuiSeriesChartUtils, | ||
} from '../../../../src/experimental'; | ||
|
||
const { SCALE } = EuiSeriesChartUtils; | ||
let timeseriesX = Date.now(); | ||
const HOUR = 1000 * 60 * 60; | ||
|
||
const histogramData = new Array(1000).fill(0).map(() => { | ||
const x0 = timeseriesX; | ||
timeseriesX += HOUR; | ||
const x = timeseriesX; | ||
const y = Math.floor(Math.random() * 100); | ||
return { x0, x, y }; | ||
}); | ||
|
||
export const FormatCrosshairTimesExample = () => ( | ||
<div> | ||
<EuiSeriesChart height={200} xType={SCALE.TIME}> | ||
<EuiHistogramSeries yDomain={[0, 100]} name="Chart Name" xCrosshairFormat="YYYY-MM-DD hh:mmZ" data={histogramData} /> | ||
</EuiSeriesChart> | ||
</div> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import { AbstractSeries, Crosshair } from 'react-vis'; | ||
import { SCALE } from '../utils/chart_utils'; | ||
import moment from 'moment'; | ||
/** | ||
* The Crosshair used by the XYChart as main tooltip mechanism along X axis (vertical). | ||
*/ | ||
|
@@ -55,9 +56,9 @@ export class EuiCrosshairX extends AbstractSeries { | |
} | ||
|
||
_formatXValue = (x) => { | ||
const { xType } = this.props; | ||
const { xType, xCrosshairFormat } = this.props; | ||
if (xType === SCALE.TIME || xType === SCALE.TIME_UTC) { | ||
return new Date(x).toISOString(); // TODO add a props for time formatting | ||
return moment(x).format(xCrosshairFormat); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either check to see that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also updated in 7968372 - added tests in a later commit as well. |
||
} else { | ||
return x; | ||
} | ||
|
@@ -201,5 +202,6 @@ EuiCrosshairX.propTypes = { | |
* The ordered array of series names | ||
*/ | ||
seriesNames: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
xCrosshairFormat: PropTypes.string, | ||
}; | ||
EuiCrosshairX.defaultProps = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\This changelog entry is now out of date, needs to be moved back to the top
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 7968372.