Skip to content

Commit

Permalink
new pdom content, new screen summary node options, string manager val…
Browse files Browse the repository at this point in the history
…ue functions implemented, link distance display in screen summary to model property, see phetsims/gravity-force-lab#109
  • Loading branch information
mbarlow12 committed Nov 2, 2018
1 parent 5d8491d commit 9bb6277
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ define( function( require ) {
var gravityForceLabBasics = require( 'GRAVITY_FORCE_LAB_BASICS/gravityForceLabBasics' );

var GravityForceLabBasicsA11yStrings = {
screenSummaryDescription: {
value: 'The Play Area has two spheres, a blue sphere labelled Mass 1 and a red sphere labelled Mass 2, and each sphere is held in place by a robot. Arrows representing force starts at center of each sphere and point directly at opposite sphere. Spheres can be moved closer or further from each other, and mass of each sphere can be increased or decreased. In Control Area there are checkboxes and buttons to show force values, show distance between spheres, set spheres to a constant size, and to reset sim.'
},
basicsSimStateLabel: {
value: 'Currently, force on mass 1 by mass 2 is of equal magnitude and pointing directly opposite to the force on mass 2 by mass 1.'
},
massReadoutPattern: {
value: '{{value}} billion kg'
},
massesDistanceApartPattern: {
value: 'masses are {{distance}} km apart;'
value: 'masses are {{distance}} km apart'
}
};

Expand Down
21 changes: 19 additions & 2 deletions js/gravity-force-lab-basics/view/GFLBStringManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@ define( require => {
const forceToPullIndex = new LinearFunction( PULL_FORCE_RANGE.min, PULL_FORCE_RANGE.max, 6, 0, true );

const massesDistanceApartPatternString = GravityForceLabBasicsA11yStrings.massesDistanceApartPattern.value;

const unitsNewtonsString = require( 'string!INVERSE_SQUARE_LAW_COMMON/units.newtons' );

class GFLBStringManager extends GravityForceLabStringManager {

constructor( model, object1Label, object2Label ) {
super( model, object1Label, object2Label, {} );
super( model, object1Label, object2Label, {
distanceUnits: 'kilometers',
centerOffset: 4800,
valueUnits: unitsNewtonsString,
convertForceValue: value => Util.toFixedNumber( value, 1 ),
convertDistanceApart: distance => Util.toFixedNumber( distance / 1e3, 1 ),
formatMassValue: mass => `${mass/1e9} billion`, // TODO: convert to proper string usage
formatPositionUnitMark: position => {
position = Util.toFixedNumber( position / 1e3, 1 );
return StringUtils.fillIn( '{{position}} kilometer', { position } );
}
} );
}

static getMassesDistanceApart( distance ) {
return StringUtils.fillIn( massesDistanceApartPatternString, { distance } );
}

// TODO: proper string usage
getOnlyQualitativeObjectDistanceSummary() {
const pattern = '{{mass1}} and {{mass2}} are {{qualitativeDistance}} each other.';
return StringUtils.fillIn( pattern, { mass1: this.object1Label, mass2: this.object2Label, qualitativeDistance: this.getQualitativeDistance() } );
}

// @override
getDistanceIndex( distance ) {
distance /= 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ define( function( require ) {
tandem: Tandem.required,

// a11y
// TODO: proper string usage
createAriaValueText: function( formattedValue, previousValue ) {
formattedValue += 4800;
return GFLBStringManager.getPositionMeterMarkText( formattedValue );
return GFLBStringManager.getPositionMeterMarkText( `${formattedValue / 1e3} kilometer` );
}
}, options );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define( function( require ) {
var GFLBStringManager = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/view/GFLBStringManager' );
var GravityForceLabA11yStrings = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/GravityForceLabA11yStrings' );
var gravityForceLabBasics = require( 'GRAVITY_FORCE_LAB_BASICS/gravityForceLabBasics' );
var GravityForceLabBasicsA11yStrings = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/GravityForceLabBasicsA11yStrings' );
var GravityForceLabBasicsConstants = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/GravityForceLabBasicsConstants' );
var GravityForceLabBasicsMassNode = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/view/GravityForceLabBasicsMassNode' );
var GravityForceLabScreenSummaryNode = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/GravityForceLabScreenSummaryNode' );
Expand Down Expand Up @@ -62,6 +63,8 @@ define( function( require ) {
var spherePositionsString = ISLCA11yStrings.spherePositions.value;
var spherePositionHelpTextString = ISLCA11yStrings.spherePositionHelpText.value;
var massControlsLabelString = GravityForceLabA11yStrings.massControlsLabel.value;
var screenSummaryDescriptionString = GravityForceLabBasicsA11yStrings.screenSummaryDescription.value;
var basicsSimStateLabelString = GravityForceLabBasicsA11yStrings.basicsSimStateLabel.value;

/**
* @param {GravityForceLabBasicsModel} model
Expand All @@ -75,7 +78,12 @@ define( function( require ) {
} );

var stringManager = new GFLBStringManager( model, mass1LabelString, mass2LabelString );
var summaryNode = new GravityForceLabScreenSummaryNode( model, stringManager );
var summaryNode = new GravityForceLabScreenSummaryNode( model, stringManager, {
descriptionContent: screenSummaryDescriptionString,
summaryOptions: {
simStateLabel: basicsSimStateLabelString
}
} );
var playAreaNode = new PlayAreaNode();
var controlAreaNode = new ControlAreaNode();
this.screenSummaryNode.addChild( summaryNode );
Expand Down Expand Up @@ -200,6 +208,14 @@ define( function( require ) {
} );
controlAreaNode.addChild( resetAllButton );

// link summary content to distance property
model.showDistanceProperty.link( function( showDistance ) {
var content = showDistance ?
stringManager.getObjectDistanceSummary() :
stringManager.getOnlyQualitativeObjectDistanceSummary();
summaryNode.objectDistanceSummaryItem.innerContent = content;
} );

// layout the view elements
parameterControlPanel.right = this.layoutBounds.width - 15;
parameterControlPanel.bottom = MASS_CONTROLS_Y_POSITION;
Expand Down

0 comments on commit 9bb6277

Please sign in to comment.