From 66f6b2cd6d1ea2c48fa472f18a58d195affd32b9 Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 30 Nov 2022 18:27:58 -0500 Subject: [PATCH] converte to StringProperty, see https://github.com/phetsims/energy-skate-park/issues/350 --- energy-skate-park_en.html | 3 ++ js/EnergySkateParkStrings.ts | 54 ------------------- js/common/view/EnergyBarGraph.js | 10 ++-- .../view/EnergySkateParkGravityControls.js | 2 +- js/common/view/EnergySkateParkGridNode.js | 2 +- js/common/view/EnergySkateParkScreenView.js | 6 +-- .../view/EnergySkateParkVisibilityControls.js | 12 ++--- js/common/view/FrictionSlider.js | 2 +- js/common/view/GravityComboBox.js | 6 +-- js/common/view/GravityNumberControl.js | 4 +- js/common/view/GravitySlider.js | 4 +- js/common/view/MassComboBox.js | 14 ++--- js/common/view/MassNumberControl.js | 4 +- js/common/view/MassSlider.js | 6 +-- js/common/view/PhysicalComboBox.js | 2 +- js/common/view/PhysicalSlider.js | 4 +- js/common/view/PieChartLegend.js | 10 ++-- js/common/view/ReferenceHeightLine.js | 2 +- js/common/view/TextPanel.js | 6 +-- js/graphs/view/EnergyGraphAccordionBox.js | 36 ++++++++----- js/measure/view/SkaterPathSensorNode.js | 16 +++--- package.json | 3 ++ 22 files changed, 85 insertions(+), 123 deletions(-) diff --git a/energy-skate-park_en.html b/energy-skate-park_en.html index 71de68f6..97a04a3b 100644 --- a/energy-skate-park_en.html +++ b/energy-skate-park_en.html @@ -46,6 +46,9 @@ "adapted-from-phet" ], "simulation": true, + "simFeatures": { + "supportsDynamicLocale": true + }, "phet-io": { "validation": false }, diff --git a/js/EnergySkateParkStrings.ts b/js/EnergySkateParkStrings.ts index add4d4be..44911c66 100644 --- a/js/EnergySkateParkStrings.ts +++ b/js/EnergySkateParkStrings.ts @@ -10,145 +10,91 @@ import energySkatePark from './energySkatePark.js'; type StringsType = { 'energy-skate-park': { - 'title': string; 'titleStringProperty': LinkableProperty; }; 'physicalControls': { 'gravityControls': { - 'gravity': string; 'gravityStringProperty': LinkableProperty; - 'earth': string; 'earthStringProperty': LinkableProperty; - 'jupiter': string; 'jupiterStringProperty': LinkableProperty; - 'moon': string; 'moonStringProperty': LinkableProperty; - 'gravityMetersPerSecondSquaredPattern': string; 'gravityMetersPerSecondSquaredPatternStringProperty': LinkableProperty; - 'gravityNewtonsPerKilogramPattern': string; 'gravityNewtonsPerKilogramPatternStringProperty': LinkableProperty; }; 'massControls': { - 'mass': string; 'massStringProperty': LinkableProperty; - 'massKilogramsPattern': string; 'massKilogramsPatternStringProperty': LinkableProperty; }; - 'friction': string; 'frictionStringProperty': LinkableProperty; - 'custom': string; 'customStringProperty': LinkableProperty; - 'small': string; 'smallStringProperty': LinkableProperty; - 'large': string; 'largeStringProperty': LinkableProperty; - 'lots': string; 'lotsStringProperty': LinkableProperty; - 'none': string; 'noneStringProperty': LinkableProperty; - 'tiny': string; 'tinyStringProperty': LinkableProperty; }; 'energies': { - 'thermal': string; 'thermalStringProperty': LinkableProperty; - 'total': string; 'totalStringProperty': LinkableProperty; - 'kinetic': string; 'kineticStringProperty': LinkableProperty; - 'potential': string; 'potentialStringProperty': LinkableProperty; - 'energy': string; 'energyStringProperty': LinkableProperty; }; 'plots': { 'barGraph': { - 'label': string; 'labelStringProperty': LinkableProperty; }; 'energyGraph': { - 'label': string; 'labelStringProperty': LinkableProperty; }; 'pieChart': { - 'label': string; 'labelStringProperty': LinkableProperty; }; - 'timeSwitchLabel': string; 'timeSwitchLabelStringProperty': LinkableProperty; - 'positionSwitchLabel': string; 'positionSwitchLabelStringProperty': LinkableProperty; - 'timeLabel': string; 'timeLabelStringProperty': LinkableProperty; - 'positionLabel': string; 'positionLabelStringProperty': LinkableProperty; - 'energyLabel': string; 'energyLabelStringProperty': LinkableProperty; }; 'visibilityControls': { - 'grid': string; 'gridStringProperty': LinkableProperty; - 'referenceHeight': string; 'referenceHeightStringProperty': LinkableProperty; - 'path': string; 'pathStringProperty': LinkableProperty; - 'speed': string; 'speedStringProperty': LinkableProperty; }; 'skaterControls': { - 'label': string; 'labelStringProperty': LinkableProperty; - 'skater1MassPattern': string; 'skater1MassPatternStringProperty': LinkableProperty; - 'skater2MassPattern': string; 'skater2MassPatternStringProperty': LinkableProperty; - 'skater3MassPattern': string; 'skater3MassPatternStringProperty': LinkableProperty; - 'skater4MassPattern': string; 'skater4MassPatternStringProperty': LinkableProperty; - 'skater5MassPattern': string; 'skater5MassPatternStringProperty': LinkableProperty; - 'dogMassPattern': string; 'dogMassPatternStringProperty': LinkableProperty; - 'restartSkater': string; 'restartSkaterStringProperty': LinkableProperty; }; 'trackControls': { - 'stickToTrack': string; 'stickToTrackStringProperty': LinkableProperty; }; 'screens': { - 'intro': string; 'introStringProperty': LinkableProperty; - 'graphs': string; 'graphsStringProperty': LinkableProperty; - 'playground': string; 'playgroundStringProperty': LinkableProperty; - 'measure': string; 'measureStringProperty': LinkableProperty; }; 'heightLabels': { - 'zeroM': string; 'zeroMStringProperty': LinkableProperty; - 'heightEqualsZero': string; 'heightEqualsZeroStringProperty': LinkableProperty; }; 'pathSensor': { - 'energyJoulesPattern': string; 'energyJoulesPatternStringProperty': LinkableProperty; - 'heightMetersPattern': string; 'heightMetersPatternStringProperty': LinkableProperty; - 'speedMetersPerSecondPattern': string; 'speedMetersPerSecondPatternStringProperty': LinkableProperty; }; 'speedometer': { - 'label': string; 'labelStringProperty': LinkableProperty; - 'metersPerSecondPattern': string; 'metersPerSecondPatternStringProperty': LinkableProperty; }; 'measuringTape': { - 'units': string; 'unitsStringProperty': LinkableProperty; } }; diff --git a/js/common/view/EnergyBarGraph.js b/js/common/view/EnergyBarGraph.js index 459c362d..5a15d9dd 100644 --- a/js/common/view/EnergyBarGraph.js +++ b/js/common/view/EnergyBarGraph.js @@ -21,11 +21,11 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import EnergySkateParkColorScheme from './EnergySkateParkColorScheme.js'; -const energyEnergyString = EnergySkateParkStrings.energies.energy; -const energyKineticString = EnergySkateParkStrings.energies.kinetic; -const energyPotentialString = EnergySkateParkStrings.energies.potential; -const energyThermalString = EnergySkateParkStrings.energies.thermal; -const energyTotalString = EnergySkateParkStrings.energies.total; +const energyEnergyString = EnergySkateParkStrings.energies.energyStringProperty; +const energyKineticString = EnergySkateParkStrings.energies.kineticStringProperty; +const energyPotentialString = EnergySkateParkStrings.energies.potentialStringProperty; +const energyThermalString = EnergySkateParkStrings.energies.thermalStringProperty; +const energyTotalString = EnergySkateParkStrings.energies.totalStringProperty; // constants const ZOOM_BUTTON_TOUCH_DILATION = 5; diff --git a/js/common/view/EnergySkateParkGravityControls.js b/js/common/view/EnergySkateParkGravityControls.js index e00a5441..ff7101dd 100644 --- a/js/common/view/EnergySkateParkGravityControls.js +++ b/js/common/view/EnergySkateParkGravityControls.js @@ -16,7 +16,7 @@ import GravityNumberControl from './GravityNumberControl.js'; import GravitySlider from './GravitySlider.js'; // constants -const gravityNewtonsPerKilogramPatternString = EnergySkateParkStrings.physicalControls.gravityControls.gravityNewtonsPerKilogramPattern; +const gravityNewtonsPerKilogramPatternString = EnergySkateParkStrings.physicalControls.gravityControls.gravityNewtonsPerKilogramPatternStringProperty; class EnergySkateParkGravityControls extends VBox { diff --git a/js/common/view/EnergySkateParkGridNode.js b/js/common/view/EnergySkateParkGridNode.js index 1520d920..7d43e42b 100644 --- a/js/common/view/EnergySkateParkGridNode.js +++ b/js/common/view/EnergySkateParkGridNode.js @@ -57,7 +57,7 @@ class EnergySkateParkGridNode extends Node { this.labelXPosition = this.modelViewTransform.modelToViewX( -5 ); // @private {TextPanel} - a unique label for the zero meter reference height position - this.zeroMeterLabel = new TextPanel( EnergySkateParkStrings.heightLabels.zeroM, { + this.zeroMeterLabel = new TextPanel( EnergySkateParkStrings.heightLabels.zeroMStringProperty, { bottom: this.modelViewTransform.modelToViewY( 0 ) - 2, right: this.labelXPosition - 2 } ); diff --git a/js/common/view/EnergySkateParkScreenView.js b/js/common/view/EnergySkateParkScreenView.js index 2d440b36..6c2ae6f6 100644 --- a/js/common/view/EnergySkateParkScreenView.js +++ b/js/common/view/EnergySkateParkScreenView.js @@ -45,10 +45,10 @@ import ToolboxPanel from './ToolboxPanel.js'; import TrackNode from './TrackNode.js'; import VisibilityControlsPanel from './VisibilityControlsPanel.js'; -const controlsRestartSkaterString = EnergySkateParkStrings.skaterControls.restartSkater; +const controlsRestartSkaterString = EnergySkateParkStrings.skaterControls.restartSkaterStringProperty; const propertiesSpeedStringProperty = EnergySkateParkStrings.speedometer.labelStringProperty; -const speedometerMetersPerSecondPatternString = EnergySkateParkStrings.speedometer.metersPerSecondPattern; -const measuringTapeUnitsString = EnergySkateParkStrings.measuringTape.units; +const speedometerMetersPerSecondPatternString = EnergySkateParkStrings.speedometer.metersPerSecondPatternStringProperty; +const measuringTapeUnitsString = EnergySkateParkStrings.measuringTape.unitsStringProperty; // constants // for wider screens, panels can float to the left and right by this much beyond dev bounds in view coordinates diff --git a/js/common/view/EnergySkateParkVisibilityControls.js b/js/common/view/EnergySkateParkVisibilityControls.js index 24583806..d7c138eb 100644 --- a/js/common/view/EnergySkateParkVisibilityControls.js +++ b/js/common/view/EnergySkateParkVisibilityControls.js @@ -19,12 +19,12 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import EnergySkateParkCheckboxItem from './EnergySkateParkCheckboxItem.js'; -const controlsPathString = EnergySkateParkStrings.visibilityControls.path; -const controlsReferenceHeightString = EnergySkateParkStrings.visibilityControls.referenceHeight; -const controlsShowGridString = EnergySkateParkStrings.visibilityControls.grid; -const controlsStickToTrackString = EnergySkateParkStrings.trackControls.stickToTrack; -const pieChartString = EnergySkateParkStrings.plots.pieChart.label; -const propertiesSpeedString = EnergySkateParkStrings.visibilityControls.speed; +const controlsPathString = EnergySkateParkStrings.visibilityControls.pathStringProperty; +const controlsReferenceHeightString = EnergySkateParkStrings.visibilityControls.referenceHeightStringProperty; +const controlsShowGridString = EnergySkateParkStrings.visibilityControls.gridStringProperty; +const controlsStickToTrackString = EnergySkateParkStrings.trackControls.stickToTrackStringProperty; +const pieChartString = EnergySkateParkStrings.plots.pieChart.labelStringProperty; +const propertiesSpeedString = EnergySkateParkStrings.visibilityControls.speedStringProperty; // constants const TEXT_OPTIONS = { diff --git a/js/common/view/FrictionSlider.js b/js/common/view/FrictionSlider.js index 78584784..732289c5 100644 --- a/js/common/view/FrictionSlider.js +++ b/js/common/view/FrictionSlider.js @@ -12,7 +12,7 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import PhysicalSlider from './PhysicalSlider.js'; -const controlsFrictionTitleString = EnergySkateParkStrings.physicalControls.friction; +const controlsFrictionTitleString = EnergySkateParkStrings.physicalControls.frictionStringProperty; class FrictionSlider extends PhysicalSlider { diff --git a/js/common/view/GravityComboBox.js b/js/common/view/GravityComboBox.js index f6bd1399..283c8ecf 100644 --- a/js/common/view/GravityComboBox.js +++ b/js/common/view/GravityComboBox.js @@ -13,9 +13,9 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import PhysicalComboBox from './PhysicalComboBox.js'; -const gravityMoonString = EnergySkateParkStrings.physicalControls.gravityControls.moon; -const gravityEarthString = EnergySkateParkStrings.physicalControls.gravityControls.earth; -const gravityJupiterString = EnergySkateParkStrings.physicalControls.gravityControls.jupiter; +const gravityMoonString = EnergySkateParkStrings.physicalControls.gravityControls.moonStringProperty; +const gravityEarthString = EnergySkateParkStrings.physicalControls.gravityControls.earthStringProperty; +const gravityJupiterString = EnergySkateParkStrings.physicalControls.gravityControls.jupiterStringProperty; class GravityComboBox extends PhysicalComboBox { diff --git a/js/common/view/GravityNumberControl.js b/js/common/view/GravityNumberControl.js index 276433df..bee1fee3 100644 --- a/js/common/view/GravityNumberControl.js +++ b/js/common/view/GravityNumberControl.js @@ -14,8 +14,8 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import PhysicalNumberControl from './PhysicalNumberControl.js'; -const controlsGravityLabelString = EnergySkateParkStrings.physicalControls.gravityControls.gravity; -const gravityMetersPerSecondSquaredPatternString = EnergySkateParkStrings.physicalControls.gravityControls.gravityMetersPerSecondSquaredPattern; +const controlsGravityLabelString = EnergySkateParkStrings.physicalControls.gravityControls.gravityStringProperty; +const gravityMetersPerSecondSquaredPatternString = EnergySkateParkStrings.physicalControls.gravityControls.gravityMetersPerSecondSquaredPatternStringProperty; class GravityNumberControl extends PhysicalNumberControl { diff --git a/js/common/view/GravitySlider.js b/js/common/view/GravitySlider.js index 52f9aac9..a03cbcba 100644 --- a/js/common/view/GravitySlider.js +++ b/js/common/view/GravitySlider.js @@ -13,8 +13,8 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import PhysicalSlider from './PhysicalSlider.js'; -const controlsGravityLabelString = EnergySkateParkStrings.physicalControls.gravityControls.gravity; -const controlsValueTinyString = EnergySkateParkStrings.physicalControls.tiny; +const controlsGravityLabelString = EnergySkateParkStrings.physicalControls.gravityControls.gravityStringProperty; +const controlsValueTinyString = EnergySkateParkStrings.physicalControls.tinyStringProperty; class GravitySlider extends PhysicalSlider { diff --git a/js/common/view/MassComboBox.js b/js/common/view/MassComboBox.js index d6458052..fc4a0096 100644 --- a/js/common/view/MassComboBox.js +++ b/js/common/view/MassComboBox.js @@ -15,13 +15,13 @@ import SkaterMasses from '../SkaterMasses.js'; import LabelledComboBox from './LabelledComboBox.js'; import PhysicalComboBox from './PhysicalComboBox.js'; -const controlsSkaterString = EnergySkateParkStrings.skaterControls.label; -const controlsSkater1MassPatternString = EnergySkateParkStrings.skaterControls.skater1MassPattern; -const controlsSkater2MassPatternString = EnergySkateParkStrings.skaterControls.skater2MassPattern; -const controlsSkater3MassPatternString = EnergySkateParkStrings.skaterControls.skater3MassPattern; -const controlsSkater4MassPatternString = EnergySkateParkStrings.skaterControls.skater4MassPattern; -const controlsSkater5MassPatternString = EnergySkateParkStrings.skaterControls.skater5MassPattern; -const controlsDogMassPatternString = EnergySkateParkStrings.skaterControls.dogMassPattern; +const controlsSkaterString = EnergySkateParkStrings.skaterControls.labelStringProperty; +const controlsSkater1MassPatternString = EnergySkateParkStrings.skaterControls.skater1MassPatternStringProperty; +const controlsSkater2MassPatternString = EnergySkateParkStrings.skaterControls.skater2MassPatternStringProperty; +const controlsSkater3MassPatternString = EnergySkateParkStrings.skaterControls.skater3MassPatternStringProperty; +const controlsSkater4MassPatternString = EnergySkateParkStrings.skaterControls.skater4MassPatternStringProperty; +const controlsSkater5MassPatternString = EnergySkateParkStrings.skaterControls.skater5MassPatternStringProperty; +const controlsDogMassPatternString = EnergySkateParkStrings.skaterControls.dogMassPatternStringProperty; class MassComboBox extends LabelledComboBox { diff --git a/js/common/view/MassNumberControl.js b/js/common/view/MassNumberControl.js index af003efe..b5a6ba96 100644 --- a/js/common/view/MassNumberControl.js +++ b/js/common/view/MassNumberControl.js @@ -11,8 +11,8 @@ import energySkatePark from '../../energySkatePark.js'; import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import PhysicalNumberControl from './PhysicalNumberControl.js'; -const controlsMassString = EnergySkateParkStrings.physicalControls.massControls.mass; -const massKilogramsPatternString = EnergySkateParkStrings.physicalControls.massControls.massKilogramsPattern; +const controlsMassString = EnergySkateParkStrings.physicalControls.massControls.massStringProperty; +const massKilogramsPatternString = EnergySkateParkStrings.physicalControls.massControls.massKilogramsPatternStringProperty; class MassNumberControl extends PhysicalNumberControl { diff --git a/js/common/view/MassSlider.js b/js/common/view/MassSlider.js index 7c9d7fbe..8d23cbe0 100644 --- a/js/common/view/MassSlider.js +++ b/js/common/view/MassSlider.js @@ -11,9 +11,9 @@ import energySkatePark from '../../energySkatePark.js'; import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import PhysicalSlider from './PhysicalSlider.js'; -const controlsMassString = EnergySkateParkStrings.physicalControls.massControls.mass; -const smallString = EnergySkateParkStrings.physicalControls.small; -const largeString = EnergySkateParkStrings.physicalControls.large; +const controlsMassString = EnergySkateParkStrings.physicalControls.massControls.massStringProperty; +const smallString = EnergySkateParkStrings.physicalControls.smallStringProperty; +const largeString = EnergySkateParkStrings.physicalControls.largeStringProperty; class MassSlider extends PhysicalSlider { diff --git a/js/common/view/PhysicalComboBox.js b/js/common/view/PhysicalComboBox.js index f67425d1..13f4c74e 100644 --- a/js/common/view/PhysicalComboBox.js +++ b/js/common/view/PhysicalComboBox.js @@ -19,7 +19,7 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; // constants -const controlsGravityCustomString = EnergySkateParkStrings.physicalControls.custom; +const controlsGravityCustomString = EnergySkateParkStrings.physicalControls.customStringProperty; class PhysicalComboBox extends ComboBox { diff --git a/js/common/view/PhysicalSlider.js b/js/common/view/PhysicalSlider.js index f99d3820..8be09585 100644 --- a/js/common/view/PhysicalSlider.js +++ b/js/common/view/PhysicalSlider.js @@ -16,8 +16,8 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import PhysicalNumberControl from './PhysicalNumberControl.js'; -const controlsValueLotsString = EnergySkateParkStrings.physicalControls.lots; -const controlsValueNoneString = EnergySkateParkStrings.physicalControls.none; +const controlsValueLotsString = EnergySkateParkStrings.physicalControls.lotsStringProperty; +const controlsValueNoneString = EnergySkateParkStrings.physicalControls.noneStringProperty; class PhysicalSlider extends PhysicalNumberControl { diff --git a/js/common/view/PieChartLegend.js b/js/common/view/PieChartLegend.js index d15ecb0b..d6f5d141 100644 --- a/js/common/view/PieChartLegend.js +++ b/js/common/view/PieChartLegend.js @@ -16,11 +16,11 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkConstants from '../EnergySkateParkConstants.js'; import EnergySkateParkColorScheme from './EnergySkateParkColorScheme.js'; -const energyEnergyString = EnergySkateParkStrings.energies.energy; -const energyKineticString = EnergySkateParkStrings.energies.kinetic; -const energyPotentialString = EnergySkateParkStrings.energies.potential; -const energyThermalString = EnergySkateParkStrings.energies.thermal; -const energyTotalString = EnergySkateParkStrings.energies.total; +const energyEnergyString = EnergySkateParkStrings.energies.energyStringProperty; +const energyKineticString = EnergySkateParkStrings.energies.kineticStringProperty; +const energyPotentialString = EnergySkateParkStrings.energies.potentialStringProperty; +const energyThermalString = EnergySkateParkStrings.energies.thermalStringProperty; +const energyTotalString = EnergySkateParkStrings.energies.totalStringProperty; class PieChartLegend extends Panel { diff --git a/js/common/view/ReferenceHeightLine.js b/js/common/view/ReferenceHeightLine.js index bf2b1f65..3cb2ecde 100644 --- a/js/common/view/ReferenceHeightLine.js +++ b/js/common/view/ReferenceHeightLine.js @@ -18,7 +18,7 @@ import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; import EnergySkateParkColorScheme from './EnergySkateParkColorScheme.js'; import TextPanel from './TextPanel.js'; -const heightEqualsZeroString = EnergySkateParkStrings.heightLabels.heightEqualsZero; +const heightEqualsZeroString = EnergySkateParkStrings.heightLabels.heightEqualsZeroStringProperty; class ReferenceHeightLine extends Node { diff --git a/js/common/view/TextPanel.js b/js/common/view/TextPanel.js index 8393b0f1..9a6e61ce 100644 --- a/js/common/view/TextPanel.js +++ b/js/common/view/TextPanel.js @@ -17,10 +17,10 @@ import EnergySkateParkColorScheme from './EnergySkateParkColorScheme.js'; class TextPanel extends Panel { /** - * @param {string} textContent - text to fill the panel + * @param {LinkableProperty} stringProperty - text to fill the panel * @param {Object} [options] */ - constructor( textContent, options ) { + constructor( stringProperty, options ) { options = merge( { @@ -37,7 +37,7 @@ class TextPanel extends Panel { resize: false // assumes the text content is static }, options ); - const text = new Text( textContent, { + const text = new Text( stringProperty, { font: options.font, maxWidth: options.textMaxWidth } ); diff --git a/js/graphs/view/EnergyGraphAccordionBox.js b/js/graphs/view/EnergyGraphAccordionBox.js index 054f8922..f4e7ccc1 100644 --- a/js/graphs/view/EnergyGraphAccordionBox.js +++ b/js/graphs/view/EnergyGraphAccordionBox.js @@ -7,6 +7,7 @@ * @author Jesse Greenberg (PhET Interactive Simulations) */ +import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; import Dimension2 from '../../../../dot/js/Dimension2.js'; import merge from '../../../../phet-core/js/merge.js'; import EraserButton from '../../../../scenery-phet/js/buttons/EraserButton.js'; @@ -25,16 +26,16 @@ import GraphsConstants from '../GraphsConstants.js'; import GraphsModel from '../model/GraphsModel.js'; import EnergyChart from './EnergyChart.js'; -const kineticEnergyLabelString = EnergySkateParkStrings.energies.kinetic; -const potentialEnergyLabelString = EnergySkateParkStrings.energies.potential; -const thermalEnergyLabelString = EnergySkateParkStrings.energies.thermal; -const totalEnergyLabelString = EnergySkateParkStrings.energies.total; -const timeSwitchLabelString = EnergySkateParkStrings.plots.timeSwitchLabel; -const positionSwitchLabelString = EnergySkateParkStrings.plots.positionSwitchLabel; -const plotsEnergyGraphString = EnergySkateParkStrings.plots.energyGraph.label; -const plotsPositionLabelString = EnergySkateParkStrings.plots.positionLabel; -const plotsEnergyLabelString = EnergySkateParkStrings.plots.energyLabel; -const plotsTimeLabelString = EnergySkateParkStrings.plots.timeLabel; +const kineticEnergyLabelString = EnergySkateParkStrings.energies.kineticStringProperty; +const potentialEnergyLabelString = EnergySkateParkStrings.energies.potentialStringProperty; +const thermalEnergyLabelString = EnergySkateParkStrings.energies.thermalStringProperty; +const totalEnergyLabelString = EnergySkateParkStrings.energies.totalStringProperty; +const timeSwitchLabelString = EnergySkateParkStrings.plots.timeSwitchLabelStringProperty; +const positionSwitchLabelString = EnergySkateParkStrings.plots.positionSwitchLabelStringProperty; +const plotsEnergyGraphString = EnergySkateParkStrings.plots.energyGraph.labelStringProperty; +const plotsPositionLabelStringProperty = EnergySkateParkStrings.plots.positionLabelStringProperty; +const plotsEnergyLabelString = EnergySkateParkStrings.plots.energyLabelStringProperty; +const plotsTimeLabelStringProperty = EnergySkateParkStrings.plots.timeLabelStringProperty; // constants const GRAPH_HEIGHT = 141; @@ -134,7 +135,13 @@ class EnergyGraphAccordionBox extends AccordionBox { font: LABEL_FONT, maxWidth: energyPlot.height / 2 } ); - const xLabelText = new Text( '', { font: LABEL_FONT, maxWidth: energyPlot.width } ); + + // Label the x-axis with the independent variable. + const xLabelStringProperty = new DerivedProperty( [ model.independentVariableProperty, plotsTimeLabelStringProperty, plotsPositionLabelStringProperty ], + ( independentVariable, timeLabelString, positionLabelString ) => ( independentVariable === GraphsModel.IndependentVariable.TIME ) ? timeLabelString : positionLabelString + ); + const xLabelText = new Text( xLabelStringProperty, { font: LABEL_FONT, maxWidth: energyPlot.width } ); + const yLabel = new VBox( { children: [ yLabelText, zoomButtonGroup ], spacing: 10 @@ -195,10 +202,13 @@ class EnergyGraphAccordionBox extends AccordionBox { // @private {GraphsModel} this.model = model; + // Keep xLabelText horizontally centered. + xLabelText.boundsProperty.link( () => { + xLabelText.centerX = xLabelText.globalToParentPoint( energyPlot.parentToGlobalPoint( energyPlot.center ) ).x; + } ); + // listeners - when the independent variable changes, clear all data and update labels model.independentVariableProperty.link( independentVariable => { - xLabelText.text = independentVariable === GraphsModel.IndependentVariable.TIME ? plotsTimeLabelString : plotsPositionLabelString; - xLabelText.centerX = xLabelText.globalToParentPoint( energyPlot.parentToGlobalPoint( energyPlot.center ) ).x; this.clearEnergyData(); } ); } diff --git a/js/measure/view/SkaterPathSensorNode.js b/js/measure/view/SkaterPathSensorNode.js index 936e4013..4b0e2a0b 100644 --- a/js/measure/view/SkaterPathSensorNode.js +++ b/js/measure/view/SkaterPathSensorNode.js @@ -26,14 +26,14 @@ import EnergySkateParkColorScheme from '../../common/view/EnergySkateParkColorSc import energySkatePark from '../../energySkatePark.js'; import EnergySkateParkStrings from '../../EnergySkateParkStrings.js'; -const energyEnergyString = EnergySkateParkStrings.energies.energy; -const energyJoulesPatternString = EnergySkateParkStrings.pathSensor.energyJoulesPattern; -const energyKineticString = EnergySkateParkStrings.energies.kinetic; -const energyPotentialString = EnergySkateParkStrings.energies.potential; -const energyThermalString = EnergySkateParkStrings.energies.thermal; -const energyTotalString = EnergySkateParkStrings.energies.total; -const heightMetersPatternString = EnergySkateParkStrings.pathSensor.heightMetersPattern; -const speedMetersPerSecondPatternString = EnergySkateParkStrings.pathSensor.speedMetersPerSecondPattern; +const energyEnergyString = EnergySkateParkStrings.energies.energyStringProperty; +const energyJoulesPatternString = EnergySkateParkStrings.pathSensor.energyJoulesPatternStringProperty; +const energyKineticString = EnergySkateParkStrings.energies.kineticStringProperty; +const energyPotentialString = EnergySkateParkStrings.energies.potentialStringProperty; +const energyThermalString = EnergySkateParkStrings.energies.thermalStringProperty; +const energyTotalString = EnergySkateParkStrings.energies.totalStringProperty; +const heightMetersPatternString = EnergySkateParkStrings.pathSensor.heightMetersPatternStringProperty; +const speedMetersPerSecondPatternString = EnergySkateParkStrings.pathSensor.speedMetersPerSecondPatternStringProperty; // constants const TITLE_CONTENT_SPACING = 5.5; // spacing between the "Energy" title and the rest of the content diff --git a/package.json b/package.json index 5f911809..5a3adf11 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "adapted-from-phet" ], "simulation": true, + "simFeatures": { + "supportsDynamicLocale": true + }, "phet-io": { "validation": false },