@@ -432,11 +432,8 @@ const TimeseriesChartIntl = injectI18n(
432432 }
433433 focusLoadTo = Math . min ( focusLoadTo , contextXMax ) ;
434434
435- const brushVisibility = focusLoadFrom !== contextXMin || focusLoadTo !== contextXMax ;
436- this . setBrushVisibility ( brushVisibility ) ;
437-
438435 if ( focusLoadFrom !== contextXMin || focusLoadTo !== contextXMax ) {
439- this . setContextBrushExtent ( new Date ( focusLoadFrom ) , new Date ( focusLoadTo ) , true ) ;
436+ this . setContextBrushExtent ( new Date ( focusLoadFrom ) , new Date ( focusLoadTo ) ) ;
440437 const newSelectedBounds = {
441438 min : moment ( new Date ( focusLoadFrom ) ) ,
442439 max : moment ( focusLoadFrom ) ,
@@ -450,6 +447,10 @@ const TimeseriesChartIntl = injectI18n(
450447 } ;
451448 if ( ! _ . isEqual ( newSelectedBounds , this . selectedBounds ) ) {
452449 this . selectedBounds = newSelectedBounds ;
450+ this . setContextBrushExtent (
451+ new Date ( contextXScaleDomain [ 0 ] ) ,
452+ new Date ( contextXScaleDomain [ 1 ] )
453+ ) ;
453454 if ( this . contextChartInitialized === false ) {
454455 this . contextChartInitialized = true ;
455456 contextChartSelected ( { from : contextXScaleDomain [ 0 ] , to : contextXScaleDomain [ 1 ] } ) ;
@@ -1194,36 +1195,29 @@ const TimeseriesChartIntl = injectI18n(
11941195 '<div class="brush-handle-inner brush-handle-inner-right"><i class="fa fa-caret-right"></i></div>'
11951196 ) ;
11961197
1197- const showBrush = show => {
1198- if ( show === true ) {
1199- const brushExtent = brush . extent ( ) ;
1200- mask . reveal ( brushExtent ) ;
1201- leftHandle . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) - 10 ) ;
1202- rightHandle . attr ( 'x' , contextXScale ( brushExtent [ 1 ] ) + 0 ) ;
1203-
1204- topBorder . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) + 1 ) ;
1205- // Use Math.max(0, ...) to make sure we don't end up
1206- // with a negative width which would cause an SVG error.
1207- topBorder . attr (
1208- 'width' ,
1209- Math . max ( 0 , contextXScale ( brushExtent [ 1 ] ) - contextXScale ( brushExtent [ 0 ] ) - 2 )
1210- ) ;
1211- }
1212-
1213- this . setBrushVisibility ( show ) ;
1214- } ;
1215-
1216- showBrush ( ! brush . empty ( ) ) ;
1217-
12181198 function brushing ( ) {
1199+ const brushExtent = brush . extent ( ) ;
1200+ mask . reveal ( brushExtent ) ;
1201+ leftHandle . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) - 10 ) ;
1202+ rightHandle . attr ( 'x' , contextXScale ( brushExtent [ 1 ] ) + 0 ) ;
1203+
1204+ topBorder . attr ( 'x' , contextXScale ( brushExtent [ 0 ] ) + 1 ) ;
1205+ // Use Math.max(0, ...) to make sure we don't end up
1206+ // with a negative width which would cause an SVG error.
1207+ const topBorderWidth = Math . max (
1208+ 0 ,
1209+ contextXScale ( brushExtent [ 1 ] ) - contextXScale ( brushExtent [ 0 ] ) - 2
1210+ ) ;
1211+ topBorder . attr ( 'width' , topBorderWidth ) ;
1212+
12191213 const isEmpty = brush . empty ( ) ;
1220- showBrush ( ! isEmpty ) ;
1214+ d3 . selectAll ( '.brush-handle' ) . style ( 'visibility' , isEmpty ? 'hidden' : 'visible' ) ;
12211215 }
1216+ brushing ( ) ;
12221217
12231218 const that = this ;
12241219 function brushed ( ) {
12251220 const isEmpty = brush . empty ( ) ;
1226-
12271221 const selectedBounds = isEmpty ? contextXScale . domain ( ) : brush . extent ( ) ;
12281222 const selectionMin = selectedBounds [ 0 ] . getTime ( ) ;
12291223 const selectionMax = selectedBounds [ 1 ] . getTime ( ) ;
@@ -1237,8 +1231,6 @@ const TimeseriesChartIntl = injectI18n(
12371231 return ;
12381232 }
12391233
1240- showBrush ( ! isEmpty ) ;
1241-
12421234 // Set the color of the swimlane cells according to whether they are inside the selection.
12431235 contextGroup . selectAll ( '.swimlane-cell' ) . style ( 'fill' , d => {
12441236 const cellMs = d . date . getTime ( ) ;
@@ -1254,26 +1246,6 @@ const TimeseriesChartIntl = injectI18n(
12541246 }
12551247 } ;
12561248
1257- setBrushVisibility = show => {
1258- const mask = this . mask ;
1259-
1260- if ( mask !== undefined ) {
1261- const visibility = show ? 'visible' : 'hidden' ;
1262- mask . style ( 'visibility' , visibility ) ;
1263-
1264- d3 . selectAll ( '.brush' ) . style ( 'visibility' , visibility ) ;
1265-
1266- const brushHandles = d3 . selectAll ( '.brush-handle-inner' ) ;
1267- brushHandles . style ( 'visibility' , visibility ) ;
1268-
1269- const topBorder = d3 . selectAll ( '.top-border' ) ;
1270- topBorder . style ( 'visibility' , visibility ) ;
1271-
1272- const border = d3 . selectAll ( '.chart-border-highlight' ) ;
1273- border . style ( 'visibility' , visibility ) ;
1274- }
1275- } ;
1276-
12771249 drawSwimlane = ( swlGroup , swlWidth , swlHeight ) => {
12781250 const { contextAggregationInterval, swimlaneData } = this . props ;
12791251
@@ -1384,21 +1356,18 @@ const TimeseriesChartIntl = injectI18n(
13841356
13851357 // Sets the extent of the brush on the context chart to the
13861358 // supplied from and to Date objects.
1387- setContextBrushExtent = ( from , to , fireEvent ) => {
1359+ setContextBrushExtent = ( from , to ) => {
13881360 const brush = this . brush ;
13891361 const brushExtent = brush . extent ( ) ;
13901362
13911363 const newExtent = [ from , to ] ;
1392- if (
1393- newExtent [ 0 ] . getTime ( ) === brushExtent [ 0 ] . getTime ( ) &&
1394- newExtent [ 1 ] . getTime ( ) === brushExtent [ 1 ] . getTime ( )
1395- ) {
1396- fireEvent = false ;
1397- }
1398-
13991364 brush . extent ( newExtent ) ;
14001365 brush ( d3 . select ( '.brush' ) ) ;
1401- if ( fireEvent ) {
1366+
1367+ if (
1368+ newExtent [ 0 ] . getTime ( ) !== brushExtent [ 0 ] . getTime ( ) ||
1369+ newExtent [ 1 ] . getTime ( ) !== brushExtent [ 1 ] . getTime ( )
1370+ ) {
14021371 brush . event ( d3 . select ( '.brush' ) ) ;
14031372 }
14041373 } ;
@@ -1419,7 +1388,7 @@ const TimeseriesChartIntl = injectI18n(
14191388 to = Math . min ( minBoundsMs + millis , maxBoundsMs ) ;
14201389 }
14211390
1422- this . setContextBrushExtent ( new Date ( from ) , new Date ( to ) , true ) ;
1391+ this . setContextBrushExtent ( new Date ( from ) , new Date ( to ) ) ;
14231392 }
14241393
14251394 showFocusChartTooltip ( marker , circle ) {
0 commit comments