@@ -91,7 +91,9 @@ export class FocusChart extends Component<Props, State> {
91
91
getScale ( ) {
92
92
const { width, height } = this . state ;
93
93
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 ] ) ;
95
97
const [ minTX , maxTX ] = d3 . extent ( maxTimeSeries , ( time : Array < number > ) => time [ 0 ] ) ;
96
98
const [ minTY , maxTY ] = d3 . extent ( maxTimeSeries , ( time : Array < number > ) => time [ 1 ] ) ;
97
99
const drawableWidth = width - 2 * CHART_MARGIN - TRANSLATE_LEFT ;
@@ -100,16 +102,20 @@ export class FocusChart extends Component<Props, State> {
100
102
const xCoord = d3 . scaleTime ( ) . range ( [ 0 , drawableWidth ] ) ;
101
103
const yCoord = d3 . scaleLinear ( ) . range ( [ drawableHeight , 0 ] ) ;
102
104
105
+ const minDtX = Math . min ( MIN_VALUE , minDtTX ) ;
106
+ const maxDtX = Math . max ( MAX_VALUE , maxDtTX ) ;
107
+
103
108
const minX = Math . min ( MIN_VALUE , minTX ) ;
104
109
const maxX = Math . max ( MAX_VALUE , maxTX ) ;
105
110
106
111
const minY = Math . min ( MIN_VALUE , minTY ) ;
107
112
const maxY = Math . max ( MAX_VALUE , maxTY ) ;
108
113
114
+ const maxDtXCood = xCoord . domain ( [ minDtX , maxDtX ] ) ;
109
115
xCoord . domain ( [ minX , maxX ] ) ;
110
116
yCoord . domain ( [ minY , maxY ] ) ;
111
117
112
- return { xCoord, yCoord } ;
118
+ return { xCoord, yCoord, maxDtXCood } ;
113
119
}
114
120
115
121
drawLine ( data ) {
@@ -279,7 +285,7 @@ export class FocusChart extends Component<Props, State> {
279
285
zoomValue,
280
286
} ;
281
287
282
- this . props . setPeriodRange ( periodRange ) ;
288
+ this . rangeToTimestamp ( periodRange ) ;
283
289
}
284
290
285
291
toggleZoom ( ) {
@@ -292,6 +298,17 @@ export class FocusChart extends Component<Props, State> {
292
298
}
293
299
}
294
300
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
+
295
312
updateChartZoomOnSelectPeriod ( ) {
296
313
const { width } = this . state ;
297
314
const focusChartWidth = width - TRANSLATE_LEFT - 2 * CHART_MARGIN ;
@@ -302,12 +319,18 @@ export class FocusChart extends Component<Props, State> {
302
319
303
320
const startRange = xCoord ( dateRangeStart * 1000 ) ;
304
321
const stopRange = xCoord ( dateRangeStop * 1000 ) ;
305
-
306
322
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
+
307
329
selectedPeriod &&
308
330
setPeriodRange ( {
309
331
eventRange : [ startRange , stopRange ] ,
310
332
zoomValue,
333
+ timeStamp : [ timestampStart , timestampStop ] ,
311
334
} ) ;
312
335
}
313
336
0 commit comments