Skip to content

Commit

Permalink
#43 factor out phetioDocumentation pattern for all NumberProperties t…
Browse files Browse the repository at this point in the history
…hat correspond to equation values

Signed-off-by: Chris Malley <[email protected]>
  • Loading branch information
pixelzoom committed Nov 6, 2018
1 parent e57af93 commit cdf85be
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
6 changes: 5 additions & 1 deletion js/common/GQConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
26 changes: 15 additions & 11 deletions js/focusanddirectrix/model/FocusAndDirectrixModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
*/
Expand All @@ -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' );
Expand All @@ -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' );

Expand All @@ -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.<Quadratic>}
Expand Down
27 changes: 15 additions & 12 deletions js/standardform/model/StandardFormModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.<Quadratic>}
Expand Down
31 changes: 17 additions & 14 deletions js/vertexform/model/VertexFormModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.<Quadratic>}
Expand Down

1 comment on commit cdf85be

@pixelzoom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.