Skip to content

Commit

Permalink
ES6 update for constants file, screen summary node draft complete, see
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarlow12 committed Oct 22, 2018
1 parent f42f963 commit 8152040
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 34 deletions.
2 changes: 1 addition & 1 deletion js/gravity-force-lab/GravityForceLabA11yStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define( require => {
value: 'Currently, force on m1 by m2 is of equal magnitude and pointing directly opposite to the force on m2 by m1.'
},
massValuesAndComparisonSummaryPattern: {
value: 'Mass of m1 is {{m1Mass}} kilograms, {{comparitiveValue}} than m2 at {{m2Mass}} kilograms.'
value: 'Mass of m1 is {{m1Mass}} kilograms, {{comparitiveValue}} m2 at {{m2Mass}} kilograms.'
},

////////////////////////
Expand Down
37 changes: 19 additions & 18 deletions js/gravity-force-lab/GravityForceLabConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
* Constants that are shared between the various portions of the Gravity Force Lab simulation.
*
* @author John Blanco
* @author Michael Barlow
*/
define( function( require ) {
define( require => {
'use strict';

// modules
var Color = require( 'SCENERY/util/Color' );
var gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
var Range = require( 'DOT/Range' );
const Color = require( 'SCENERY/util/Color' );
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const Range = require( 'DOT/Range' );

// constants
var MIN_MASS = 1; // kg
var MAX_MASS = 1000; // kg
var MAX_DISTANCE_FROM_CENTER = 4.8; // meters, empirically determined boundary for masses
var MASS_BLUE_COLOR = new Color( '#00f' );
var MASS_RED_COLOR = new Color( '#f00' );

var GravityForceLabConstants = {
MASS_RED_COLOR: MASS_RED_COLOR,
MASS_BLUE_COLOR: MASS_BLUE_COLOR,
MIN_MASS: MIN_MASS,
MAX_MASS: MAX_MASS,
const MIN_MASS = 1; // kg
const MAX_MASS = 1000; // kg
const MAX_DISTANCE_FROM_CENTER = 4.8; // meters, empirically determined boundary for masses
const MASS_BLUE_COLOR = new Color( '#00f' );
const MASS_RED_COLOR = new Color( '#f00' );
const PULL_FORCE_RANGE = new Range( ( 0.5e-10 ), ( 1.1e-6 ) ); // empirically determined for linear mapping of pull objects

const GravityForceLabConstants = {
MASS_RED_COLOR,
MASS_BLUE_COLOR,
MIN_MASS,
MAX_MASS,
PULL_FORCE_RANGE,
RIGHT_MASS_BOUNDARY: MAX_DISTANCE_FROM_CENTER,
LEFT_MASS_BOUNDARY: -MAX_DISTANCE_FROM_CENTER,
LOCATION_SNAP_VALUE: 0.1,
Expand All @@ -33,7 +36,5 @@ define( function( require ) {
MASS_DENSITY: 150 // kg/m^3
};

gravityForceLab.register( 'GravityForceLabConstants', GravityForceLabConstants );

return GravityForceLabConstants;
return gravityForceLab.register( 'GravityForceLabConstants', GravityForceLabConstants );
} );
35 changes: 33 additions & 2 deletions js/gravity-force-lab/view/GravityForceLabScreenSummaryNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,44 @@ define( require => {
this.children = [ this.simStateNode, interactionHintNode ];

Property.multilink( [ model.forceProperty, model.forceValuesProperty ], ( force, showValues ) => {
this.updateSimStateList();
this.updateForceVectorSummary();
this.updateRobotEffort();
} );

Property.multilink(
[ model.object1.positionProperty,
model.object1.radiusProperty,
model.object2.positionProperty,
model.object2.radiusProperty
],
( x1, r1, x2, r2 ) => {
this.updateObjectDistanceSummary();
this.updateMassValuesSummary();
}
);
}

updateSimStateList() {
this.updateForceVectorSummary();
this.updateObjectDistanceSummary();
this.updateMassValuesSummary();
this.updateRobotEffort();
}

updateForceVectorSummary() {
this.forceVectorsSummaryItem.innerContent = this.stringManager.getForceVectorsSummaryText();
// this.objectDistanceSummaryItem.innerContent = this.stringManager.getObjectDistanceSummary();
}

updateObjectDistanceSummary() {
this.objectDistanceSummaryItem.innerContent = this.stringManager.getObjectDistanceSummary();
}

updateMassValuesSummary() {
this.massValuesSummaryItem.innerContent = this.stringManager.getMassValuesSummaryText();
}

updateRobotEffort() {
this.robotsSummaryItem.innerContent = this.stringManager.getRobotEffortSummaryText();
}
}

Expand Down
108 changes: 98 additions & 10 deletions js/gravity-force-lab/view/GravityForceLabStringManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,86 @@ define( require => {
// modules
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 ISLCStringManager = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCStringManager' );
const LinearFunction = require( 'DOT/LinearFunction' );
const Property = require( 'AXON/Property' );
const StringUtils = require( 'PHETCOMMON/util/StringUtils' );
const Util = require( 'DOT/Util' );

// strings
const micronewtonsString = GravityForceLabA11yStrings.micronewtons.value;
const mass1AbbreviatedString = require( 'string!GRAVITY_FORCE_LAB/mass1Abbreviated' );
const mass2AbbreviatedString = require( 'string!GRAVITY_FORCE_LAB/mass2Abbreviated' );

const massValuesAndComparisonSummaryPatternString = GravityForceLabA11yStrings.massValuesAndComparisonSummaryPattern.value;

const muchMuchSmallerThanString = GravityForceLabA11yStrings.muchMuchSmallerThan.value;
const muchSmallerThanString = GravityForceLabA11yStrings.muchSmallerThan.value;
const slightlySmallerThanString = GravityForceLabA11yStrings.slightlySmallerThan.value;
const comparableToString = GravityForceLabA11yStrings.comparableTo.value;
const somewhatLargerThanString = GravityForceLabA11yStrings.somewhatLargerThan.value;
const muchLargerThanString = GravityForceLabA11yStrings.muchLargerThan.value;
const muchMuchLargerThanString = GravityForceLabA11yStrings.muchMuchLargerThan.value;
const RELATIVE_SIZE_STRINGS = [ muchMuchSmallerThanString, muchSmallerThanString, slightlySmallerThanString,
comparableToString, somewhatLargerThanString, muchLargerThanString,
muchMuchLargerThanString ];

// constants
const MICRO_CONVERSION_FACTOR = 1e6;
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 ) {

super( model, {
distanceUnits: micronewtonsString,
valueUnitConversion: 1e6
super( model, mass1AbbreviatedString, mass2AbbreviatedString, {
valueUnits: micronewtonsString,
valueUnitConversion: MICRO_CONVERSION_FACTOR
} );

// @private
this.model = model;
this._object1ToObject2Ratio = 0;
this._object2ToObject1Ratio = 0;

Property.multilink(
[ model.object1.radiusProperty, model.object2.radiusProperty ],
( r1, r2 ) => {
this._object1ToObject2Ratio = r1 / r2;
this._object2ToObject1Ratio = 1 / this._object1ToObject2Ratio;
}
);
}

// @override
/////////////////////
// Summary Strings //
/////////////////////

getMassValuesSummaryText() {
const relativeSizeIndex = Util.roundSymmetric( this.getRelativeSizeIndex( this._object1ToObject2Ratio ) );
const fillObject = {
m1Mass: this.object1.valueProperty.get(),
m2Mass: this.object2.valueProperty.get(),
comparitiveValue: RELATIVE_SIZE_STRINGS[ relativeSizeIndex ]
};
return StringUtils.fillIn( massValuesAndComparisonSummaryPatternString, fillObject );
}

getRelativeSizeIndex( ratio ) {
const exp = Math.log10( ratio );
return Util.roundSymmetric( exponentToIndex( exp ) );
}

///////////////
// Overrides //
///////////////
// see ISLCStringManager.js for more details

// NOTE: these are pure functions, so it may be possible to pass them into the supertype constructor
// as a config object

getForceVectorIndex( force ) {
const convertedForce = Math.abs( force ) * 1e6;
const convertedForce = Math.abs( force ) * MICRO_CONVERSION_FACTOR;
if ( convertedForce < 0.041713 ) {
return 0;
}
Expand All @@ -58,10 +118,38 @@ define( require => {
throw new Error( 'Invalid force value' );
}

/////////////////////
// Summary Strings //
/////////////////////
// @override
getDistanceIndex( distance ) {
assert && assert( distance > 0, 'Distance between spheres should always be positive.' );

if ( distance >= 8.8 ) {
return 0;
}
if ( distance >= 7 ) {
return 1;
}
if ( distance >= 5 ) {
return 2;
}
if ( distance >= 3 ) {
return 3;
}
if ( distance >= 1 ) {
return 4;
}
if ( distance >= 0.6 ) {
return 5;
}
if ( distance < 0.6 ) {
return 6;
}
throw new Error( 'Invalid distance value' );
}

// @override
getEffortIndex( force ) {
return Util.roundSymmetric( forceToPullIndex( force ) );
}
}

return gravityForceLab.register( 'GravityForceLabStringManager', GravityForceLabStringManager );
Expand Down
4 changes: 1 addition & 3 deletions js/gravity-force-lab/view/MassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ define( function( require ) {
var inherit = require( 'PHET_CORE/inherit' );
var ISLCObjectNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectNode' );
var RadialGradient = require( 'SCENERY/util/RadialGradient' );
var Range = require( 'DOT/Range' );
var Tandem = require( 'TANDEM/Tandem' );

// constants
var pullForceRange = new Range( ( 0.5e-10 ), ( 1.1e-6 ) ); // empirically determined for linear mapping of pull objects
var ARROW_LABEL_COLOR_STRING = '#000';
var MASS_NODE_Y_POSITION = 185;

Expand Down Expand Up @@ -54,7 +52,7 @@ define( function( require ) {
this.model = model;
this.objectModel = massModel;

ISLCObjectNode.call( this, model, massModel, layoutBounds, modelViewTransform, pullForceRange, options );
ISLCObjectNode.call( this, model, massModel, layoutBounds, modelViewTransform, GravityForceLabConstants.PULL_FORCE_RANGE, options );

var self = this;
model.scientificNotationProperty.link( function( scientificNotation ) {
Expand Down

0 comments on commit 8152040

Please sign in to comment.