Skip to content

Commit

Permalink
use 3 decimal places for pH meter in Micro and My Solution screens, #225
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jul 26, 2021
1 parent 4c6cfe5 commit a7b56c9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion js/common/PHScaleConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const PHScaleConstants = {

// pH
PH_RANGE: new RangeWithValue( -1, 15, 7 ),
PH_METER_DECIMAL_PLACES: 2,
MACRO_PH_METER_DECIMAL_PLACES: 2,
MICRO_PH_METER_DECIMAL_PLACES: 3,

// volume
VOLUME_DECIMAL_PLACES: 2,
Expand Down
14 changes: 7 additions & 7 deletions js/common/view/PHMeterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PHMeterNode extends AccordionBox {

// the meter is not interactive, just display the pH value
contentNode = new NumberDisplay( pHProperty, PHScaleConstants.PH_RANGE, {
decimalPlaces: PHScaleConstants.PH_METER_DECIMAL_PLACES,
decimalPlaces: PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES,
cornerRadius: CORNER_RADIUS,
textOptions: {
font: new PhetFont( 28 ),
Expand Down Expand Up @@ -137,18 +137,18 @@ class PHSpinnerNode extends NumberSpinner {
*/
constructor( pHProperty, options ) {

const pHDelta = 1 / Math.pow( 10, PHScaleConstants.PH_METER_DECIMAL_PLACES );
const pHDelta = 1 / Math.pow( 10, PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES );

// When using the spinner to change pH, constrain pHProperty to be exactly the value displayed by the spinner.
// See https://github.com/phetsims/ph-scale/issues/143
const incrementFunction = value => {
value = Utils.toFixedNumber( value, PHScaleConstants.PH_METER_DECIMAL_PLACES );
return Utils.toFixedNumber( value + pHDelta, PHScaleConstants.PH_METER_DECIMAL_PLACES );
value = Utils.toFixedNumber( value, PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES );
return Utils.toFixedNumber( value + pHDelta, PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES );
};

const decrementFunction = value => {
value = Utils.toFixedNumber( value, PHScaleConstants.PH_METER_DECIMAL_PLACES );
return Utils.toFixedNumber( value - pHDelta, PHScaleConstants.PH_METER_DECIMAL_PLACES );
value = Utils.toFixedNumber( value, PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES );
return Utils.toFixedNumber( value - pHDelta, PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES );
};

options = merge( {
Expand All @@ -157,7 +157,7 @@ class PHSpinnerNode extends NumberSpinner {
incrementFunction: incrementFunction,
decrementFunction: decrementFunction,
numberDisplayOptions: {
decimalPlaces: PHScaleConstants.PH_METER_DECIMAL_PLACES,
decimalPlaces: PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES,
xMargin: 10,
yMargin: 4,
cornerRadius: CORNER_RADIUS,
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/RatioNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class RatioNode extends Node {

let pH = this.solution.pHProperty.get();
if ( pH !== null ) {
pH = Utils.toFixedNumber( this.solution.pHProperty.get(), PHScaleConstants.PH_METER_DECIMAL_PLACES );
pH = Utils.toFixedNumber( this.solution.pHProperty.get(), PHScaleConstants.MICRO_PH_METER_DECIMAL_PLACES );
}

if ( this.pH !== pH ) {
Expand Down
2 changes: 1 addition & 1 deletion js/macro/model/MacroSolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class MacroSolution extends PhetioObject {
* @private
*/
isEquivalentToWater() {
return Utils.toFixedNumber( this.pHProperty.get(), PHScaleConstants.PH_METER_DECIMAL_PLACES ) === Water.pH;
return Utils.toFixedNumber( this.pHProperty.get(), PHScaleConstants.MACRO_PH_METER_DECIMAL_PLACES ) === Water.pH;
}
}

Expand Down
4 changes: 2 additions & 2 deletions js/macro/view/MacroPHMeterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class PHIndicatorNode extends Node {

// pH display
const numberDisplay = new NumberDisplay( pHProperty, PHScaleConstants.PH_RANGE, {
decimalPlaces: PHScaleConstants.PH_METER_DECIMAL_PLACES,
decimalPlaces: PHScaleConstants.MACRO_PH_METER_DECIMAL_PLACES,
align: 'right',
noValueAlign: 'center',
cornerRadius: CORNER_RADIUS,
Expand Down Expand Up @@ -445,7 +445,7 @@ class PHIndicatorNode extends Node {
arrowNode.visible = lineNode.visible = enabled;

// Highlight the indicator when displayed pH === 7
highlight.visible = ( Utils.toFixedNumber( pH, PHScaleConstants.PH_METER_DECIMAL_PLACES ) === 7 );
highlight.visible = ( Utils.toFixedNumber( pH, PHScaleConstants.MACRO_PH_METER_DECIMAL_PLACES ) === 7 );
} );
}
}
Expand Down

0 comments on commit a7b56c9

Please sign in to comment.