From cdf85be0bd6db31b14e266b25ecc8317fa25500f Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Tue, 6 Nov 2018 11:55:03 -0700 Subject: [PATCH] #43 factor out phetioDocumentation pattern for all NumberProperties that correspond to equation values Signed-off-by: Chris Malley --- js/common/GQConstants.js | 6 +++- .../model/FocusAndDirectrixModel.js | 26 +++++++++------- js/standardform/model/StandardFormModel.js | 27 +++++++++------- js/vertexform/model/VertexFormModel.js | 31 ++++++++++--------- 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/js/common/GQConstants.js b/js/common/GQConstants.js index 413ad837..ccb12007 100644 --- a/js/common/GQConstants.js +++ b/js/common/GQConstants.js @@ -135,7 +135,11 @@ define( require => { EQUATION_OPERATOR_SPACING: 8, // spacing within terms in interactive equations - EQUATION_TERM_SPACING: 6 + EQUATION_TERM_SPACING: 6, + + // PhET-iO documentation for NumberProperty instances that correspond to equation values. + // See https://github.com/phetsims/graphing-quadratics/issues/103 + PHETIO_DOCUMENTATION_PATTERN: 'the value of \'{{symbol}}\' in the interactive equation' }; return graphingQuadratics.register( 'GQConstants', GQConstants ); diff --git a/js/focusanddirectrix/model/FocusAndDirectrixModel.js b/js/focusanddirectrix/model/FocusAndDirectrixModel.js index b03f72c3..2e470be3 100644 --- a/js/focusanddirectrix/model/FocusAndDirectrixModel.js +++ b/js/focusanddirectrix/model/FocusAndDirectrixModel.js @@ -2,7 +2,7 @@ /** * Model for the 'Focus & Directrix' screen. - * Alternate vertex form of the quadratic equation is: y = (1/(4p)(x - h)^1 - k + * Alternate vertex form of the quadratic equation is: y = (1/(4p)(x - h)^2 - k * * @author Chris Malley (PixelZoom, Inc.) */ @@ -13,6 +13,7 @@ define( require => { const DerivedProperty = require( 'AXON/DerivedProperty' ); const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); const GQColors = require( 'GRAPHING_QUADRATICS/common/GQColors' ); + const GQConstants = require( 'GRAPHING_QUADRATICS/common/GQConstants' ); const GQModel = require( 'GRAPHING_QUADRATICS/common/model/GQModel' ); const graphingQuadratics = require( 'GRAPHING_QUADRATICS/graphingQuadratics' ); const NumberProperty = require( 'AXON/NumberProperty' ); @@ -21,6 +22,7 @@ define( require => { const Quadratic = require( 'GRAPHING_QUADRATICS/common/model/Quadratic' ); const QuadraticIO = require( 'GRAPHING_QUADRATICS/common/model/QuadraticIO' ); const RangeWithValue = require( 'DOT/RangeWithValue' ); + const StringUtils = require( 'PHETCOMMON/util/StringUtils' ); const Vector2 = require( 'DOT/Vector2' ); const Vector2IO = require( 'DOT/Vector2IO' ); @@ -37,34 +39,36 @@ define( require => { */ constructor( tandem ) { - // Options used in all of the coefficient Properties - const coefficientPropertyOptions = { + // Options for NumberProperty instances + const numberPropertyOptions = { - // This NumberProperty can be controlled directly in the simulation, hence we do not require a redundant + // Can be controlled directly in the simulation, hence we do not require a redundant // slider in Studio, see https://github.com/phetsims/graphing-quadratics/issues/52 phetioStudioControl: false }; - // coefficients for alternate vertex form + // p const pProperty = new NumberProperty( P_RANGE.defaultValue, _.extend( { range: P_RANGE, tandem: tandem.createTandem( 'pProperty' ), - phetioDocumentation: 'coefficient a for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'p' } ) + }, numberPropertyOptions ) ); phet.log && pProperty.link( p => { phet.log( 'p=' + p ); } ); + // h const hProperty = new NumberProperty( H_RANGE.defaultValue, _.extend( { range: H_RANGE, tandem: tandem.createTandem( 'hProperty' ), - phetioDocumentation: 'coefficient h for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'h' } ) + }, numberPropertyOptions ) ); phet.log && hProperty.link( h => { phet.log( 'h=' + h ); } ); + // k const kProperty = new NumberProperty( K_RANGE.defaultValue, _.extend( { range: K_RANGE, tandem: tandem.createTandem( 'kProperty' ), - phetioDocumentation: 'coefficient k for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'k' } ) + }, numberPropertyOptions ) ); phet.log && kProperty.link( k => { phet.log( 'k=' + k ); } ); // {DerivedProperty.} diff --git a/js/standardform/model/StandardFormModel.js b/js/standardform/model/StandardFormModel.js index 68363fd2..96fd2e2b 100644 --- a/js/standardform/model/StandardFormModel.js +++ b/js/standardform/model/StandardFormModel.js @@ -13,12 +13,14 @@ define( require => { const DerivedProperty = require( 'AXON/DerivedProperty' ); const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); const GQColors = require( 'GRAPHING_QUADRATICS/common/GQColors' ); + const GQConstants = require( 'GRAPHING_QUADRATICS/common/GQConstants' ); const GQModel = require( 'GRAPHING_QUADRATICS/common/model/GQModel' ); const graphingQuadratics = require( 'GRAPHING_QUADRATICS/graphingQuadratics' ); const NumberProperty = require( 'AXON/NumberProperty' ); const Quadratic = require( 'GRAPHING_QUADRATICS/common/model/Quadratic' ); const QuadraticIO = require( 'GRAPHING_QUADRATICS/common/model/QuadraticIO' ); const RangeWithValue = require( 'DOT/RangeWithValue' ); + const StringUtils = require( 'PHETCOMMON/util/StringUtils' ); // constants const A_RANGE = new RangeWithValue( -6, 6, 1 ); // a coefficient @@ -35,40 +37,41 @@ define( require => { options = _.extend( { - // NumberProperty options, for coefficients + // NumberProperty options numberType: 'Integer' }, options ); - // Options used in all of the coefficient Properties - const coefficientPropertyOptions = { + // Options for NumberProperty instances + const numberPropertyOptions = { numberType: options.numberType, - // This NumberProperty can be controlled directly in the simulation, hence we do not require a redundant + // Can be controlled directly in the simulation, hence we do not require a redundant // slider in Studio, see https://github.com/phetsims/graphing-quadratics/issues/52 phetioStudioControl: false }; - //REVIEW: Since aProperty is duplicated in VertexFormModel.js, should there be comments that note that the - //documentation should stay in sync? + // a const aProperty = new NumberProperty( A_RANGE.defaultValue, _.extend( { range: A_RANGE, tandem: tandem.createTandem( 'aProperty' ), - phetioDocumentation: 'coefficient a for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'a' } ) + }, numberPropertyOptions ) ); phet.log && aProperty.link( a => { phet.log( 'a=' + a ); } ); + // b const bProperty = new NumberProperty( B_RANGE.defaultValue, _.extend( { range: B_RANGE, tandem: tandem.createTandem( 'bProperty' ), - phetioDocumentation: 'coefficient b for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'p' } ) + }, numberPropertyOptions ) ); phet.log && bProperty.link( b => { phet.log( 'b=' + b ); } ); + // c const cProperty = new NumberProperty( C_RANGE.defaultValue, _.extend( { range: C_RANGE, tandem: tandem.createTandem( 'cProperty' ), - phetioDocumentation: 'coefficient c for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'p' } ) + }, numberPropertyOptions ) ); phet.log && cProperty.link( c => { phet.log( 'c=' + c ); } ); // {DerivedProperty.} diff --git a/js/vertexform/model/VertexFormModel.js b/js/vertexform/model/VertexFormModel.js index 71d2545d..fc00baf4 100644 --- a/js/vertexform/model/VertexFormModel.js +++ b/js/vertexform/model/VertexFormModel.js @@ -13,18 +13,19 @@ define( require => { const DerivedProperty = require( 'AXON/DerivedProperty' ); const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); const GQColors = require( 'GRAPHING_QUADRATICS/common/GQColors' ); + const GQConstants = require( 'GRAPHING_QUADRATICS/common/GQConstants' ); const GQModel = require( 'GRAPHING_QUADRATICS/common/model/GQModel' ); const graphingQuadratics = require( 'GRAPHING_QUADRATICS/graphingQuadratics' ); const NumberProperty = require( 'AXON/NumberProperty' ); const Quadratic = require( 'GRAPHING_QUADRATICS/common/model/Quadratic' ); const QuadraticIO = require( 'GRAPHING_QUADRATICS/common/model/QuadraticIO' ); const RangeWithValue = require( 'DOT/RangeWithValue' ); + const StringUtils = require( 'PHETCOMMON/util/StringUtils' ); // constants const A_RANGE = new RangeWithValue( -6, 6, 1 ); // a coefficient const H_RANGE = new RangeWithValue( -9, 9, 0 ); // h coefficient const K_RANGE = new RangeWithValue( -9, 9, 0 ); // k coefficient - const COEFFICIENT_NUMBER_TYPE = 'Integer'; class VertexFormModel extends GQModel { @@ -34,37 +35,39 @@ define( require => { */ constructor( tandem, options ) { - // Options used in all of the coefficient Properties - const coefficientPropertyOptions = { - numberType: COEFFICIENT_NUMBER_TYPE, + // Options for NumberProperty instances + const numberPropertyOptions = { - // This NumberProperty can be controlled directly in the simulation, hence we do not require a redundant + // Values are controlled by integer pickers + numberType: 'Integer', + + // Can be controlled directly in the simulation, hence we do not require a redundant // slider in Studio, see https://github.com/phetsims/graphing-quadratics/issues/52 phetioStudioControl: false }; - // coefficients for vertex form + // a const aProperty = new NumberProperty( A_RANGE.defaultValue, _.extend( { range: A_RANGE, tandem: tandem.createTandem( 'aProperty' ), - phetioDocumentation: 'coefficient a for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'a' } ) + }, numberPropertyOptions ) ); phet.log && aProperty.link( a => { phet.log( 'a=' + a ); } ); - //REVIEW: Since h and k are duplicated in FocusAndDirectrixModel.js, should there be comments that note that - //the documentation should stay in sync? + // h const hProperty = new NumberProperty( H_RANGE.defaultValue, _.extend( { range: H_RANGE, tandem: tandem.createTandem( 'hProperty' ), - phetioDocumentation: 'coefficient h for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'h' } ) + }, numberPropertyOptions ) ); phet.log && hProperty.link( h => { phet.log( 'h=' + h ); } ); + // k const kProperty = new NumberProperty( K_RANGE.defaultValue, _.extend( { range: K_RANGE, tandem: tandem.createTandem( 'kProperty' ), - phetioDocumentation: 'coefficient k for the interactive quadratic' - }, coefficientPropertyOptions ) ); + phetioDocumentation: StringUtils.fillIn( GQConstants.PHETIO_DOCUMENTATION_PATTERN, { symbol: 'k' } ) + }, numberPropertyOptions ) ); phet.log && kProperty.link( k => { phet.log( 'k=' + k ); } ); // {DerivedProperty.}