diff --git a/js/energy-skate-park/common/view/EnergyBarGraph.js b/js/energy-skate-park/common/view/EnergyBarGraph.js index 0e636587..2cffe427 100644 --- a/js/energy-skate-park/common/view/EnergyBarGraph.js +++ b/js/energy-skate-park/common/view/EnergyBarGraph.js @@ -152,6 +152,8 @@ define( require => { zoomInButton.enabled = scale < Constants.MAX_ZOOM_FACTOR; zoomOutButton.enabled = scale > Constants.MIN_ZOOM_FACTOR; } ); + + graphScaleProperty.link( () => { this.updateWhenVisible( barGraphVisibleProperty.value ); } ); } else { content = labelledChart; @@ -176,20 +178,24 @@ define( require => { this.addChild( clearThermalButton ); // attach listeners - bar chart exists for life of sim, no need to dispose - const updateWhenVisible = ( visible ) => { - if ( visible ) { - this.barChartNode.update(); - } - }; - skater.energyChangedEmitter.addListener( () => { - updateWhenVisible( barGraphVisibleProperty.value ); - } ); - barGraphVisibleProperty.link( updateWhenVisible ); + skater.energyChangedEmitter.addListener( () => { this.updateWhenVisible( barGraphVisibleProperty.value ); } ); + barGraphVisibleProperty.link( this.updateWhenVisible.bind( this ) ); skater.allowClearingThermalEnergyProperty.link( function( allowClearingThermalEnergy ) { clearThermalButton.enabled = allowClearingThermalEnergy; } ); } + + /** + * If model indicates that graph is visible, redraw the graph. + * + * @param {boolean} visible + */ + updateWhenVisible( visible ) { + if ( visible ) { + this.barChartNode.update(); + } + } } return energySkatePark.register( 'EnergyBarGraph', EnergyBarGraph );