-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pH Meter value text is not aligned properly on the initial set state #218
Comments
Thanks @phet-steele, I'll investigate. Sounds like code that's changing the displayed value, but forgetting to center it in the meter. |
PHMeterNode.js is the place to start. |
Here's a screenshot of the State wrapper, showing the downstream alignment problem for the pH meter in the Macro screen: It's also a problem with the pH meter in the Micro screen: I'm beginning to suspect a general problem with NumberDisplay. These 2 meters were recently changed to use NumberDisplay in #96. But... I don't see this problem in other sims that use NumberDisplay (e.g. beers-law-lab, gas-properties, natural-selection). |
I made these changes in NumberDisplay, so that I can see the background with a red stroke: - stroke: options.backgroundStroke,
- lineWidth: options.backgroundLineWidth,
+ stroke: 'red',
+ lineWidth: 3, Below is a screenshot. NumberDisplay's background is in the correct position, and does not move. What is NOT correct is the alignment of the value on the background, which is the responsibility of NumberDisplay. |
Here's the NumberDisplay instantiation in MacroPHMeterNode.js: // pH display
const numberDisplay = new NumberDisplay( pHProperty, PHScaleConstants.PH_RANGE, {
decimalPlaces: PHScaleConstants.PH_METER_DECIMAL_PLACES,
align: 'right',
noValueAlign: 'center',
cornerRadius: CORNER_RADIUS,
xMargin: 8,
yMargin: 5,
textOptions: {
font: new PhetFont( 28 ),
textPropertyOptions: { phetioHighFrequency: true }
},
tandem: options.tandem.createTandem( 'numberDisplay' )
} ); After moving the probe out of the solution, the "No value" (—) character is also misaligned in the downstream sim. It is supposed to be |
This is indeed a general problem with NumberDisplay. Here's the problem: const valueText = new Constructor( longestString, merge( {
tandem: options.tandem.createTandem( 'valueText' )
}, options.textOptions, {
maxWidth: null // we are handling maxWidth manually, so we don't want to provide it initially.
} ) );
...
// display the value
const numberObserver = value => {
...
// horizontally align value in background
const align = ( value === null ) ? options.noValueAlign : options.align;
if ( align === 'center' ) {
valueText.centerX = backgroundNode.centerX;
}
else if ( align === 'left' ) {
valueText.left = backgroundNode.left + options.xMargin;
}
else { // right
valueText.right = backgroundNode.right - options.xMargin;
}
valueText.centerY = backgroundNode.centerY;
};
numberProperty.link( numberObserver );
This can be fixed by moving the alignment code into an observer of |
Fixed in the above commit, tested in State Wrapper. @phet-steele please verify in master. If it's OK, you can simply close this issue. Since this problem was introduced recently by #96, it was never published in a production version. |
This looks fixed in master on my Win 10 Chrome. |
Thanks @phet-steele. |
Some notes!
Seen on Win 10 Chrome and FF. For phetsims/qa/issues/648.
The text was updated successfully, but these errors were encountered: