Skip to content

Commit

Permalink
small force value linear function added, allows greater visual dynami…
Browse files Browse the repository at this point in the history
…cs for small force values, see phetsims/coulombs-law#27
  • Loading branch information
mbarlow12 committed Sep 8, 2017
1 parent 3e2c4a7 commit 237dfae
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions js/view/ISLCForceArrowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ define( function( require ) {
this.scientificNotationMode = options.defaultScientificNotationMode;
this.attractNegative = options.attractNegative;

var minArrowLength = arrowForceRange.min === 0 ? 0 : 1;
// get a new higher min
this.augmentedMin = ( ( arrowForceRange.max - arrowForceRange.min ) * 0.00003 ) + arrowForceRange.min;
// @private - maps the force value to the desired width of the arrow in view coordinates
this.forceToArrowWidthFunction = new LinearFunction( arrowForceRange.min, arrowForceRange.max, minArrowLength, options.maxArrowWidth, false );
this.forceToArrowWidthFunction = new LinearFunction( this.augmentedMin, arrowForceRange.max, 1.5, options.maxArrowWidth * 2, false );

// @private - when the force is below the typical arrow range, width of the arrow is mapped from 0 to 1
// this.forceToArrowWidthMinFunction = new LinearFunction( 0, arrowForceRange.min, 0, 1, false );
this.smallForceToArrowWidthFunction = new LinearFunction( 0, this.augmentedMin, 0, 1.5, false );

// @public (read-only) - for layout, the label for the arrow
this.arrowText = new RichText( options.title, {
Expand Down Expand Up @@ -107,17 +108,21 @@ define( function( require ) {
valueSign *= -1;
}
var absValue = Math.abs( value );
// if ( absValue < this.arrowForceRange.min ) {
// arrowLengthMultiplier = this.forceToArrowWidthMinFunction( absValue );
// }
// else {

if ( absValue < this.augmentedMin ) {
arrowLengthMultiplier = this.smallForceToArrowWidthFunction( absValue );
} else {
arrowLengthMultiplier = this.forceToArrowWidthFunction( absValue );
// }
}

if ( this.defaultDirection === 'right' ) {
arrowLengthMultiplier *= -1;
}

if ( value === 0 ) {
arrowLengthMultiplier = 0;
}

this.setTailAndTip( 0, 0, valueSign * arrowLengthMultiplier * ARROW_LENGTH, 0 );
},

Expand Down

0 comments on commit 237dfae

Please sign in to comment.