From 2c2fc850a0f4cacf251af06af8798250a209809e Mon Sep 17 00:00:00 2001 From: Michael Barlow Date: Mon, 26 Nov 2018 21:02:16 -0500 Subject: [PATCH] alert text for mass control focus, see #109 --- .../view/GravityForceLabAlertManager.js | 9 +++ .../view/GravityForceLabScreenView.js | 18 +++++ .../view/GravityForceLabStringManager.js | 70 +++++++++++++++++-- js/gravity-force-lab/view/MassControl.js | 6 +- 4 files changed, 93 insertions(+), 10 deletions(-) diff --git a/js/gravity-force-lab/view/GravityForceLabAlertManager.js b/js/gravity-force-lab/view/GravityForceLabAlertManager.js index f973a899..e6cb4a83 100644 --- a/js/gravity-force-lab/view/GravityForceLabAlertManager.js +++ b/js/gravity-force-lab/view/GravityForceLabAlertManager.js @@ -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; @@ -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 ); diff --git a/js/gravity-force-lab/view/GravityForceLabScreenView.js b/js/gravity-force-lab/view/GravityForceLabScreenView.js index dea5fd48..2c793799 100644 --- a/js/gravity-force-lab/view/GravityForceLabScreenView.js +++ b/js/gravity-force-lab/view/GravityForceLabScreenView.js @@ -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 ); @@ -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 ); @@ -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 ); diff --git a/js/gravity-force-lab/view/GravityForceLabStringManager.js b/js/gravity-force-lab/view/GravityForceLabStringManager.js index 3bd0a906..1c58a948 100644 --- a/js/gravity-force-lab/view/GravityForceLabStringManager.js +++ b/js/gravity-force-lab/view/GravityForceLabStringManager.js @@ -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 ); @@ -85,6 +87,7 @@ define( require => { // @private this._object1ToObject2Ratio = 0; this._object2ToObject1Ratio = 0; + this._radiusDifference = 0; this.formatMassValue = options.formatMassValue; this.centerOffset = options.centerOffset; this.formatPositionUnitMark = options.formatPositionUnitMark; @@ -92,8 +95,26 @@ define( require => { 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; } ); } @@ -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, @@ -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 ) { diff --git a/js/gravity-force-lab/view/MassControl.js b/js/gravity-force-lab/view/MassControl.js index 0ede2772..9c893d9a 100644 --- a/js/gravity-force-lab/view/MassControl.js +++ b/js/gravity-force-lab/view/MassControl.js @@ -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 @@ -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: {