@@ -424,11 +424,8 @@ class TimeseriesChartIntl extends Component {
424424 }
425425 focusLoadTo = Math . min ( focusLoadTo , contextXMax ) ;
426426
427- const brushVisibility = focusLoadFrom !== contextXMin || focusLoadTo !== contextXMax ;
428- this . setBrushVisibility ( brushVisibility ) ;
429-
430427 if ( focusLoadFrom !== contextXMin || focusLoadTo !== contextXMax ) {
431- this . setContextBrushExtent ( new Date ( focusLoadFrom ) , new Date ( focusLoadTo ) , true ) ;
428+ this . setContextBrushExtent ( new Date ( focusLoadFrom ) , new Date ( focusLoadTo ) ) ;
432429 const newSelectedBounds = {
433430 min : moment ( new Date ( focusLoadFrom ) ) ,
434431 max : moment ( focusLoadFrom ) ,
@@ -442,6 +439,10 @@ class TimeseriesChartIntl extends Component {
442439 } ;
443440 if ( ! _ . isEqual ( newSelectedBounds , this . selectedBounds ) ) {
444441 this . selectedBounds = newSelectedBounds ;
442+ this . setContextBrushExtent (
443+ new Date ( contextXScaleDomain [ 0 ] ) ,
444+ new Date ( contextXScaleDomain [ 1 ] )
445+ ) ;
445446 if ( this . contextChartInitialized === false ) {
446447 this . contextChartInitialized = true ;
447448 contextChartSelected ( { from : contextXScaleDomain [ 0 ] , to : contextXScaleDomain [ 1 ] } ) ;
@@ -1178,36 +1179,29 @@ class TimeseriesChartIntl extends Component {
11781179 '<div class="brush-handle-inner brush-handle-inner-right"><i class="fa fa-caret-right"></i></div>'
11791180 ) ;
11801181
1181- const showBrush = show => {
1182- if ( show === true ) {
1183- const brushExtent = brush . extent ( ) ;
1184- mask . reveal ( brushExtent ) ;
1185- leftHandle . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) - 10 ) ;
1186- rightHandle . attr ( 'x' , contextXScale ( brushExtent [ 1 ] ) + 0 ) ;
1187-
1188- topBorder . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) + 1 ) ;
1189- // Use Math.max(0, ...) to make sure we don't end up
1190- // with a negative width which would cause an SVG error.
1191- topBorder . attr (
1192- 'width' ,
1193- Math . max ( 0 , contextXScale ( brushExtent [ 1 ] ) - contextXScale ( brushExtent [ 0 ] ) - 2 )
1194- ) ;
1195- }
1196-
1197- this . setBrushVisibility ( show ) ;
1198- } ;
1199-
1200- showBrush ( ! brush . empty ( ) ) ;
1201-
12021182 function brushing ( ) {
1183+ const brushExtent = brush . extent ( ) ;
1184+ mask . reveal ( brushExtent ) ;
1185+ leftHandle . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) - 10 ) ;
1186+ rightHandle . attr ( 'x' , contextXScale ( brushExtent [ 1 ] ) + 0 ) ;
1187+
1188+ topBorder . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) + 1 ) ;
1189+ // Use Math.max(0, ...) to make sure we don't end up
1190+ // with a negative width which would cause an SVG error.
1191+ const topBorderWidth = Math . max (
1192+ 0 ,
1193+ contextXScale ( brushExtent [ 1 ] ) - contextXScale ( brushExtent [ 0 ] ) - 2
1194+ ) ;
1195+ topBorder . attr ( 'width' , topBorderWidth ) ;
1196+
12031197 const isEmpty = brush . empty ( ) ;
1204- showBrush ( ! isEmpty ) ;
1198+ d3 . selectAll ( '.brush-handle' ) . style ( 'visibility' , isEmpty ? 'hidden' : 'visible' ) ;
12051199 }
1200+ brushing ( ) ;
12061201
12071202 const that = this ;
12081203 function brushed ( ) {
12091204 const isEmpty = brush . empty ( ) ;
1210-
12111205 const selectedBounds = isEmpty ? contextXScale . domain ( ) : brush . extent ( ) ;
12121206 const selectionMin = selectedBounds [ 0 ] . getTime ( ) ;
12131207 const selectionMax = selectedBounds [ 1 ] . getTime ( ) ;
@@ -1221,8 +1215,6 @@ class TimeseriesChartIntl extends Component {
12211215 return ;
12221216 }
12231217
1224- showBrush ( ! isEmpty ) ;
1225-
12261218 // Set the color of the swimlane cells according to whether they are inside the selection.
12271219 contextGroup . selectAll ( '.swimlane-cell' ) . style ( 'fill' , d => {
12281220 const cellMs = d . date . getTime ( ) ;
@@ -1238,26 +1230,6 @@ class TimeseriesChartIntl extends Component {
12381230 }
12391231 } ;
12401232
1241- setBrushVisibility = show => {
1242- const mask = this . mask ;
1243-
1244- if ( mask !== undefined ) {
1245- const visibility = show ? 'visible' : 'hidden' ;
1246- mask . style ( 'visibility' , visibility ) ;
1247-
1248- d3 . selectAll ( '.brush' ) . style ( 'visibility' , visibility ) ;
1249-
1250- const brushHandles = d3 . selectAll ( '.brush-handle-inner' ) ;
1251- brushHandles . style ( 'visibility' , visibility ) ;
1252-
1253- const topBorder = d3 . selectAll ( '.top-border' ) ;
1254- topBorder . style ( 'visibility' , visibility ) ;
1255-
1256- const border = d3 . selectAll ( '.chart-border-highlight' ) ;
1257- border . style ( 'visibility' , visibility ) ;
1258- }
1259- } ;
1260-
12611233 drawSwimlane = ( swlGroup , swlWidth , swlHeight ) => {
12621234 const { contextAggregationInterval, swimlaneData } = this . props ;
12631235
@@ -1368,21 +1340,18 @@ class TimeseriesChartIntl extends Component {
13681340
13691341 // Sets the extent of the brush on the context chart to the
13701342 // supplied from and to Date objects.
1371- setContextBrushExtent = ( from , to , fireEvent ) => {
1343+ setContextBrushExtent = ( from , to ) => {
13721344 const brush = this . brush ;
13731345 const brushExtent = brush . extent ( ) ;
13741346
13751347 const newExtent = [ from , to ] ;
1376- if (
1377- newExtent [ 0 ] . getTime ( ) === brushExtent [ 0 ] . getTime ( ) &&
1378- newExtent [ 1 ] . getTime ( ) === brushExtent [ 1 ] . getTime ( )
1379- ) {
1380- fireEvent = false ;
1381- }
1382-
13831348 brush . extent ( newExtent ) ;
13841349 brush ( d3 . select ( '.brush' ) ) ;
1385- if ( fireEvent ) {
1350+
1351+ if (
1352+ newExtent [ 0 ] . getTime ( ) !== brushExtent [ 0 ] . getTime ( ) ||
1353+ newExtent [ 1 ] . getTime ( ) !== brushExtent [ 1 ] . getTime ( )
1354+ ) {
13861355 brush . event ( d3 . select ( '.brush' ) ) ;
13871356 }
13881357 } ;
@@ -1403,7 +1372,7 @@ class TimeseriesChartIntl extends Component {
14031372 to = Math . min ( minBoundsMs + millis , maxBoundsMs ) ;
14041373 }
14051374
1406- this . setContextBrushExtent ( new Date ( from ) , new Date ( to ) , true ) ;
1375+ this . setContextBrushExtent ( new Date ( from ) , new Date ( to ) ) ;
14071376 }
14081377
14091378 showFocusChartTooltip ( marker , circle ) {
0 commit comments