Skip to content

Commit

Permalink
new a11y string content, and endDrag logic for creating position chan…
Browse files Browse the repository at this point in the history
…ge alerts, new string manager getter functions, variable renaming, see phetsims/gravity-force-lab#124 and phetsims/gravity-force-lab#109
  • Loading branch information
mbarlow12 committed Dec 13, 2018
1 parent f9bb084 commit e8c4ecb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
20 changes: 15 additions & 5 deletions js/ISLCA11yStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ define( require => {
const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' );

const ISLCA11yStrings = {
// TODO: replace instances of {{objectValueUnits}} or {{valueAndUnits}} to {{value}} {{units}}

/***************************
* Summary Pattern Strings *
***************************/
vectorSizePattern: {
summaryVectorSizePattern: {
value: 'Force vectors are {{size}}.'
},
vectorSizeValueUnitsPattern: {
summaryVectorSizeValueUnitsPattern: {
value: 'Force vectors are {{size}} at {{objectValueUnits}}.'
},
robotPullSummaryPattern: {
Expand Down Expand Up @@ -90,15 +91,24 @@ define( require => {
/************************
* Force vector strings *
************************/
forceVectorsSize: {
forceVectorSizePattern: {
value: 'Force vectors {{size}}.'
},
vectorAlertNoValuePattern: {
vectorSizeForcesValuePattern: {
value: 'Vectors {{size}}, forces {{valueAndUnits}}.'
},
vectorSizePattern: {
value: 'Vectors {{changeOrSize}}.'
},
vectorAlertWithValuePattern: {
vectorSizeForcesNowValuePattern: {
value: 'Vectors {{changeOrSize}}, forces now {{valueAndUnits}}.'
},
getBigger: {
value: 'get bigger'
},
getSmaller: {
value: 'get smaller'
},

/**********************
* Qualitative Values *
Expand Down
32 changes: 31 additions & 1 deletion js/view/ISLCObjectNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ define( function( require ) {
var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );
var Tandem = require( 'TANDEM/Tandem' );
var Util = require( 'DOT/Util' );
var Utterance = require( 'SCENERY_PHET/accessibility/Utterance' );
var utteranceQueue = require( 'SCENERY_PHET/accessibility/utteranceQueue' );

// phetio
var BooleanProperty = require( 'AXON/BooleanProperty' );
Expand Down Expand Up @@ -85,7 +87,7 @@ define( function( require ) {
* @param {Object} options
* @constructor
*/
function ISLCObjectNode( model, object, layoutBounds, modelViewTransform, pullForceRange, options ) {
function ISLCObjectNode( model, object, layoutBounds, stringManager, modelViewTransform, pullForceRange, options ) {

var self = this;

Expand Down Expand Up @@ -294,7 +296,11 @@ define( function( require ) {

this.redrawForce();

// a11y - for experimenting with default step sizes. Ignore if not explicitly set
var defaultStepSize = QueryStringMachine.containsKey( 'stepSize' ) ? ISLCQueryParameters.stepSize : options.snapToNearest * 2;

var currentPosition = object.positionProperty.get();
var currentForce = model.forceProperty.get();
var accessibleSliderOptions = {
keyboardStep: defaultStepSize,
shiftKeyboardStep: options.snapToNearest,
Expand All @@ -306,10 +312,34 @@ define( function( require ) {
},
startDrag: function() {
object.isDragging = true;
currentPosition = object.positionProperty.get();
currentForce = model.forceProperty.get();
},
endDrag: function() {
var newPosition = object.positionProperty.get();
var newForce = model.forceProperty.get();
var forceGrowing = ( newForce - currentForce ) > 0;
var positionChanged = newPosition - currentPosition;
object.isDragging = false;
self.redrawForce();

// TODO: consider implementing with alertManager
// alertManager.positionSliderAlert( positionChanged );
if ( positionChanged ) {
// alert force vectors changed
// TODO: consider setting forceGrowing in ISLCStringManager
utteranceQueue.addToBack( new Utterance( {
alert: stringManager.getForceVectorsChangedAlertText( forceGrowing ),
uniqueGroupId: 'forceVectorChanged'
} ) );
}
else {
// alert state of force vectors
utteranceQueue.addToBack( new Utterance( {
alert: stringManager.getForceVectorStateAlertText(),
uniqueGroupId: 'forceVectorState'
} ) );
}
},
createAriaValueText: options.createAriaValueText
};
Expand Down
48 changes: 40 additions & 8 deletions js/view/ISLCStringManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ define( require => {
const unitsMetersString = require( 'string!INVERSE_SQUARE_LAW_COMMON/units.meters' );
const unitsNewtonsString = require( 'string!INVERSE_SQUARE_LAW_COMMON/units.newtons' );

const vectorSizePatternString = ISLCA11yStrings.vectorSizePattern.value;
const vectorSizeValueUnitsPatternString = ISLCA11yStrings.vectorSizeValueUnitsPattern.value;
const summaryVectorSizePatternString = ISLCA11yStrings.summaryVectorSizePattern.value;
const summaryVectorSizeValueUnitsPatternString = ISLCA11yStrings.summaryVectorSizeValueUnitsPattern.value;
const summaryInteractionHintPatternString = ISLCA11yStrings.summaryInteractionHintPattern.value;
const distanceAndValueSummaryPatternString = ISLCA11yStrings.distanceAndValueSummaryPattern.value;
const robotPullSummaryPatternString = ISLCA11yStrings.robotPullSummaryPattern.value;
const robotPushSummaryPatternString = ISLCA11yStrings.robotPushSummaryPattern.value;

const vectorSizePatternString = ISLCA11yStrings.vectorSizePattern.value;
const forceVectorSizePatternString = ISLCA11yStrings.forceVectorSizePattern.value;
const vectorSizeForcesValuePatternString = ISLCA11yStrings.vectorSizeForcesValuePattern.value;
const vectorSizeForcesNowValuePatternString = ISLCA11yStrings.vectorSizeForcesNowValuePattern.value;

// sphere strings
// const spherePositionHelpTextString = ISLCA11yStrings.spherePositionHelpText.value;
const forceVectorMagnitudePatternString = ISLCA11yStrings.forceVectorMagnitudePattern.value;
const forceAndVectorPatternString = ISLCA11yStrings.forceAndVectorPattern.value;
const positionMeterMarkPatternString = ISLCA11yStrings.positionMeterMarkPattern.value;
const objectLabelPositionPatternString = ISLCA11yStrings.objectLabelPositionPattern.value;
// const spherePositionProgressObjectPatternString = ISLCA11yStrings.spherePositionProgressObjectPattern.value;
// const spherePositionProgressPatternString = ISLCA11yStrings.spherePositionProgressPattern.value;
const spherePositionRegionObjectPatternString = ISLCA11yStrings.spherePositionRegionObjectPattern.value;
// const spherePositionRegionPatternString = ISLCA11yStrings.spherePositionRegionPattern.value;

/* new from 12/11/18 */
const positionDistanceFromOtherObjectPatternString = ISLCA11yStrings.positionDistanceFromOtherObjectPattern.value;
const progressDistanceFromOtherObjectPatternString = ISLCA11yStrings.progressDistanceFromOtherObjectPattern.value;
const distanceFromOtherObjectPatternString = ISLCA11yStrings.distanceFromOtherObjectPattern.value;
const lastStopDistanceFromOtherObjectPatternString = ISLCA11yStrings.lastStopDistanceFromOtherObjectPattern.value;

const getBiggerString = ISLCA11yStrings.getBigger.value;
const getSmallerString = ISLCA11yStrings.getSmaller.value;

const tinyString = ISLCA11yStrings.tiny.value;
const verySmallString = ISLCA11yStrings.verySmall.value;
const smallString = ISLCA11yStrings.small.value;
Expand Down Expand Up @@ -221,8 +225,8 @@ define( require => {
getForceVectorsSummaryText() {
const fillObject = {};
const pattern = this.model.forceValuesProperty.get() ?
vectorSizeValueUnitsPatternString :
vectorSizePatternString;
summaryVectorSizeValueUnitsPatternString :
summaryVectorSizePatternString;

fillObject.size = this.getForceVectorSize();

Expand Down Expand Up @@ -253,6 +257,34 @@ define( require => {
return StringUtils.fillIn( pattern, { effort } );
}

getForceVectorsChangedAlertText( vectorsGrowing ) {
const changeOrSize = vectorsGrowing ? getBiggerString : getSmallerString;
const valueAndUnits = this.getForceValueText();
const fillObject = { changeOrSize };

let pattern = vectorSizePatternString;

if ( this.model.forceValuesProperty.get() ) {
pattern = vectorSizeForcesNowValuePatternString;
fillObject.valueAndUnits = valueAndUnits;
}

return StringUtils.fillIn( pattern, fillObject );
}

getForceVectorStateAlertText() {
const size = this.getForceVectorSize();
const fillObject = { size };
let pattern = forceVectorSizePatternString;

if ( this.model.forceValuesProperty.get() ) {
pattern = vectorSizeForcesValuePatternString;
fillObject.valueAndUnits = this.getForceValueText();
}

return StringUtils.fillIn( pattern, fillObject );
}

// TODO: string usage
getPositionFocusAlertText() {
const pattern = 'Force vectors {{size}}';
Expand Down

0 comments on commit e8c4ecb

Please sign in to comment.