Skip to content

Commit

Permalink
alert text for mass control focus, see #109
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarlow12 committed Nov 27, 2018
1 parent 9c82e25 commit 2c2fc85
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 10 deletions.
9 changes: 9 additions & 0 deletions js/gravity-force-lab/view/GravityForceLabAlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ 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 ISLCA11yStrings = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCA11yStrings' );
const ISLCAlertManager = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCAlertManager' );
const Utterance = require( 'SCENERY_PHET/accessibility/Utterance' );
const utteranceQueue = require( 'SCENERY_PHET/accessibility/utteranceQueue' );

// constants
// const { OBJECT_ONE } = ISLCObjectEnum;

// strings
const forcesInScientificNotationString = ISLCA11yStrings.forcesInScientificNotation.value;
const constantRadiusThinkDensityString = GravityForceLabA11yStrings.constantRadiusThinkDensity.value;
Expand Down Expand Up @@ -53,6 +57,11 @@ define( require => {
const utterance = new Utterance( { alert, uniqueGroupId: 'constantRadius' } );
utteranceQueue.addToBack( utterance );
}

alertMassControlFocus( objectEnum ) {
const alert = this.stringManager.getMassControlFocusAlertText( objectEnum );
utteranceQueue.addToBack( alert );
}
}

return gravityForceLab.register( 'GravityForceLabAlertManager', GravityForceLabAlertManager );
Expand Down
18 changes: 18 additions & 0 deletions js/gravity-force-lab/view/GravityForceLabScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ define( function( require ) {
addScreenSummaryNode: true,
tandem: tandem
} );
var self = this;
var stringManager = new GravityForceLabStringManager( model, mass1AbbreviatedString, mass2AbbreviatedString );
this.alertManager = new GravityForceLabAlertManager( model, stringManager );
var summaryNode = new GravityForceLabScreenSummaryNode( model, stringManager );
Expand Down Expand Up @@ -166,11 +167,23 @@ define( function( require ) {
} );
playAreaNode.addChild( massControlsNode );

// function massControlOnFocus( objectEnum ) {
// return function( event ) {
// this.alertManager.alertMassControlFocus( objectEnum );
// };
// }

var massControl1 = new MassControl(
mass1String,
model.object1.valueProperty,
GravityForceLabConstants.MASS_RANGE,
GravityForceLabConstants.MASS_BLUE_COLOR,
{
onFocus: function( event ) {
console.log( 'from screenview', self);
self.alertManager.alertMassControlFocus( OBJECT_ONE );
}
},
tandem.createTandem( 'massControl1' )
);
massControl1.scale( CONTROL_SCALE );
Expand All @@ -181,6 +194,11 @@ define( function( require ) {
model.object2.valueProperty,
GravityForceLabConstants.MASS_RANGE,
GravityForceLabConstants.MASS_RED_COLOR,
{
onFocus: function( event ) {
self.alertManager.alertMassControlFocus( OBJECT_TWO );
}
},
tandem.createTandem( 'massControl2' )
);
massControl2.scale( CONTROL_SCALE );
Expand Down
70 changes: 63 additions & 7 deletions js/gravity-force-lab/view/GravityForceLabStringManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ define( require => {
// constants
const MICRO_CONVERSION_FACTOR = 1e6;
const { OBJECT_ONE } = ISLCObjectEnum;
const exponentToIndex = new LinearFunction( -1, 1, 0, 6 );
// const exponentToIndex = new LinearFunction( -1, 1, 0, 6 );
// const massDifferenceToIndex = new LinearFunction( -500, 500, 0, 6, true );
const radiusDifferenceToIndex = new LinearFunction( -0.6, 0.6, 0, 6, true );
const { min, max } = GravityForceLabConstants.PULL_FORCE_RANGE;
const forceToPullIndex = new LinearFunction( min, max, 6, 0, true );

Expand Down Expand Up @@ -85,15 +87,34 @@ define( require => {
// @private
this._object1ToObject2Ratio = 0;
this._object2ToObject1Ratio = 0;
this._radiusDifference = 0;
this.formatMassValue = options.formatMassValue;
this.centerOffset = options.centerOffset;
this.formatPositionUnitMark = options.formatPositionUnitMark;

Property.multilink(
[ model.object1.radiusProperty, model.object2.radiusProperty ],
( r1, r2 ) => {
this._object1ToObject2Ratio = r1 / r2;
this._object2ToObject1Ratio = 1 / this._object1ToObject2Ratio;
console.log( 'radius diff', r1 - r2);
this._radiusDifference = r1 - r2;
// max diff -1.0507898924466623
// min diff 0
}
);

Property.multilink(
[ model.object1.valueProperty, model.object2.valueProperty ],
( m1, m2 ) => {
/*
* TS noted in the design doc about using 'steps' instead of ratios
* this implies that I should take the actual difference between the two
* values
* One advantage is that I can simply use the sign of the value
*/
// this._object1ToObject2Ratio = r1 / r2;
// this._object2ToObject1Ratio = 1 / this._object1ToObject2Ratio;
// if r2 is larger than r1 then the value will be negative
this._objectDifference = m1 - m2;
}
);
}
Expand All @@ -103,7 +124,7 @@ define( require => {
/////////////////////

getMassValuesSummaryText() {
const relativeSizeIndex = Util.roundSymmetric( this.getRelativeSizeIndex( this._object1ToObject2Ratio ) );
const relativeSizeIndex = Util.roundSymmetric( this.getRelativeSizeIndex( this._radiusDifference ) );
const fillObject = {
mass1Label: this.object1Label,
mass2Label: this.object2Label,
Expand Down Expand Up @@ -140,14 +161,49 @@ define( require => {
return objectEnum === OBJECT_ONE ? massBlueSpherePatternString : massRedSpherePatternString;
}

getMassControlFocusAlertText( objectEnum ) {
const pattern = '{{value}} kilograms, {{size}}, {{relativeSize}} {{otherObject}}';
const thisObject = objectEnum === OBJECT_ONE ? this.object1 : this.object2;
const value = thisObject.valueProperty.get();
const size = this.getSizeOfMass( value );
const relativeSize = this.getObjectRelativeSize( objectEnum );
const otherObject = objectEnum === OBJECT_ONE ? this.object2Label : this.object1Label;
return StringUtils.fillIn( pattern, { value, size, relativeSize, otherObject } );
}

getSizeOfMass( massValue ) {
const massIndex = this.getMassSizeIndex( massValue );
return this.getSizeFromIndex( massIndex );
}

getRelativeSizeIndex( ratio ) {
const exp = Math.log10( ratio );
return Util.roundSymmetric( exponentToIndex( exp ) );
getObjectRelativeSize( objectEnum ) {
// const ratio = objectEnum === OBJECT_ONE ? this._object1ToObject2Ratio : this._object2ToObject1Ratio;
const difference = objectEnum === OBJECT_ONE ? this._radiusDifference : this._radiusDifference * -1;
// console.log('getObjectRelativeSize', difference);
const index = this.getRelativeSizeIndex( difference );
return this.getRelativeSizeFromIndex( index );
}

getRelativeSizeFromIndex( index ) {
// negative values => much smaller than (this < other)
// positive values =>
return RELATIVE_SIZE_STRINGS[ index ];
}

getRelativeSizeIndex( difference ) {
// step size is ~50
// const exp = Math.log10( difference );
// return Util.roundSymmetric( exponentToIndex( exp ) );
console.log( 'getraltivesizeindex radius diff', difference );
console.log( Util.roundSymmetric( radiusDifferenceToIndex(difference) ) );
return Util.roundSymmetric( radiusDifferenceToIndex( difference ) );
// if ( difference > 500 ) {
// return 0;
// }
//
// if ( difference > 300 && ) {
//
// }
}

getMassSizeIndex( mass ) {
Expand Down
6 changes: 3 additions & 3 deletions js/gravity-force-lab/view/MassControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ define( function( require ) {
* @param {Tandem} tandem
* @constructor
*/
function MassControl( titleString, valueProperty, massRange, thumbColor, tandem ) {

function MassControl( titleString, valueProperty, massRange, thumbColor, options, tandem ) {
ISLCObjectControlPanel.call( this, titleString, unitsKgString, valueProperty, massRange, {

// panel options
Expand All @@ -60,7 +59,8 @@ define( function( require ) {
keyboardStep: 50,
pageKeyboardStep: 100,
accessibleName: titleString,
accessibleValuePattern: valueKilogramsPatternString // {{value}} kilograms
accessibleValuePattern: valueKilogramsPatternString, // {{value}} kilograms
onFocus: options.onFocus
},

tickLabelOptions: {
Expand Down

0 comments on commit 2c2fc85

Please sign in to comment.