@@ -17,11 +17,13 @@ import PropTypes from 'prop-types';
1717import React , { PureComponent } from 'react' ;
1818import { last } from 'lodash' ;
1919import { rgba } from 'polished' ;
20+ import { scaleUtc } from 'd3-scale' ;
2021
2122import StatusText from './StatusText' ;
2223import { SharedPlot } from './plotUtils' ;
2324import { i18n } from '@kbn/i18n' ;
2425import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue' ;
26+ import { getTimezoneOffsetInMs } from './getTimezoneOffsetInMs' ;
2527
2628// undefined values are converted by react-vis into NaN when stacking
2729// see https://github.com/uber/react-vis/issues/1214
@@ -42,7 +44,7 @@ class StaticPlot extends PureComponent {
4244 < LineSeries
4345 getNull = { getNull }
4446 key = { serie . title }
45- xType = "time"
47+ xType = "time-utc "
4648 curve = { 'curveMonotoneX' }
4749 data = { serie . data }
4850 color = { serie . color }
@@ -54,7 +56,7 @@ class StaticPlot extends PureComponent {
5456 < AreaSeries
5557 getNull = { getNull }
5658 key = { serie . title }
57- xType = "time"
59+ xType = "time-utc "
5860 curve = { 'curveMonotoneX' }
5961 data = { serie . data }
6062 color = { serie . color }
@@ -78,7 +80,7 @@ class StaticPlot extends PureComponent {
7880 < AreaSeries
7981 getNull = { getNull }
8082 key = { `${ serie . title } -area` }
81- xType = "time"
83+ xType = "time-utc "
8284 curve = { 'curveMonotoneX' }
8385 data = { data }
8486 color = { serie . color }
@@ -90,7 +92,7 @@ class StaticPlot extends PureComponent {
9092 < LineSeries
9193 getNull = { getNull }
9294 key = { `${ serie . title } -line` }
93- xType = "time"
95+ xType = "time-utc "
9496 curve = { 'curveMonotoneX' }
9597 data = { data }
9698 color = { serie . color }
@@ -113,7 +115,7 @@ class StaticPlot extends PureComponent {
113115 < VerticalRectSeries
114116 getNull = { getNull }
115117 key = { serie . title }
116- xType = "time"
118+ xType = "time-utc "
117119 curve = { 'curveMonotoneX' }
118120 data = { data }
119121 color = { serie . color }
@@ -126,7 +128,7 @@ class StaticPlot extends PureComponent {
126128 < LineMarkSeries
127129 getNull = { getNull }
128130 key = { serie . title }
129- xType = "time"
131+ xType = "time-utc "
130132 curve = { 'curveMonotoneX' }
131133 data = { serie . data }
132134 color = { serie . color }
@@ -138,24 +140,42 @@ class StaticPlot extends PureComponent {
138140 }
139141 }
140142
143+ /**
144+ * A tick format function that takes the timezone from Kibana's settings into
145+ * account. Used if no tickFormatX prop is supplied.
146+ *
147+ * This produces the same results as the built-in formatter from D3, which is
148+ * what react-vis uses, but shifts the timezone.
149+ */
150+ tickFormatXTime = value => {
151+ const xDomain = this . props . plotValues . x . domain ( ) ;
152+
153+ const time = value . getTime ( ) ;
154+
155+ return scaleUtc ( )
156+ . domain ( xDomain )
157+ . tickFormat ( ) ( new Date ( time - getTimezoneOffsetInMs ( time ) ) ) ;
158+ } ;
159+
141160 render ( ) {
142- const {
143- width,
144- series,
145- tickFormatX,
146- tickFormatY,
147- plotValues,
148- noHits
149- } = this . props ;
150- const { yTickValues } = plotValues ;
161+ const { width, series, tickFormatY, plotValues, noHits } = this . props ;
162+ const { xTickValues, yTickValues } = plotValues ;
151163
152164 // approximate number of x-axis ticks based on the width of the plot. There should by approx 1 tick per 100px
153165 // d3 will determine the exact number of ticks based on the selected range
154166 const xTickTotal = Math . floor ( width / 100 ) ;
155167
168+ const tickFormatX = this . props . tickFormatX || this . tickFormatXTime ;
169+
156170 return (
157171 < SharedPlot plotValues = { plotValues } >
158- < XAxis tickSize = { 0 } tickTotal = { xTickTotal } tickFormat = { tickFormatX } />
172+ < XAxis
173+ type = "time-utc"
174+ tickSize = { 0 }
175+ tickTotal = { xTickTotal }
176+ tickFormat = { tickFormatX }
177+ tickValues = { xTickValues }
178+ />
159179 { noHits ? (
160180 < StatusText
161181 marginLeft = { 30 }
0 commit comments