Closed pixelzoom closed 2 years ago
Does NumberDisplay.setNumberFormatter
not work for your case? Were you wanting a numberFormatterProperty
option?
Pretty hideous API (see below), but I'll roll with it. Closing.
const numberDisplay = new NumberDisplay( light.wavelengthProperty, light.wavelengthProperty.range!, {
xMargin: 7,
yMargin: 3,
tandem: options.tandem.createTandem( 'numberDisplay' )
} );
// Whenever one of the strings used to format the NumberDisplay changes, call setNumberFormatter with a
// new formatting function.
Multilink.multilink(
[ BeersLawLabStrings.pattern[ '0value' ][ '1unitsStringProperty' ], BeersLawLabStrings.units.nmStringProperty ],
( pattern, nmString ) => numberDisplay.setNumberFormatter( wavelength => StringUtils.format( pattern, Utils.toFixed( wavelength, 0 ), nmString ) )
);
NumberDisplay does not fully support dynamic text. @jonathanolson added support to the
valuePattern
option, but did not address thenumberFormatter
option. And I can see why, because it's not straightforward, or even obvious what can/should be done.This is blocking beers-law-lab https://github.com/phetsims/beers-law-lab/issues/288.
@kathy-phet do you want me to address this?