Skip to content

Commit

Permalink
use math font for slope-intercept screen equations, #94
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Malley <[email protected]>
  • Loading branch information
pixelzoom committed Oct 28, 2018
1 parent 46e31a9 commit 522135f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions js/slopeintercept/view/SlopeInterceptEquationNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define( function( require ) {
var GLColors = require( 'GRAPHING_LINES/common/GLColors' );
var GLConstants = require( 'GRAPHING_LINES/common/GLConstants' );
var GLFont = require( 'GRAPHING_LINES/common/GLFont' );
var GLSymbols = require( 'GRAPHING_LINES/common/GLSymbols' );
var graphingLines = require( 'GRAPHING_LINES/graphingLines' );
var inherit = require( 'PHET_CORE/inherit' );
var Line = require( 'GRAPHING_LINES/common/model/Line' );
Expand All @@ -31,19 +32,15 @@ define( function( require ) {
var NumberPicker = require( 'SCENERY_PHET/NumberPicker' );
var PlusNode = require( 'SCENERY_PHET/PlusNode' );
var Property = require( 'AXON/Property' );
var RichText = require( 'SCENERY/nodes/RichText' );
var scenery = { Line: require( 'SCENERY/nodes/Line' ) }; // scenery.Line, workaround for name collision with graphing-lines.Line
var SlopePicker = require( 'GRAPHING_LINES/common/view/picker/SlopePicker' );
var StringUtils = require( 'PHETCOMMON/util/StringUtils' );
var Text = require( 'SCENERY/nodes/Text' );
var UndefinedSlopeIndicator = require( 'GRAPHING_LINES/common/view/UndefinedSlopeIndicator' );
var Util = require( 'DOT/Util' );

// strings
var slopeUndefinedString = require( 'string!GRAPHING_LINES/slopeUndefined' );
var symbolInterceptString = require( 'string!GRAPHING_LINES/symbol.intercept' );
var symbolSlopeString = require( 'string!GRAPHING_LINES/symbol.slope' );
var symbolXString = require( 'string!GRAPHING_LINES/symbol.x' );
var symbolYString = require( 'string!GRAPHING_LINES/symbol.y' );

/**
* @param {Property.<Line>} lineProperty
Expand Down Expand Up @@ -103,8 +100,8 @@ define( function( require ) {
var maxSlopePickerWidth = EquationNode.computeMaxSlopePickerWidth( options.riseRangeProperty, options.runRangeProperty, interactiveFont, self.DECIMAL_PLACES );

// Nodes that appear in all possible forms of the equation: y = -(rise/run)x + -b
var yNode = new Text( symbolYString, staticOptions );
var equalsNode = new Text( '=', staticOptions );
var yNode = new RichText( GLSymbols.y, staticOptions );
var equalsNode = new RichText( MathSymbols.EQUAL_TO, staticOptions );
var slopeMinusSignNode = new MinusNode( _.extend( { size: self.signLineSize }, staticOptions ) );
var riseNode;
var runNode;
Expand All @@ -117,7 +114,7 @@ define( function( require ) {
runNode = new DynamicValueNode( runProperty, _.extend( { absoluteValue: true }, staticOptions ) );
}
var slopeFractionLineNode = new scenery.Line( 0, 0, maxSlopePickerWidth, 0, fractionLineOptions );
var xNode = new Text( symbolXString, _.extend( { absoluteValue: true }, staticOptions ) );
var xNode = new RichText( GLSymbols.x, _.extend( { absoluteValue: true }, staticOptions ) );
var plusNode = new PlusNode( _.extend( { size: self.operatorLineSize }, staticOptions ) );
var minusNode = new MinusNode( _.extend( { size: self.operatorLineSize }, staticOptions ) );
var yInterceptMinusSignNode = new MinusNode( _.extend( {
Expand All @@ -138,7 +135,7 @@ define( function( require ) {
}
var yInterceptDenominatorNode = new DynamicValueNode( yInterceptDenominatorProperty, _.extend( { absoluteValue: true }, staticOptions ) );
var yInterceptFractionLineNode = new scenery.Line( 0, 0, maxSlopePickerWidth, 0, fractionLineOptions );
var slopeUndefinedNode = new Text( '?', staticOptions );
var slopeUndefinedNode = new RichText( '?', staticOptions );

// add all nodes, we'll set which ones are visible bases on desired simplification
self.children = [ yNode, equalsNode, slopeMinusSignNode, riseNode, runNode, slopeFractionLineNode, xNode, plusNode, minusNode,
Expand All @@ -165,8 +162,8 @@ define( function( require ) {
slopeUndefinedNode.visible = true;
slopeUndefinedNode.fill = lineColor;
slopeUndefinedNode.text = ( options.slopeUndefinedVisible ) ?
StringUtils.format( slopeUndefinedString, symbolXString, line.x1 ) :
StringUtils.format( GLConstants.PATTERN_0VALUE_EQUALS_1VALUE, symbolXString, line.x1 );
StringUtils.format( slopeUndefinedString, GLSymbols.x, line.x1 ) :
StringUtils.format( GLConstants.PATTERN_0VALUE_EQUALS_1VALUE, GLSymbols.x, line.x1 );
return;
}

Expand Down Expand Up @@ -457,9 +454,10 @@ define( function( require ) {
*/
createGeneralFormNode: function( options ) {
options = _.extend( { font: new GLFont( { size: 20, weight: 'bold' } ) }, options );
// y = mx + b
var text = StringUtils.format( '{0} {1} {2}{3} {4} {5}',
symbolYString, MathSymbols.EQUAL_TO, symbolSlopeString, symbolXString, MathSymbols.PLUS, symbolInterceptString );
return new Text( text, { font: options.font, pickable: false } );
GLSymbols.y, MathSymbols.EQUAL_TO, GLSymbols.m, GLSymbols.x, MathSymbols.PLUS, GLSymbols.b );
return new RichText( text, { font: options.font, pickable: false } );
},

/**
Expand Down

0 comments on commit 522135f

Please sign in to comment.