From a314988f5624fcae6dca6a78bff19cef161189c1 Mon Sep 17 00:00:00 2001 From: Jesse Greenberg Date: Wed, 22 May 2019 18:14:43 -0400 Subject: [PATCH] fix bug displaying negative energies in BarChart, see #31 --- js/energy-skate-park/common/view/EnergyBarGraph.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/energy-skate-park/common/view/EnergyBarGraph.js b/js/energy-skate-park/common/view/EnergyBarGraph.js index f184daec..88d36341 100644 --- a/js/energy-skate-park/common/view/EnergyBarGraph.js +++ b/js/energy-skate-park/common/view/EnergyBarGraph.js @@ -68,7 +68,8 @@ define( require => { // "The kinetic energy is zero at the top of the trajectory (turning point) const hideSmallValues = ( value, scale ) => { const height = value * scale; - if ( height < 1 ) { + const absHeight = Math.abs( height ); + if ( absHeight < 1 ) { return 0; } return height; @@ -76,11 +77,14 @@ define( require => { // For thermal and total energy, make sure they are big enough to be visible, see #307 const showSmallValues = ( value, scale ) => { + const valueSign = value < 0 ? -1 : 1; + let height = value * scale; - if ( height < 1 && height > 1E-6 ) { + const absHeight = Math.abs( height ); + if ( absHeight < 1 && absHeight > 1E-6 ) { height = 1; } - return height; + return height * valueSign; }; const kineticEntry = { property: skater.kineticEnergyProperty, color: EnergySkateParkColorScheme.kineticEnergy, modifyBarHeight: hideSmallValues }; @@ -158,7 +162,7 @@ define( require => { // add the clear thermal button separately on top of the panel, it is separate from panel layout let thermalLabelBottom = this.barChartNode.getBarLabelLocation( 2, 'centerBottom' ); - thermalLabelBottom = containingPanel.globalToLocalPoint( self.barChartNode.localToGlobalPoint( thermalLabelBottom ) ); + thermalLabelBottom = containingPanel.globalToLocalPoint( this.barChartNode.localToGlobalPoint( thermalLabelBottom ) ); const clearThermalButton = new MoveToTrashButton( { arrowColor: EnergySkateParkColorScheme.thermalEnergy,