@@ -32,11 +32,14 @@ class GraphsContainer extends React.Component {
32
32
this . tooltip = React . createRef ( ) ;
33
33
this . leftChartPadding = 25 ;
34
34
this . rightChartPadding = 10 ;
35
+ const scatterPlotData = flatMap ( this . props . testData , ( item ) =>
36
+ item . visible ? item . data : [ ] ,
37
+ ) ;
38
+ const zoomDomain = this . initZoomDomain ( scatterPlotData ) ;
35
39
this . state = {
36
40
highlights : [ ] ,
37
- scatterPlotData : flatMap ( this . props . testData , ( item ) =>
38
- item . visible ? item . data : [ ] ,
39
- ) ,
41
+ scatterPlotData,
42
+ zoomDomain,
40
43
lockTooltip : false ,
41
44
externalMutation : undefined ,
42
45
width : window . innerWidth ,
@@ -45,11 +48,15 @@ class GraphsContainer extends React.Component {
45
48
46
49
componentDidMount ( ) {
47
50
const { zoom, selectedDataPoint } = this . props ;
48
-
51
+ const { scatterPlotData } = this . state ;
52
+ const zoomDomain = this . initZoomDomain ( scatterPlotData ) ;
49
53
this . addHighlights ( ) ;
50
54
if ( selectedDataPoint ) this . verifySelectedDataPoint ( ) ;
51
55
window . addEventListener ( 'resize' , ( ) =>
52
- this . setState ( { width : window . innerWidth } ) ,
56
+ this . setState ( {
57
+ width : window . innerWidth ,
58
+ zoomDomain,
59
+ } ) ,
53
60
) ;
54
61
}
55
62
@@ -60,6 +67,9 @@ class GraphsContainer extends React.Component {
60
67
testData,
61
68
timeRange,
62
69
} = this . props ;
70
+ const scatterPlotData = flatMap ( testData , ( item ) =>
71
+ item . visible ? item . data : [ ] ,
72
+ ) ;
63
73
64
74
if (
65
75
prevProps . highlightAlerts !== highlightAlerts ||
@@ -77,6 +87,35 @@ class GraphsContainer extends React.Component {
77
87
}
78
88
}
79
89
90
+ getToday = ( ) => {
91
+ return moment . utc ( ) . toDate ( ) ;
92
+ } ;
93
+
94
+ // limits for the zoomDomain of VictoryChart
95
+ initZoomDomain = ( plotData ) => {
96
+ const minDomainY = this . getMinY ( plotData ) ;
97
+ const maxDomainY = this . getMaxY ( plotData ) ;
98
+ // zoom domain padding is the space between the lowest/highest datapoint
99
+ // and the top/bottom limits of the zoom domain. The minimum value is 100
100
+ // as this is the top victory graph behavior
101
+ let zoomDomPadd ;
102
+ if ( minDomainY !== maxDomainY ) {
103
+ zoomDomPadd = ( maxDomainY - minDomainY ) / 1.8 ;
104
+ } else {
105
+ zoomDomPadd = 100 ;
106
+ }
107
+ const minX = this . getMinX ( plotData ) ;
108
+ const maxX = this . getToday ( ) ;
109
+ const minY = minDomainY - zoomDomPadd < 0 ? 0 : minDomainY - zoomDomPadd ;
110
+ const maxY = maxDomainY + zoomDomPadd ;
111
+
112
+ return { minX, maxX, minY, maxY } ;
113
+ } ;
114
+
115
+ updateZoomDomain = ( plotData ) => {
116
+ return this . initZoomDomain ( plotData ) ;
117
+ } ;
118
+
80
119
verifySelectedDataPoint = ( ) => {
81
120
const { selectedDataPoint, testData, updateStateParams } = this . props ;
82
121
@@ -106,8 +145,10 @@ class GraphsContainer extends React.Component {
106
145
item . visible ? item . data : [ ] ,
107
146
) ;
108
147
this . addHighlights ( ) ;
148
+ const zoomDomain = this . updateZoomDomain ( scatterPlotData ) ;
109
149
this . setState ( {
110
150
scatterPlotData,
151
+ zoomDomain,
111
152
} ) ;
112
153
113
154
if ( ! visibilityChanged ) {
@@ -267,11 +308,25 @@ class GraphsContainer extends React.Component {
267
308
updateStateParams ( { zoom } ) ;
268
309
} ;
269
310
311
+ // helper functions that allow the zoom domain to be tuned correctly
312
+ getMinX = ( data ) => {
313
+ return data . reduce ( ( min , p ) => ( p . x < min ? p . x : min ) , data [ 0 ] . x ) ;
314
+ } ;
315
+
316
+ getMinY = ( data ) => {
317
+ return data . reduce ( ( min , p ) => ( p . y < min ? p . y : min ) , data [ 0 ] . y ) ;
318
+ } ;
319
+
320
+ getMaxY = ( data ) => {
321
+ return data . reduce ( ( max , p ) => ( p . y > max ? p . y : max ) , data [ 0 ] . y ) ;
322
+ } ;
323
+
270
324
render ( ) {
271
325
const { testData, showTable, zoom, highlightedRevisions } = this . props ;
272
326
const {
273
327
highlights,
274
328
scatterPlotData,
329
+ zoomDomain,
275
330
lockTooltip,
276
331
externalMutation,
277
332
width,
@@ -357,7 +412,8 @@ class GraphsContainer extends React.Component {
357
412
style = { { parent : { maxHeight : '400px' , maxWidth : '1350px' } } }
358
413
scale = { { x : 'time' , y : 'linear' } }
359
414
domainPadding = { { y : 40 , x : [ 10 , 10 ] } }
360
- maxDomain = { { x : today } }
415
+ minDomain = { { x : zoomDomain . minX , y : zoomDomain . minY } }
416
+ maxDomain = { { x : today , y : zoomDomain . maxY } }
361
417
externalEventMutations = { externalMutation }
362
418
containerComponent = {
363
419
< VictoryZoomSelectionContainer
0 commit comments