Skip to content

Commit

Permalink
screen summary option added to screen summary node, use new optional …
Browse files Browse the repository at this point in the history
…value formatters, pdom updates see #109
  • Loading branch information
mbarlow12 committed Nov 2, 2018
1 parent 726cd4a commit e8ad2be
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
15 changes: 11 additions & 4 deletions js/gravity-force-lab/view/GravityForceLabScreenSummaryNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ define( require => {

class GravityForceLabScreenSummaryNode extends Node {

constructor( model, stringManager ) {
super( {
constructor( model, stringManager, options ) {

options = _.extend( {
tagName: 'div',
descriptionTagName: 'p',
descriptionContent: screenSummaryDescriptionString
} );
}, options );

const summaryOptions = _.extend( {
simStateLabel: simStateListLabelString
}, options.summaryOptions );

super( _.omit( options, 'summaryOptions' ) );

this.stringManager = stringManager;

this.simStateNode = new Node( {
tagName: 'ul',
labelTagName: 'p',
labelContent: simStateListLabelString
labelContent: summaryOptions.simStateLabel
} );

this.forceVectorsSummaryItem = new Node( { tagName: 'li' } );
Expand Down
38 changes: 30 additions & 8 deletions js/gravity-force-lab/view/GravityForceLabStringManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ define( require => {
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
const GravityForceLabConstants = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabConstants' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
const ISLCStringManager = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCStringManager' );
const LinearFunction = require( 'DOT/LinearFunction' );
const Property = require( 'AXON/Property' );
Expand All @@ -27,7 +28,8 @@ define( require => {
// const mass2AbbreviatedString = require( 'string!GRAVITY_FORCE_LAB/mass2Abbreviated' );

const massValuesAndComparisonSummaryPatternString = GravityForceLabA11yStrings.massValuesAndComparisonSummaryPattern.value;
const sizeAndPositionPatternString = '{{thisObject}} is {{size}} at {{massValue}} kg and at {{positionMark}} meter mark';
// TODO: proper string usage
const sizeAndPositionPatternString = '{{thisObject}} is {{size}} at {{massValue}} kg and at {{positionUnitMark}} mark';

const muchMuchSmallerThanString = GravityForceLabA11yStrings.muchMuchSmallerThan.value;
const muchSmallerThanString = GravityForceLabA11yStrings.muchSmallerThan.value;
Expand All @@ -42,23 +44,34 @@ define( require => {

// constants
const MICRO_CONVERSION_FACTOR = 1e6;
const { OBJECT_ONE } = ISLCObjectEnum;
const exponentToIndex = new LinearFunction( -1, 1, 0, 6 );
const { min, max } = GravityForceLabConstants.PULL_FORCE_RANGE;
const forceToPullIndex = new LinearFunction( min, max, 6, 0, true );

class GravityForceLabStringManager extends ISLCStringManager {
constructor( model, object1Label, object2Label, options ) {

options = options ? options : _.extend( {
options = _.extend( {
valueUnits: micronewtonsString,
valueUnitConversion: MICRO_CONVERSION_FACTOR
centerOffset: 5,
convertForceValue: value => Util.toFixedNumber( value * MICRO_CONVERSION_FACTOR, 7 ),
convertDistanceApart: distance => Util.toFixedNumber( distance, 2 ),
formatPositionUnitMark: position => {
position = Util.toFixedNumber( position, 1 );
return StringUtils.fillIn( '{{position}} meter', { position } );
},
formatMassValue: mass => mass
}, options );

super( model, object1Label, object2Label, options );

// @private
this._object1ToObject2Ratio = 0;
this._object2ToObject1Ratio = 0;
this.formatMassValue = options.formatMassValue;
this.centerOffset = options.centerOffset;
this.formatPositionUnitMark = options.formatPositionUnitMark;

Property.multilink(
[ model.object1.radiusProperty, model.object2.radiusProperty ],
Expand All @@ -78,8 +91,8 @@ define( require => {
const fillObject = {
mass1Label: this.object1Label,
mass2Label: this.object2Label,
m1Mass: this.object1.valueProperty.get(),
m2Mass: this.object2.valueProperty.get(),
m1Mass: this.formatMassValue( this.object1.valueProperty.get() ),
m2Mass: this.formatMassValue( this.object2.valueProperty.get() ),
comparitiveValue: RELATIVE_SIZE_STRINGS[ relativeSizeIndex ]
};
return StringUtils.fillIn( massValuesAndComparisonSummaryPatternString, fillObject );
Expand All @@ -89,11 +102,20 @@ define( require => {
getSizeAndPositionItemText( massLabel ) {
const modelObject = massLabel === this.object1Label ? this.object1 : this.object2;
const thisObject = massLabel;
const massValue = modelObject.valueProperty.get();
let massValue = modelObject.valueProperty.get();
const size = this.getSizeOfMass( massValue );
const positionMark = Util.toFixedNumber( modelObject.positionProperty.get() + 5, 1 );
massValue = this.formatMassValue( massValue );
const positionUnitMark = this.formatPositionUnitMark( modelObject.positionProperty.get() + this.centerOffset );
const pattern = sizeAndPositionPatternString;
return StringUtils.fillIn( pattern, { thisObject, size, massValue, positionMark } );
return StringUtils.fillIn( pattern, { thisObject, size, massValue, positionUnitMark } );
}

// TODO: proper string usage
getMassSphereString( objectEnum ) {
const massLabel = objectEnum === OBJECT_ONE ? this.object1Label : this.object2Label;
const massRedSpherePatternString = `${massLabel}, Red Sphere`;
const massBlueSpherePatternString = `${massLabel}, Blue Sphere`;
return objectEnum === OBJECT_ONE ? massBlueSpherePatternString : massRedSpherePatternString;
}

getSizeOfMass( massValue ) {
Expand Down
2 changes: 1 addition & 1 deletion js/gravity-force-lab/view/MassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ define( function( require ) {
// a11y
createAriaValueText: function( formattedValue, previousValue ) {
formattedValue += 5;
return ISLCStringManager.getPositionMeterMarkText( formattedValue );
return ISLCStringManager.getPositionMeterMarkText( `${formattedValue} meter` );
}
}, options );

Expand Down
10 changes: 5 additions & 5 deletions js/gravity-force-lab/view/MassPDOMNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ define( require => {

// modules
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
// const GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
const ISLCObjectPDOMNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectPDOMNode' );
const Node = require( 'SCENERY/nodes/Node' );

// strings
const mass1BlueSphereString = GravityForceLabA11yStrings.mass1BlueSphere.value;
const mass2RedSphereString = GravityForceLabA11yStrings.mass2RedSphere.value;
// const mass1BlueSphereString = GravityForceLabA11yStrings.mass1BlueSphere.value;
// const mass2RedSphereString = GravityForceLabA11yStrings.mass2RedSphere.value;

class MassPDOMNode extends ISLCObjectPDOMNode {

constructor( model, objectEnum, stringManager, options ) {

const labelContent = objectEnum === ISLCObjectEnum.OBJECT_ONE ? mass1BlueSphereString : mass2RedSphereString;
// const labelContent = objectEnum === ISLCObjectEnum.OBJECT_ONE ? mass1BlueSphereString : mass2RedSphereString;
const labelContent = stringManager.getMassSphereString( objectEnum );
options.a11yOptions = { labelContent };

super( model, objectEnum, stringManager, options );
Expand Down

0 comments on commit e8ad2be

Please sign in to comment.