From 7dffb5aeae5650cc4a9e7519cd44d3ce40226e55 Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Thu, 19 Dec 2024 17:07:48 -0700 Subject: [PATCH] Add dynamic strings, see https://github.com/phetsims/least-squares-regression/issues/90 --- js/LeastSquaresRegressionStrings.ts | 71 ------- js/least-squares-regression/model/DataSet.ts | 188 ++++++------------ .../view/BestFitLineAccordionBox.ts | 13 +- .../CorrelationCoefficientAccordionBox.ts | 6 +- .../view/EquationNode.ts | 7 +- .../view/LeastSquaresRegressionScreenView.ts | 4 +- .../view/MyLineControlPanel.ts | 26 +-- .../view/SourceAndReferenceNode.ts | 7 +- .../view/SumOfSquaredResidualsChart.ts | 4 +- least-squares-regression_en.html | 5 +- package.json | 5 +- 11 files changed, 97 insertions(+), 239 deletions(-) diff --git a/js/LeastSquaresRegressionStrings.ts b/js/LeastSquaresRegressionStrings.ts index 372e3a6..3a48334 100644 --- a/js/LeastSquaresRegressionStrings.ts +++ b/js/LeastSquaresRegressionStrings.ts @@ -13,179 +13,108 @@ import leastSquaresRegression from './leastSquaresRegression.js'; type StringsType = { 'least-squares-regression': { - 'title': string; 'titleStringProperty': LocalizedStringProperty; }; - 'bestFitLine': string; 'bestFitLineStringProperty': LocalizedStringProperty; - 'myLine': string; 'myLineStringProperty': LocalizedStringProperty; - 'residuals': string; 'residualsStringProperty': LocalizedStringProperty; - 'squaredResiduals': string; 'squaredResidualsStringProperty': LocalizedStringProperty; - 'sum': string; 'sumStringProperty': LocalizedStringProperty; - 'a': string; 'aStringProperty': LocalizedStringProperty; - 'b': string; 'bStringProperty': LocalizedStringProperty; 'symbol': { - 'x': string; 'xStringProperty': LocalizedStringProperty; - 'y': string; 'yStringProperty': LocalizedStringProperty; - 'r': string; 'rStringProperty': LocalizedStringProperty; }; - 'questionMark': string; 'questionMarkStringProperty': LocalizedStringProperty; - 'sourcePattern': string; 'sourcePatternStringProperty': LocalizedStringProperty; - 'correlationCoefficient': string; 'correlationCoefficientStringProperty': LocalizedStringProperty; 'custom': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; }; 'temperatureFahrenheitLatitude': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'temperatureFahrenheitLongitude': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'temperatureCelsiusLatitude': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'temperatureCelsiusLongitude': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'spendingSalary': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'wageYear': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'mortalityYear': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'userYear': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'gasolineYear': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'lifeTV': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'speedDistance': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'temperatureFahrenheitChirp': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'temperatureCelsiusChirp': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; }; 'heightShoe': { - 'graphTitle': string; 'graphTitleStringProperty': LocalizedStringProperty; - 'xAxisTitle': string; 'xAxisTitleStringProperty': LocalizedStringProperty; - 'yAxisTitle': string; 'yAxisTitleStringProperty': LocalizedStringProperty; - 'reference': string; 'referenceStringProperty': LocalizedStringProperty; } }; diff --git a/js/least-squares-regression/model/DataSet.ts b/js/least-squares-regression/model/DataSet.ts index 0e1ce72..9c849ef 100644 --- a/js/least-squares-regression/model/DataSet.ts +++ b/js/least-squares-regression/model/DataSet.ts @@ -7,6 +7,8 @@ * @author Martin Veillette (Berea College) */ +import StringProperty from '../../../../axon/js/StringProperty.js'; +import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import Range from '../../../../dot/js/Range.js'; import leastSquaresRegression from '../../leastSquaresRegression.js'; import LeastSquaresRegressionStrings from '../../LeastSquaresRegressionStrings.js'; @@ -29,195 +31,137 @@ const SOURCES = { HEIGHT_SHOE_SOURCE: 'Courtney Pearson, www.statcrunch.com' }; -const custom_graphTitleString = LeastSquaresRegressionStrings.custom.graphTitle; -const temperatureCelsiusLatitude_graphTitleString = LeastSquaresRegressionStrings.temperatureCelsiusLatitude.graphTitle; -const temperatureCelsiusLatitude_yAxisTitleString = LeastSquaresRegressionStrings.temperatureCelsiusLatitude.yAxisTitle; -const temperatureCelsiusLatitude_xAxisTitleString = LeastSquaresRegressionStrings.temperatureCelsiusLatitude.xAxisTitle; -const temperatureCelsiusLatitude_referenceString = LeastSquaresRegressionStrings.temperatureCelsiusLatitude.reference; -const temperatureCelsiusLongitude_graphTitle = LeastSquaresRegressionStrings.temperatureCelsiusLongitude.graphTitle; -const temperatureCelsiusLongitude_yAxisTitle = LeastSquaresRegressionStrings.temperatureCelsiusLongitude.yAxisTitle; -const temperatureCelsiusLongitude_xAxisTitle = LeastSquaresRegressionStrings.temperatureCelsiusLongitude.xAxisTitle; -const temperatureCelsiusLongitude_reference = LeastSquaresRegressionStrings.temperatureCelsiusLongitude.reference; -const temperatureFahrenheitLatitude_graphTitle = LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.graphTitle; -const temperatureFahrenheitLatitude_yAxisTitle = LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.yAxisTitle; -const temperatureFahrenheitLatitude_xAxisTitle = LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.xAxisTitle; -const temperatureFahrenheitLatitude_reference = LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.reference; -const temperatureFahrenheitLongitude_graphTitle = LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.graphTitle; -const temperatureFahrenheitLongitude_yAxisTitle = LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.yAxisTitle; -const temperatureFahrenheitLongitude_xAxisTitle = LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.xAxisTitle; -const temperatureFahrenheitLongitude_reference = LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.reference; -const spendingSalary_graphTitle = LeastSquaresRegressionStrings.spendingSalary.graphTitle; -const spendingSalary_yAxisTitle = LeastSquaresRegressionStrings.spendingSalary.yAxisTitle; -const spendingSalary_xAxisTitle = LeastSquaresRegressionStrings.spendingSalary.xAxisTitle; -const spendingSalary_reference = LeastSquaresRegressionStrings.spendingSalary.reference; -const wageYear_graphTitle = LeastSquaresRegressionStrings.wageYear.graphTitle; -const wageYear_yAxisTitle = LeastSquaresRegressionStrings.wageYear.yAxisTitle; -const wageYear_xAxisTitle = LeastSquaresRegressionStrings.wageYear.xAxisTitle; -const wageYear_reference = LeastSquaresRegressionStrings.wageYear.reference; -const mortalityYear_graphTitle = LeastSquaresRegressionStrings.mortalityYear.graphTitle; -const mortalityYear_yAxisTitle = LeastSquaresRegressionStrings.mortalityYear.yAxisTitle; -const mortalityYear_xAxisTitle = LeastSquaresRegressionStrings.mortalityYear.xAxisTitle; -const mortalityYear_reference = LeastSquaresRegressionStrings.mortalityYear.reference; -const userYear_graphTitle = LeastSquaresRegressionStrings.userYear.graphTitle; -const userYear_yAxisTitle = LeastSquaresRegressionStrings.userYear.yAxisTitle; -const userYear_xAxisTitle = LeastSquaresRegressionStrings.userYear.xAxisTitle; -const userYear_reference = LeastSquaresRegressionStrings.userYear.reference; -const gasolineYear_graphTitle = LeastSquaresRegressionStrings.gasolineYear.graphTitle; -const gasolineYear_yAxisTitle = LeastSquaresRegressionStrings.gasolineYear.yAxisTitle; -const gasolineYear_xAxisTitle = LeastSquaresRegressionStrings.gasolineYear.xAxisTitle; -const gasolineYear_reference = LeastSquaresRegressionStrings.gasolineYear.reference; -const lifeTV_graphTitle = LeastSquaresRegressionStrings.lifeTV.graphTitle; -const lifeTV_yAxisTitle = LeastSquaresRegressionStrings.lifeTV.yAxisTitle; -const lifeTV_xAxisTitle = LeastSquaresRegressionStrings.lifeTV.xAxisTitle; -const lifeTV_reference = LeastSquaresRegressionStrings.lifeTV.reference; -const speedDistance_graphTitle = LeastSquaresRegressionStrings.speedDistance.graphTitle; -const speedDistance_yAxisTitle = LeastSquaresRegressionStrings.speedDistance.yAxisTitle; -const speedDistance_xAxisTitle = LeastSquaresRegressionStrings.speedDistance.xAxisTitle; -const speedDistance_reference = LeastSquaresRegressionStrings.speedDistance.reference; -const temperatureFahrenheitChirp_graphTitle = LeastSquaresRegressionStrings.temperatureFahrenheitChirp.graphTitle; -const temperatureFahrenheitChirp_yAxisTitle = LeastSquaresRegressionStrings.temperatureFahrenheitChirp.yAxisTitle; -const temperatureFahrenheitChirp_xAxisTitle = LeastSquaresRegressionStrings.temperatureFahrenheitChirp.xAxisTitle; -const temperatureFahrenheitChirp_reference = LeastSquaresRegressionStrings.temperatureFahrenheitChirp.reference; -const temperatureCelsiusChirp_graphTitle = LeastSquaresRegressionStrings.temperatureCelsiusChirp.graphTitle; -const temperatureCelsiusChirp_yAxisTitle = LeastSquaresRegressionStrings.temperatureCelsiusChirp.yAxisTitle; -const temperatureCelsiusChirp_xAxisTitle = LeastSquaresRegressionStrings.temperatureCelsiusChirp.xAxisTitle; -const temperatureCelsiusChirp_reference = LeastSquaresRegressionStrings.temperatureCelsiusChirp.reference; -const heightShoe_graphTitle = LeastSquaresRegressionStrings.heightShoe.graphTitle; -const heightShoe_yAxisTitle = LeastSquaresRegressionStrings.heightShoe.yAxisTitle; -const heightShoe_xAxisTitle = LeastSquaresRegressionStrings.heightShoe.xAxisTitle; -const heightShoe_reference = LeastSquaresRegressionStrings.heightShoe.reference; - const custom = { - graphTitle: custom_graphTitleString, - yAxisTitle: '', - xAxisTitle: '', - reference: '', + graphTitle: LeastSquaresRegressionStrings.custom.graphTitleStringProperty, + yAxisTitle: new StringProperty( '' ), + xAxisTitle: new StringProperty( '' ), + reference: new StringProperty( '' ), source: '' }; const temperatureCelsiusLatitude = { - graphTitle: temperatureCelsiusLatitude_graphTitleString, - yAxisTitle: temperatureCelsiusLatitude_yAxisTitleString, - xAxisTitle: temperatureCelsiusLatitude_xAxisTitleString, - reference: temperatureCelsiusLatitude_referenceString, + graphTitle: LeastSquaresRegressionStrings.temperatureCelsiusLatitude.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.temperatureCelsiusLatitude.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.temperatureCelsiusLatitude.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.temperatureCelsiusLatitude.referenceStringProperty, source: SOURCES.TEMPERATURE_CELSIUS_LATITUDE_SOURCE }; const temperatureCelsiusLongitude = { - graphTitle: temperatureCelsiusLongitude_graphTitle, - yAxisTitle: temperatureCelsiusLongitude_yAxisTitle, - xAxisTitle: temperatureCelsiusLongitude_xAxisTitle, - reference: temperatureCelsiusLongitude_reference, + graphTitle: LeastSquaresRegressionStrings.temperatureCelsiusLongitude.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.temperatureCelsiusLongitude.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.temperatureCelsiusLongitude.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.temperatureCelsiusLongitude.referenceStringProperty, source: SOURCES.TEMPERATURE_CELSIUS_LONGITUDE_SOURCE }; const temperatureFahrenheitLatitude = { - graphTitle: temperatureFahrenheitLatitude_graphTitle, - yAxisTitle: temperatureFahrenheitLatitude_yAxisTitle, - xAxisTitle: temperatureFahrenheitLatitude_xAxisTitle, - reference: temperatureFahrenheitLatitude_reference, + graphTitle: LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.temperatureFahrenheitLatitude.referenceStringProperty, source: SOURCES.TEMPERATURE_FAHRENHEIT_LATITUDE_SOURCE }; const temperatureFahrenheitLongitude = { - graphTitle: temperatureFahrenheitLongitude_graphTitle, - yAxisTitle: temperatureFahrenheitLongitude_yAxisTitle, - xAxisTitle: temperatureFahrenheitLongitude_xAxisTitle, - reference: temperatureFahrenheitLongitude_reference, + graphTitle: LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.temperatureFahrenheitLongitude.referenceStringProperty, source: SOURCES.TEMPERATURE_FAHRENHEIT_LONGITUDE_SOURCE }; const spendingSalary = { - graphTitle: spendingSalary_graphTitle, - yAxisTitle: spendingSalary_yAxisTitle, - xAxisTitle: spendingSalary_xAxisTitle, - reference: spendingSalary_reference, + graphTitle: LeastSquaresRegressionStrings.spendingSalary.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.spendingSalary.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.spendingSalary.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.spendingSalary.referenceStringProperty, source: SOURCES.SPENDING_SALARY_SOURCE }; const wageYear = { - graphTitle: wageYear_graphTitle, - yAxisTitle: wageYear_yAxisTitle, - xAxisTitle: wageYear_xAxisTitle, - reference: wageYear_reference, + graphTitle: LeastSquaresRegressionStrings.wageYear.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.wageYear.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.wageYear.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.wageYear.referenceStringProperty, source: SOURCES.WAGE_YEAR_SOURCE }; const mortalityYear = { - graphTitle: mortalityYear_graphTitle, - yAxisTitle: mortalityYear_yAxisTitle, - xAxisTitle: mortalityYear_xAxisTitle, - reference: mortalityYear_reference, + graphTitle: LeastSquaresRegressionStrings.mortalityYear.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.mortalityYear.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.mortalityYear.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.mortalityYear.referenceStringProperty, source: SOURCES.MORTALITY_YEAR_SOURCE }; const userYear = { - graphTitle: userYear_graphTitle, - yAxisTitle: userYear_yAxisTitle, - xAxisTitle: userYear_xAxisTitle, - reference: userYear_reference, + graphTitle: LeastSquaresRegressionStrings.userYear.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.userYear.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.userYear.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.userYear.referenceStringProperty, source: SOURCES.USER_YEAR_SOURCE }; const gasolineYear = { - graphTitle: gasolineYear_graphTitle, - yAxisTitle: gasolineYear_yAxisTitle, - xAxisTitle: gasolineYear_xAxisTitle, - reference: gasolineYear_reference, + graphTitle: LeastSquaresRegressionStrings.gasolineYear.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.gasolineYear.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.gasolineYear.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.gasolineYear.referenceStringProperty, source: SOURCES.GASOLINE_YEAR_SOURCE }; const lifeTV = { - graphTitle: lifeTV_graphTitle, - yAxisTitle: lifeTV_yAxisTitle, - xAxisTitle: lifeTV_xAxisTitle, - reference: lifeTV_reference, + graphTitle: LeastSquaresRegressionStrings.lifeTV.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.lifeTV.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.lifeTV.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.lifeTV.referenceStringProperty, source: SOURCES.LIFE_TV_SOURCE }; const speedDistance = { - graphTitle: speedDistance_graphTitle, - yAxisTitle: speedDistance_yAxisTitle, - xAxisTitle: speedDistance_xAxisTitle, - reference: speedDistance_reference, + graphTitle: LeastSquaresRegressionStrings.speedDistance.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.speedDistance.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.speedDistance.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.speedDistance.referenceStringProperty, source: SOURCES.SPEED_DISTANCE_SOURCE }; const temperatureFahrenheitChirp = { - graphTitle: temperatureFahrenheitChirp_graphTitle, - yAxisTitle: temperatureFahrenheitChirp_yAxisTitle, - xAxisTitle: temperatureFahrenheitChirp_xAxisTitle, - reference: temperatureFahrenheitChirp_reference, + graphTitle: LeastSquaresRegressionStrings.temperatureFahrenheitChirp.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.temperatureFahrenheitChirp.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.temperatureFahrenheitChirp.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.temperatureFahrenheitChirp.referenceStringProperty, source: SOURCES.TEMPERATURE_FAHRENHEIT_CHIRP_SOURCE }; const temperatureCelsiusChirp = { - graphTitle: temperatureCelsiusChirp_graphTitle, - yAxisTitle: temperatureCelsiusChirp_yAxisTitle, - xAxisTitle: temperatureCelsiusChirp_xAxisTitle, - reference: temperatureCelsiusChirp_reference, + graphTitle: LeastSquaresRegressionStrings.temperatureCelsiusChirp.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.temperatureCelsiusChirp.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.temperatureCelsiusChirp.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.temperatureCelsiusChirp.referenceStringProperty, source: SOURCES.TEMPERATURE_CELSIUS_CHIRP_SOURCE }; const heightShoe = { - graphTitle: heightShoe_graphTitle, - yAxisTitle: heightShoe_yAxisTitle, - xAxisTitle: heightShoe_xAxisTitle, - reference: heightShoe_reference, + graphTitle: LeastSquaresRegressionStrings.heightShoe.graphTitleStringProperty, + yAxisTitle: LeastSquaresRegressionStrings.heightShoe.yAxisTitleStringProperty, + xAxisTitle: LeastSquaresRegressionStrings.heightShoe.xAxisTitleStringProperty, + reference: LeastSquaresRegressionStrings.heightShoe.referenceStringProperty, source: SOURCES.HEIGHT_SHOE_SOURCE }; export default class DataSet { public constructor( - config: { graphTitle: string; yAxisTitle: string; xAxisTitle: string; reference: string; source: string }, + config: { graphTitle: TReadOnlyProperty; yAxisTitle: TReadOnlyProperty; xAxisTitle: TReadOnlyProperty; reference: TReadOnlyProperty; source: string }, public readonly yRange: Range, public readonly xRange: Range, public readonly dataXY: Array<{ x: number; y: number }>, public readonly name = config.graphTitle, - public readonly yAxisTitle: string = config.yAxisTitle, - public readonly xAxisTitle: string = config.xAxisTitle, - public readonly reference: string = config.reference, + public readonly yAxisTitle: TReadOnlyProperty = config.yAxisTitle, + public readonly xAxisTitle: TReadOnlyProperty = config.xAxisTitle, + public readonly reference: TReadOnlyProperty = config.reference, public readonly source: string = config.source ) {} diff --git a/js/least-squares-regression/view/BestFitLineAccordionBox.ts b/js/least-squares-regression/view/BestFitLineAccordionBox.ts index 889113f..88b6f2c 100644 --- a/js/least-squares-regression/view/BestFitLineAccordionBox.ts +++ b/js/least-squares-regression/view/BestFitLineAccordionBox.ts @@ -25,11 +25,6 @@ import SumOfSquaredResidualsChart from './SumOfSquaredResidualsChart.js'; */ const MAX_LABEL_WIDTH = 120; -// String constants from localization -const bestFitLineString = LeastSquaresRegressionStrings.bestFitLine; -const residualsString = LeastSquaresRegressionStrings.residuals; -const squaredResidualsString = LeastSquaresRegressionStrings.squaredResiduals; - export default class BestFitLineAccordionBox extends AccordionBox { private readonly equationText: EquationNode; @@ -55,7 +50,7 @@ export default class BestFitLineAccordionBox extends AccordionBox { touchAreaXDilation: 16, touchAreaYDilation: 16 }, - titleNode: new Text( bestFitLineString, { + titleNode: new Text( LeastSquaresRegressionStrings.bestFitLineStringProperty, { font: LeastSquaresRegressionConstants.TEXT_BOLD_FONT, maxWidth: MAX_LABEL_WIDTH } ), @@ -95,11 +90,11 @@ export default class BestFitLineAccordionBox extends AccordionBox { // Create the checkboxes const lineCheckbox = new Checkbox( graph.bestFitLineVisibleProperty, - new Text( bestFitLineString, textOptions ) + new Text( LeastSquaresRegressionStrings.bestFitLineStringProperty, textOptions ) ); - const residualsCheckbox = new Checkbox( graph.bestFitLineShowResidualsProperty, new Text( residualsString, textOptions ) ); - const squaredResidualsCheckbox = new Checkbox( graph.bestFitLineShowSquaredResidualsProperty, new Text( squaredResidualsString, textOptions ) ); + const residualsCheckbox = new Checkbox( graph.bestFitLineShowResidualsProperty, new Text( LeastSquaresRegressionStrings.residualsStringProperty, textOptions ) ); + const squaredResidualsCheckbox = new Checkbox( graph.bestFitLineShowSquaredResidualsProperty, new Text( LeastSquaresRegressionStrings.squaredResidualsStringProperty, textOptions ) ); // Expand the touch Area lineCheckbox.touchArea = lineCheckbox.localBounds.dilatedXY( 8, 8 ); diff --git a/js/least-squares-regression/view/CorrelationCoefficientAccordionBox.ts b/js/least-squares-regression/view/CorrelationCoefficientAccordionBox.ts index 183136b..30a8d4a 100644 --- a/js/least-squares-regression/view/CorrelationCoefficientAccordionBox.ts +++ b/js/least-squares-regression/view/CorrelationCoefficientAccordionBox.ts @@ -20,10 +20,10 @@ import LeastSquaresRegressionConstants from '../LeastSquaresRegressionConstants. import Graph from '../model/Graph.js'; // string -const pattern_0r_1value = '{0} {1}'; +const pattern_0r_1value = '{0} {1}'; // TODO: https://github.com/phetsims/least-squares-regression/issues/90 move this to the i18n file // constants -const R_EQUALS = StringUtils.format( '{0} =', LeastSquaresRegressionStrings.symbol.r ); +const R_EQUALS = StringUtils.format( '{0} =', LeastSquaresRegressionStrings.symbol.rStringProperty.value ); // TODO: https://github.com/phetsims/least-squares-regression/issues/90 move this to the i18n file const MAX_LABEL_WIDTH = 120; // restrict width of labels for i18n export default class CorrelationCoefficientAccordionBox extends AccordionBox { @@ -41,7 +41,7 @@ export default class CorrelationCoefficientAccordionBox extends AccordionBox { touchAreaYDilation: 16 }, titleYMargin: 10, - titleNode: new RichText( LeastSquaresRegressionStrings.correlationCoefficient, { + titleNode: new RichText( LeastSquaresRegressionStrings.correlationCoefficientStringProperty, { replaceNewlines: true, align: 'center', font: LeastSquaresRegressionConstants.TEXT_BOLD_FONT, diff --git a/js/least-squares-regression/view/EquationNode.ts b/js/least-squares-regression/view/EquationNode.ts index a7ed337..2eba889 100644 --- a/js/least-squares-regression/view/EquationNode.ts +++ b/js/least-squares-regression/view/EquationNode.ts @@ -14,9 +14,6 @@ import leastSquaresRegression from '../../leastSquaresRegression.js'; import LeastSquaresRegressionStrings from '../../LeastSquaresRegressionStrings.js'; import LeastSquaresRegressionConstants from '../LeastSquaresRegressionConstants.js'; -const symbolXString = LeastSquaresRegressionStrings.symbol.x; -const symbolYString = LeastSquaresRegressionStrings.symbol.y; - type SelfOptions = { maxDecimalPlaces?: number; // Maximum number of decimal places for slope and intercept mode?: 'myLine' | 'bestFitLine'; // Mode of the equation node @@ -101,11 +98,11 @@ export default class EquationNode extends Node { maxWidthInterceptString = `${maxWidthInterceptString}0`; } - this.yText = new Text( symbolYString, stringTextOptions ); // 'y' + this.yText = new Text( LeastSquaresRegressionStrings.symbol.yStringProperty, stringTextOptions ); // 'y' this.equalText = new Text( MathSymbols.EQUAL_TO, stringTextOptions ); // the '=' sign this.signSlopeText = new Text( MathSymbols.PLUS, numericalTextOptions ); // + or - this.valueSlopeText = new Text( maxWidthSlopeString, numericalTextOptions ); // a number - this.xText = new Text( symbolXString, stringTextOptions ); // 'x' + this.xText = new Text( LeastSquaresRegressionStrings.symbol.xStringProperty, stringTextOptions ); // 'x' this.signInterceptText = new Text( MathSymbols.PLUS, stringTextOptions );// + or - this.valueInterceptText = new Text( maxWidthInterceptString, numericalTextOptions );// a number diff --git a/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts b/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts index e038800..c7c38ce 100644 --- a/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts +++ b/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts @@ -36,8 +36,6 @@ import MyLineControlPanel from './MyLineControlPanel.js'; import SourceAndReferenceNode from './SourceAndReferenceNode.js'; import StaticDataPointNode from './StaticDataPointNode.js'; -const questionMarkString = LeastSquaresRegressionStrings.questionMark; - // constants const GRAPH_BOUNDS = new Dimension2( 480, 480 ); // Size of the graph Node const GRAPH_OFFSET = new Vector2( 10, 0 ); // Offset Vector from the center of the screen @@ -113,7 +111,7 @@ export default class LeastSquaresRegressionScreenView extends ScreenView { // Create a Push Button (next to the ComboBox) that can activate a dialog Node (Source and Reference Node) associated with each dataSet. const sourceAndReferenceNode = new SourceAndReferenceNode( model.selectedDataSetProperty ); - const sourceAndReferencePushButton = new TextPushButton( questionMarkString, { + const sourceAndReferencePushButton = new TextPushButton( LeastSquaresRegressionStrings.questionMarkStringProperty, { baseColor: 'gray', font: LeastSquaresRegressionConstants.TEXT_BOLD_FONT, listener: () => { diff --git a/js/least-squares-regression/view/MyLineControlPanel.ts b/js/least-squares-regression/view/MyLineControlPanel.ts index 291ab79..d68d0d2 100644 --- a/js/least-squares-regression/view/MyLineControlPanel.ts +++ b/js/least-squares-regression/view/MyLineControlPanel.ts @@ -22,14 +22,6 @@ import Graph from '../model/Graph.js'; import EquationNode from './EquationNode.js'; import SumOfSquaredResidualsChart from './SumOfSquaredResidualsChart.js'; -const aString = LeastSquaresRegressionStrings.a; -const bString = LeastSquaresRegressionStrings.b; -const myLineString = LeastSquaresRegressionStrings.myLine; -const residualsString = LeastSquaresRegressionStrings.residuals; -const squaredResidualsString = LeastSquaresRegressionStrings.squaredResiduals; -const symbolXString = LeastSquaresRegressionStrings.symbol.x; -const symbolYString = LeastSquaresRegressionStrings.symbol.y; - // constants const SLIDER_OPTIONS = { trackFill: 'black', @@ -80,12 +72,12 @@ export default class MyLineControlPanel extends Panel { maxWidth: equationCharacterMaxWidth }; - const yText = new Text( symbolYString, blackOptions ); // 'y' + const yText = new Text( LeastSquaresRegressionStrings.symbol.yStringProperty, blackOptions ); // 'y' const equalText = new Text( '=', blackOptions ); // the '=' sign - const aText = new Text( aString, boldOptions ); // a number - const xText = new Text( symbolXString, blackOptions ); // 'x' + const aText = new Text( LeastSquaresRegressionStrings.aStringProperty, boldOptions ); // a number + const xText = new Text( LeastSquaresRegressionStrings.symbol.xStringProperty, blackOptions ); // 'x' const signInterceptText = new Text( MathSymbols.PLUS, blackOptions );// '+' - const bText = new Text( bString, boldOptions );// a number + const bText = new Text( LeastSquaresRegressionStrings.bStringProperty, boldOptions );// a number const immutableEquationText = new Node( { children: [ @@ -124,8 +116,8 @@ export default class MyLineControlPanel extends Panel { bSlider.addMajorTick( 0 ); // Create label below the sliders - const aSliderText = new Text( aString, merge( { maxWidth: MAX_WIDTH }, boldOptions ) ); - const bSliderText = new Text( bString, merge( { maxWidth: MAX_WIDTH }, boldOptions ) ); + const aSliderText = new Text( LeastSquaresRegressionStrings.aStringProperty, merge( { maxWidth: MAX_WIDTH }, boldOptions ) ); + const bSliderText = new Text( LeastSquaresRegressionStrings.bStringProperty, merge( { maxWidth: MAX_WIDTH }, boldOptions ) ); // collect the immutable equation, the mutable equation and the sliders in one node const rightAlignedNode = new Node(); @@ -140,9 +132,9 @@ export default class MyLineControlPanel extends Panel { // Create three checkboxes const checkboxTextOptions = { font: LeastSquaresRegressionConstants.CHECKBOX_TEXT_FONT, maxWidth: MAX_WIDTH }; - const lineCheckbox = new Checkbox( graph.myLineVisibleProperty, new Text( myLineString, checkboxTextOptions ) ); - const residualsCheckbox = new Checkbox( graph.myLineShowResidualsProperty, new Text( residualsString, checkboxTextOptions ) ); - const squaredResidualsCheckbox = new Checkbox( graph.myLineShowSquaredResidualsProperty, new Text( squaredResidualsString, checkboxTextOptions ) ); + const lineCheckbox = new Checkbox( graph.myLineVisibleProperty, new Text( LeastSquaresRegressionStrings.myLineStringProperty, checkboxTextOptions ) ); + const residualsCheckbox = new Checkbox( graph.myLineShowResidualsProperty, new Text( LeastSquaresRegressionStrings.residualsStringProperty, checkboxTextOptions ) ); + const squaredResidualsCheckbox = new Checkbox( graph.myLineShowSquaredResidualsProperty, new Text( LeastSquaresRegressionStrings.squaredResidualsStringProperty, checkboxTextOptions ) ); // Expand the touch Area lineCheckbox.touchArea = lineCheckbox.localBounds.dilatedXY( 8, 8 ); diff --git a/js/least-squares-regression/view/SourceAndReferenceNode.ts b/js/least-squares-regression/view/SourceAndReferenceNode.ts index f0cb535..72cbf63 100644 --- a/js/least-squares-regression/view/SourceAndReferenceNode.ts +++ b/js/least-squares-regression/view/SourceAndReferenceNode.ts @@ -6,6 +6,7 @@ * @author Martin Veillette (Berea College) */ +import Multilink from '../../../../axon/js/Multilink.js'; import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import Bounds2 from '../../../../dot/js/Bounds2.js'; import ScreenView from '../../../../joist/js/ScreenView.js'; @@ -17,8 +18,6 @@ import LeastSquaresRegressionStrings from '../../LeastSquaresRegressionStrings.j import LeastSquaresRegressionConstants from '../LeastSquaresRegressionConstants.js'; import DataSet from '../model/DataSet.js'; -const sourcePatternString = LeastSquaresRegressionStrings.sourcePattern; - export default class SourceAndReferenceNode extends ScreenView { public constructor( selectedDataSetProperty: TReadOnlyProperty ) { @@ -98,8 +97,8 @@ export default class SourceAndReferenceNode extends ScreenView { // Update the content of this node and the layout. // no need to unlink, present for the lifetime of the sim - selectedDataSetProperty.link( selectedDataSet => { - referenceText.string = selectedDataSet.reference; + Multilink.multilink( [ LeastSquaresRegressionStrings.sourcePatternStringProperty, selectedDataSetProperty ], ( sourcePatternString, selectedDataSet ) => { + referenceText.setStringProperty( selectedDataSet.reference ); const formattedSourceString = StringUtils.format( sourcePatternString, selectedDataSet.source ); sourceText.string = formattedSourceString; panel.centerX = this.layoutBounds.centerX; diff --git a/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts b/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts index 1f73a80..32da034 100644 --- a/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts +++ b/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts @@ -16,8 +16,6 @@ import LeastSquaresRegressionStrings from '../../LeastSquaresRegressionStrings.j import LeastSquaresRegressionConstants from '../LeastSquaresRegressionConstants.js'; import Graph from '../model/Graph.js'; -const sumString = LeastSquaresRegressionStrings.sum; - // constants const ARROW_LENGTH = 175; const ARROW_HEAD_WIDTH = 4; @@ -53,7 +51,7 @@ export default class SumOfSquaredResidualsChart extends Node { } ); // Text for the chart - const label = new Text( sumString, { + const label = new Text( LeastSquaresRegressionStrings.sumStringProperty, { font: FONT, centerX: horizontalArrow.centerX, top: horizontalArrow.bottom + 5, diff --git a/least-squares-regression_en.html b/least-squares-regression_en.html index a87a892..d479acd 100644 --- a/least-squares-regression_en.html +++ b/least-squares-regression_en.html @@ -44,7 +44,10 @@ ], "simulation": true, "supportsOutputJS": true, - "published": true + "published": true, + "simFeatures": { + "supportsDynamicLocale": true + } } }; window.phet.chipper.stringRepos = diff --git a/package.json b/package.json index 22b9b82..8ff55a7 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,9 @@ ], "simulation": true, "supportsOutputJS": true, - "published": true + "published": true, + "simFeatures": { + "supportsDynamicLocale": true + } } } \ No newline at end of file