Skip to content

Commit

Permalink
only update energy bars when bar graphis visible, see #31
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed May 22, 2019
1 parent 7c3a351 commit 45ffa61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions js/energy-skate-park/common/view/EnergyBarGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define( require => {
* @param {Tandem} tandem
* @returns {Skater}
*/
constructor( skater, graphScaleProperty, tandem, options ) {
constructor( skater, graphScaleProperty, barGraphVisibleProperty, tandem, options ) {

options = _.extend( {

Expand Down Expand Up @@ -176,9 +176,15 @@ 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( () => {
this.barChartNode.update();
updateWhenVisible( barGraphVisibleProperty.value );
} );
barGraphVisibleProperty.link( updateWhenVisible );

skater.allowClearingThermalEnergyProperty.link( function( allowClearingThermalEnergy ) {
clearThermalButton.enabled = allowClearingThermalEnergy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ define( function( require ) {
} );

// @private - the bar chart showing energy distribution
this.energyBarGraph = new EnergyBarGraph( model.skater, model.graphScaleProperty, tandem.createTandem( 'energyBarGraph' ), options.barGraphOptions );
this.energyBarGraph = new EnergyBarGraph( model.skater, model.graphScaleProperty, model.barGraphVisibleProperty, tandem.createTandem( 'energyBarGraph' ), options.barGraphOptions );
this.energyBarGraph.leftTop = new Vector2( 5, 5 );
this.bottomLayer.addChild( this.energyBarGraph );
model.barGraphVisibleProperty.linkAttribute( this.energyBarGraph, 'visible' );

this.resetAllButton = new ResetAllButton( {
listener: model.reset.bind( model ),
Expand Down

0 comments on commit 45ffa61

Please sign in to comment.