Skip to content

Commit

Permalink
collect derived strings in FMWDerivedStrings.ts, #235
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jun 5, 2023
1 parent 61e4fca commit 752803f
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 137 deletions.
148 changes: 148 additions & 0 deletions js/common/FMWDerivedStrings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright 2023, University of Colorado Boulder

/**
* Derived strings used globally throughout this simulation.
*
* @author Chris Malley (PixelZoom, Inc.)
*/

import fourierMakingWaves from '../fourierMakingWaves.js';
import Tandem from '../../../tandem/js/Tandem.js';
import FMWSymbols from './FMWSymbols.js';
import PatternStringProperty from '../../../axon/js/PatternStringProperty.js';
import FourierMakingWavesStrings from '../FourierMakingWavesStrings.js';
import StringProperty from '../../../axon/js/StringProperty.js';

//TODO https://github.com/phetsims/tandem/issues/298
const DERIVED_STRINGS_TANDEM = Tandem.GENERAL_MODEL.createTandem( 'strings' ).createTandem( 'fourierMakingWaves' ).createTandem( 'derivedStrings' )

const FMWDerivedStrings = {

k1StringProperty: new PatternStringProperty( new StringProperty( '{{k}}<sub>1</sub>' ), {
k: FMWSymbols.kStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'k1StringProperty' )
} ),

omega1StringProperty: new PatternStringProperty( new StringProperty( '{{omega}}<sub>1</sub>' ), {
omega: FMWSymbols.omegaStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'omega1StringProperty' )
} ),

xMetersStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, {
symbol: FMWSymbols.xStringProperty,
units: FourierMakingWavesStrings.units.metersStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'xMetersStringProperty' )
} ),

xMillisecondsStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, {
symbol: FMWSymbols.tStringProperty,
units: FourierMakingWavesStrings.units.millisecondsStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'xMillisecondsStringProperty' )
} ),

spaceXStringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceSymbolStringProperty, {
symbol: FMWSymbols.xStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'spaceXStringProperty' )
} ),

timeTStringProperty: new PatternStringProperty( FourierMakingWavesStrings.timeSymbolStringProperty, {
symbol: FMWSymbols.tStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'timeTStringProperty' )
} ),

spaceAndTimeXTStringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceAndTimeSymbolsStringProperty, {
spaceSymbol: FMWSymbols.xStringProperty,
timeSymbol: FMWSymbols.tStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'spaceAndTimeXTStringProperty' )
} ),

lambdaAndTStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolAndSymbolStringProperty, {
symbol1: FMWSymbols.lambdaStringProperty,
symbol2: FMWSymbols.TStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'lambdaAndTStringProperty' )
} ),

kAndOmegaStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolAndSymbolStringProperty, {
symbol1: FMWSymbols.kStringProperty,
symbol2: FMWSymbols.omegaStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'kAndOmegaStringProperty' )
} ),

ADescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.AStringProperty, {
A: FMWSymbols.AStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'ADescriptionStringProperty' )
} ),

fDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.fStringProperty, {
f: FMWSymbols.fStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'fDescriptionStringProperty' )
} ),

lambdaDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.lambdaStringProperty, {
lambda: FMWSymbols.lambdaStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'lambdaDescriptionStringProperty' )
} ),

kDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.kStringProperty, {
k: FMWSymbols.kStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'kDescriptionStringProperty' )
} ),

LDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.LStringProperty, {
L: FMWSymbols.LStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'LDescriptionStringProperty' )
} ),

nDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.nStringProperty, {
n: FMWSymbols.nStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'nDescriptionStringProperty' )
} ),

tDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.tStringProperty, {
t: FMWSymbols.tStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'tDescriptionStringProperty' )
} ),

TDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.TStringProperty, {
T: FMWSymbols.TStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'TDescriptionStringProperty' )
} ),

omegaDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.omegaStringProperty, {
omega: FMWSymbols.omegaStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'omegaDescriptionStringProperty' )
} ),

sigmaDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.sigmaStringProperty, {
sigma: FMWSymbols.sigmaStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'sigmaDescriptionStringProperty' )
} ),

xDescriptionStringProperty: new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.xStringProperty, {
x: FMWSymbols.xStringProperty
}, {
tandem: DERIVED_STRINGS_TANDEM.createTandem( 'xDescriptionStringProperty' )
} )
};

fourierMakingWaves.register( 'FMWDerivedStrings', FMWDerivedStrings );
export default FMWDerivedStrings;
14 changes: 10 additions & 4 deletions js/common/view/AmplitudeKeypadDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import optionize, { combineOptions } from '../../../../phet-core/js/optionize.js
import Bounds2 from '../../../../dot/js/Bounds2.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import StringIO from '../../../../tandem/js/types/StringIO.js';

// constants
const TITLE_FONT = new PhetFont( 18 );
Expand Down Expand Up @@ -104,8 +104,12 @@ export default class AmplitudeKeypadDialog extends Dialog {
} );

// Title indicates which amplitude we're editing, e.g. A<sub>2</sub>.
const titleStringProperty = new DerivedProperty( [ FMWSymbols.AStringProperty, orderProperty ],
( A, order ) => `${A}<sub>${order}</sub>` );
const titleStringProperty = new DerivedProperty(
[ FMWSymbols.AStringProperty, orderProperty ],
( A, order ) => `${A}<sub>${order}</sub>`, {
tandem: options.tandem.createTandem( 'titleStringProperty' ),
phetioValueType: StringIO
} );
const titleNode = new RichText( titleStringProperty, {
font: TITLE_FONT,
maxWidth: keypad.width
Expand All @@ -115,7 +119,9 @@ export default class AmplitudeKeypadDialog extends Dialog {
const rangeStringProperty = new PatternStringProperty( FourierMakingWavesStrings.minToMaxStringProperty, {
min: Utils.toFixedNumber( amplitudeRange.min, options.decimalPlaces ),
max: Utils.toFixedNumber( amplitudeRange.max, options.decimalPlaces )
}, { tandem: Tandem.OPT_OUT } );
}, {
tandem: options.tandem.createTandem( 'rangeStringProperty' )
} );
const rangeNode = new Text( rangeStringProperty, {
font: VALUE_FONT,
maxWidth: keypad.width
Expand Down
9 changes: 7 additions & 2 deletions js/common/view/AmplitudeNumberDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AmplitudeKeypadDialog from './AmplitudeKeypadDialog.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import optionize from '../../../../phet-core/js/optionize.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import StringIO from '../../../../tandem/js/types/StringIO.js';

// constants
const DEFAULT_FONT = new PhetFont( 14 );
Expand Down Expand Up @@ -61,8 +62,12 @@ export default class AmplitudeNumberDisplay extends InteractiveHighlighting( VBo
const numberDisplay = new NumberDisplay( harmonic.amplitudeProperty, harmonic.amplitudeProperty.range,
options.numberDisplayOptions );

const labelStringProperty = new DerivedProperty( [ FMWSymbols.AStringProperty ],
A => `${A}<sub>${harmonic.order}</sub>` );
const labelStringProperty = new DerivedProperty(
[ FMWSymbols.AStringProperty ],
A => `${A}<sub>${harmonic.order}</sub>`, {
tandem: options.tandem.createTandem( 'labelStringProperty' ),
phetioValueType: StringIO
} );

const labelNode = new RichText( labelStringProperty, {
font: DEFAULT_FONT,
Expand Down
26 changes: 9 additions & 17 deletions js/common/view/DomainChartNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Multilink from '../../../../axon/js/Multilink.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import AxisLine, { AxisLineOptions } from '../../../../bamboo/js/AxisLine.js';
import ChartRectangle, { ChartRectangleOptions } from '../../../../bamboo/js/ChartRectangle.js';
import ChartTransform, { ChartTransformOptions } from '../../../../bamboo/js/ChartTransform.js';
Expand All @@ -31,25 +30,16 @@ import fourierMakingWaves from '../../fourierMakingWaves.js';
import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js';
import FMWColors from '../FMWColors.js';
import FMWConstants from '../FMWConstants.js';
import FMWSymbols from '../FMWSymbols.js';
import Domain from '../model/Domain.js';
import DomainChart from '../model/DomainChart.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import optionize from '../../../../phet-core/js/optionize.js';
import Tandem from '../../../../tandem/js/Tandem.js';

// constants
const DEFAULT_X_SPACE_LABEL_PROPERTY = new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, {
symbol: FMWSymbols.xStringProperty,
units: FourierMakingWavesStrings.units.metersStringProperty
}, { tandem: Tandem.OPT_OUT } );
const DEFAULT_X_TIME_LABEL_PROPERTY = new PatternStringProperty( FourierMakingWavesStrings.symbolUnitsStringProperty, {
symbol: FMWSymbols.tStringProperty,
units: FourierMakingWavesStrings.units.millisecondsStringProperty
}, { tandem: Tandem.OPT_OUT } );
import StringIO from '../../../../tandem/js/types/StringIO.js';
import FMWDerivedStrings from '../FMWDerivedStrings.js';

const DEFAULT_EDGE = 'min';

type SelfOptions = {
Expand Down Expand Up @@ -107,8 +97,8 @@ export default class DomainChartNode extends Node {
const options = optionize<DomainChartNodeOptions, SelfOptions, NodeOptions>()( {

// x-axis
xSpaceLabelProperty: DEFAULT_X_SPACE_LABEL_PROPERTY,
xTimeLabelProperty: DEFAULT_X_TIME_LABEL_PROPERTY,
xSpaceLabelProperty: FMWDerivedStrings.xMetersStringProperty,
xTimeLabelProperty: FMWDerivedStrings.xMillisecondsStringProperty,
xGridLineSpacing: 1,
xTickMarkSpacing: 1,
xTickLabelSpacing: 1,
Expand Down Expand Up @@ -172,8 +162,10 @@ export default class DomainChartNode extends Node {

const xAxisLabelStringProperty = new DerivedProperty(
[ domainProperty, options.xTimeLabelProperty, options.xSpaceLabelProperty ],
( domain, xTimeLabel, xSpaceLabel ) => ( domain === Domain.TIME ) ? xTimeLabel : xSpaceLabel
);
( domain, xTimeLabel, xSpaceLabel ) => ( domain === Domain.TIME ) ? xTimeLabel : xSpaceLabel, {
tandem: options.tandem.createTandem( 'xAxisLabelStringProperty' ),
phetioValueType: StringIO
} );

// x-axis
const xAxis = new AxisLine( chartTransform, Orientation.HORIZONTAL, options.axisLineOptions );
Expand Down
17 changes: 4 additions & 13 deletions js/common/view/DomainComboBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,30 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import { Node } from '../../../../scenery/js/imports.js';
import ComboBox from '../../../../sun/js/ComboBox.js';
import fourierMakingWaves from '../../fourierMakingWaves.js';
import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js';
import FMWSymbols from '../FMWSymbols.js';
import Domain from '../model/Domain.js';
import FMWComboBox, { FMWComboBoxChoice } from './FMWComboBox.js';
import Property from '../../../../axon/js/Property.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import FMWDerivedStrings from '../FMWDerivedStrings.js';

// This format is specific to FMWComboBox.
const CHOICES: FMWComboBoxChoice<Domain>[] = [
{
value: Domain.SPACE,
stringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceSymbolStringProperty, {
symbol: FMWSymbols.xStringProperty
}, { tandem: Tandem.OPT_OUT } ),
stringProperty: FMWDerivedStrings.spaceXStringProperty,
tandemName: `spaceItem${ComboBox.ITEM_TANDEM_NAME_SUFFIX}`
},
{
value: Domain.TIME,
stringProperty: new PatternStringProperty( FourierMakingWavesStrings.timeSymbolStringProperty, {
symbol: FMWSymbols.tStringProperty
}, { tandem: Tandem.OPT_OUT } ),
stringProperty: FMWDerivedStrings.timeTStringProperty,
tandemName: `time${ComboBox.ITEM_TANDEM_NAME_SUFFIX}`
},
{
value: Domain.SPACE_AND_TIME,
stringProperty: new PatternStringProperty( FourierMakingWavesStrings.spaceAndTimeSymbolsStringProperty, {
spaceSymbol: FMWSymbols.xStringProperty,
timeSymbol: FMWSymbols.tStringProperty
}, { tandem: Tandem.OPT_OUT } ),
stringProperty: FMWDerivedStrings.spaceAndTimeXTStringProperty,
tandemName: `spaceAndTime${ComboBox.ITEM_TANDEM_NAME_SUFFIX}`
}
];
Expand Down
1 change: 1 addition & 0 deletions js/common/view/SumSymbolNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class SumSymbolNode extends Node {
font: options.symbolFont
} );

// Not instrumented for PhET-iO.
const nEqualsStringProperty = new DerivedProperty( [ indexSymbolProperty ],
indexSymbol => `${indexSymbol} ${MathSymbols.EQUAL_TO}&nbsp` );

Expand Down
1 change: 1 addition & 0 deletions js/common/view/TickLabelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const TickLabelUtils = {

const symbolStringProperty = ( typeof symbol === 'string' ) ? new StringProperty( symbol ) : symbol;

// Not instrumented for PhET-iO.
richTextArgument = new DerivedProperty( [ symbolStringProperty ], symbol => {
let text = '';
if ( sign === -1 ) {
Expand Down
43 changes: 11 additions & 32 deletions js/discrete/view/DiscreteInfoDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
*/

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import { RichText, Text } from '../../../../scenery/js/imports.js';
import Dialog from '../../../../sun/js/Dialog.js';
import FMWConstants from '../../common/FMWConstants.js';
import FMWSymbols from '../../common/FMWSymbols.js';
import fourierMakingWaves from '../../fourierMakingWaves.js';
import FourierMakingWavesStrings from '../../FourierMakingWavesStrings.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import FMWDerivedStrings from '../../common/FMWDerivedStrings.js';

// constants
const MAX_WIDTH = 800; // determined empirically
Expand All @@ -30,36 +29,16 @@ export default class DiscreteInfoDialog extends Dialog {

// For each translated string describing a symbol, fill in the symbol.
const stringProperties = [
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.AStringProperty, {
A: FMWSymbols.AStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.fStringProperty, {
f: FMWSymbols.fStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.lambdaStringProperty, {
lambda: FMWSymbols.lambdaStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.kStringProperty, {
k: FMWSymbols.kStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.LStringProperty, {
L: FMWSymbols.LStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.nStringProperty, {
n: FMWSymbols.nStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.tStringProperty, {
t: FMWSymbols.tStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.TStringProperty, {
T: FMWSymbols.TStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.omegaStringProperty, {
omega: FMWSymbols.omegaStringProperty
}, { tandem: Tandem.OPT_OUT } ),
new PatternStringProperty( FourierMakingWavesStrings.symbolsDialog.xStringProperty, {
x: FMWSymbols.xStringProperty
}, { tandem: Tandem.OPT_OUT } )
FMWDerivedStrings.ADescriptionStringProperty,
FMWDerivedStrings.fDescriptionStringProperty,
FMWDerivedStrings.lambdaDescriptionStringProperty,
FMWDerivedStrings.kDescriptionStringProperty,
FMWDerivedStrings.LDescriptionStringProperty,
FMWDerivedStrings.nDescriptionStringProperty,
FMWDerivedStrings.tDescriptionStringProperty,
FMWDerivedStrings.TDescriptionStringProperty,
FMWDerivedStrings.omegaDescriptionStringProperty,
FMWDerivedStrings.xDescriptionStringProperty
];

// Put a line break between each of the above strings.
Expand Down
Loading

0 comments on commit 752803f

Please sign in to comment.