@@ -91,7 +91,9 @@ export class FocusChart extends Component<Props, State> {
9191 getScale ( ) {
9292 const { width, height } = this . state ;
9393 const { dataRun } = this . props ;
94- const { maxTimeSeries } = dataRun ;
94+
95+ const { maxTimeSeries, timeSeries } = dataRun ;
96+ const [ minDtTX , maxDtTX ] = d3 . extent ( timeSeries , ( time : Array < number > ) => time [ 0 ] ) ;
9597 const [ minTX , maxTX ] = d3 . extent ( maxTimeSeries , ( time : Array < number > ) => time [ 0 ] ) ;
9698 const [ minTY , maxTY ] = d3 . extent ( maxTimeSeries , ( time : Array < number > ) => time [ 1 ] ) ;
9799 const drawableWidth = width - 2 * CHART_MARGIN - TRANSLATE_LEFT ;
@@ -100,16 +102,20 @@ export class FocusChart extends Component<Props, State> {
100102 const xCoord = d3 . scaleTime ( ) . range ( [ 0 , drawableWidth ] ) ;
101103 const yCoord = d3 . scaleLinear ( ) . range ( [ drawableHeight , 0 ] ) ;
102104
105+ const minDtX = Math . min ( MIN_VALUE , minDtTX ) ;
106+ const maxDtX = Math . max ( MAX_VALUE , maxDtTX ) ;
107+
103108 const minX = Math . min ( MIN_VALUE , minTX ) ;
104109 const maxX = Math . max ( MAX_VALUE , maxTX ) ;
105110
106111 const minY = Math . min ( MIN_VALUE , minTY ) ;
107112 const maxY = Math . max ( MAX_VALUE , maxTY ) ;
108113
114+ const maxDtXCood = xCoord . domain ( [ minDtX , maxDtX ] ) ;
109115 xCoord . domain ( [ minX , maxX ] ) ;
110116 yCoord . domain ( [ minY , maxY ] ) ;
111117
112- return { xCoord, yCoord } ;
118+ return { xCoord, yCoord, maxDtXCood } ;
113119 }
114120
115121 drawLine ( data ) {
@@ -279,7 +285,7 @@ export class FocusChart extends Component<Props, State> {
279285 zoomValue,
280286 } ;
281287
282- this . props . setPeriodRange ( periodRange ) ;
288+ this . rangeToTimestamp ( periodRange ) ;
283289 }
284290
285291 toggleZoom ( ) {
@@ -292,6 +298,17 @@ export class FocusChart extends Component<Props, State> {
292298 }
293299 }
294300
301+ rangeToTimestamp ( periodRange ) {
302+ const { zoomValue } = periodRange ;
303+ const { maxDtXCood } = this . getScale ( ) ;
304+ const xCoordCopy = maxDtXCood . copy ( ) ;
305+ // @ts -ignore
306+ const timeStamp = zoomValue . rescaleX ( xCoordCopy . copy ( ) ) . domain ( ) ;
307+ const timestampStart = new Date ( timeStamp [ 0 ] ) . getTime ( ) ;
308+ const timestampStop = new Date ( timeStamp [ 1 ] ) . getTime ( ) ;
309+ this . props . setPeriodRange ( { ...periodRange , timeStamp : [ timestampStart , timestampStop ] } ) ;
310+ }
311+
295312 updateChartZoomOnSelectPeriod ( ) {
296313 const { width } = this . state ;
297314 const focusChartWidth = width - TRANSLATE_LEFT - 2 * CHART_MARGIN ;
@@ -302,12 +319,18 @@ export class FocusChart extends Component<Props, State> {
302319
303320 const startRange = xCoord ( dateRangeStart * 1000 ) ;
304321 const stopRange = xCoord ( dateRangeStop * 1000 ) ;
305-
306322 const zoomValue = d3 . zoomIdentity . scale ( focusChartWidth / ( stopRange - startRange ) ) . translate ( - startRange , 0 ) ;
323+
324+ const xCoordCopy = xCoord . copy ( ) ;
325+ const timeStamp = zoomValue . rescaleX ( xCoordCopy ) . domain ( ) ;
326+ const timestampStart = new Date ( timeStamp [ 0 ] ) . getTime ( ) ;
327+ const timestampStop = new Date ( timeStamp [ 1 ] ) . getTime ( ) ;
328+
307329 selectedPeriod &&
308330 setPeriodRange ( {
309331 eventRange : [ startRange , stopRange ] ,
310332 zoomValue,
333+ timeStamp : [ timestampStart , timestampStop ] ,
311334 } ) ;
312335 }
313336
0 commit comments