Skip to content

Commit

Permalink
redraw graph when zoom changes, see #31
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed May 22, 2019
1 parent 45ffa61 commit 8a977e8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions js/energy-skate-park/common/view/EnergyBarGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
Expand Down

0 comments on commit 8a977e8

Please sign in to comment.