Skip to content

Commit

Permalink
add xAxisLabelString and yAxisLabelString parameters to GraphNode, be…
Browse files Browse the repository at this point in the history
…cause it's used in 2 sims with different string Properties, phetsims/graphing-quadratics#178
  • Loading branch information
pixelzoom committed Jun 6, 2023
1 parent ffad157 commit 0aad176
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion js/common/view/GLIconFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import DimensionalArrowNode from './DimensionalArrowNode.js';
import GraphNode from './GraphNode.js';
import Manipulator from './manipulator/Manipulator.js';
import SlopeToolNode from './SlopeToolNode.js';
import GLSymbols from '../GLSymbols.js';

// constants
const scenery = {
Expand Down Expand Up @@ -137,7 +138,7 @@ const GLIconFactory = {
const axisRange = new Range( -3, 3 );
const graph = new Graph( axisRange, axisRange );
const modelViewTransform = ModelViewTransform2.createOffsetXYScaleMapping( new Vector2( 0, 0 ), 15, -15 );
const graphNode = new GraphNode( graph, modelViewTransform );
const graphNode = new GraphNode( graph, modelViewTransform, GLSymbols.x, GLSymbols.y );
const p1 = modelViewTransform.modelToViewXY( x1, y1 );
const p2 = modelViewTransform.modelToViewXY( x2, y2 );
graphNode.addChild( new Path( Shape.lineSegment( p1.x, p1.y, p2.x, p2.y ), {
Expand Down
19 changes: 11 additions & 8 deletions js/common/view/GraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import ArrowNode from '../../../../scenery-phet/js/ArrowNode.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Line, Node, Path, Rectangle, RichText, Text } from '../../../../scenery/js/imports.js';
import graphingLines from '../../graphingLines.js';
import GLSymbols from '../GLSymbols.js';
import Graph from '../model/Graph.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';

//----------------------------------------------------------------------------------------
// constants
Expand Down Expand Up @@ -53,7 +53,10 @@ export default class GraphNode extends Node {

private readonly gridNode: GridNode;

public constructor( graph: Graph, modelViewTransform: ModelViewTransform2 ) {
public constructor( graph: Graph,
modelViewTransform: ModelViewTransform2,
xAxisLabelString: TReadOnlyProperty<string> | string,
yAxisLabelString: TReadOnlyProperty<string> | string ) {

// (0,0) and quadrant 1 is visible
assert && assert( graph.contains( new Vector2( 0, 0 ) ) && graph.contains( new Vector2( 1, 1 ) ) );
Expand All @@ -63,8 +66,8 @@ export default class GraphNode extends Node {
super( {
children: [
gridNode,
new XAxisNode( graph, modelViewTransform ),
new YAxisNode( graph, modelViewTransform )
new XAxisNode( graph, xAxisLabelString, modelViewTransform ),
new YAxisNode( graph, yAxisLabelString, modelViewTransform )
]
} );

Expand Down Expand Up @@ -149,7 +152,7 @@ class MinorTickNode extends Path {
*/
class XAxisNode extends Node {

public constructor( graph: Graph, modelViewTransform: ModelViewTransform2 ) {
public constructor( graph: Graph, xAxisLabelString: TReadOnlyProperty<string> | string, modelViewTransform: ModelViewTransform2 ) {

super();

Expand All @@ -167,7 +170,7 @@ class XAxisNode extends Node {
this.addChild( lineNode );

// label at positive (right) end
const labelNode = new RichText( GLSymbols.x, { font: AXIS_LABEL_FONT, maxWidth: 30 } );
const labelNode = new RichText( xAxisLabelString, { font: AXIS_LABEL_FONT, maxWidth: 30 } );
this.addChild( labelNode );
labelNode.left = lineNode.right + AXIS_LABEL_SPACING;
labelNode.centerY = lineNode.centerY;
Expand Down Expand Up @@ -197,7 +200,7 @@ class XAxisNode extends Node {
*/
class YAxisNode extends Node {

public constructor( graph: Graph, modelViewTransform: ModelViewTransform2 ) {
public constructor( graph: Graph, yAxisLabelString: TReadOnlyProperty<string> | string, modelViewTransform: ModelViewTransform2 ) {

super();

Expand All @@ -215,7 +218,7 @@ class YAxisNode extends Node {
this.addChild( lineNode );

// label at positive (top) end
const labelNode = new RichText( GLSymbols.y, { font: AXIS_LABEL_FONT, maxWidth: 30 } );
const labelNode = new RichText( yAxisLabelString, { font: AXIS_LABEL_FONT, maxWidth: 30 } );
this.addChild( labelNode );
labelNode.centerX = lineNode.centerX;
labelNode.bottom = lineNode.top - AXIS_LABEL_SPACING;
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/LineFormsGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import LineNode, { CreateDynamicLabelFunction } from './LineNode.js';
import SlopeToolNode from './SlopeToolNode.js';
import LineFormsViewProperties from './LineFormsViewProperties.js';
import Line from '../model/Line.js';
import GLSymbols from '../GLSymbols.js';

export default class LineFormsGraphNode extends GraphNode {

Expand All @@ -42,7 +43,7 @@ export default class LineFormsGraphNode extends GraphNode {
viewProperties: LineFormsViewProperties,
createDynamicLabel: CreateDynamicLabelFunction ) {

super( model.graph, model.modelViewTransform );
super( model.graph, model.modelViewTransform, GLSymbols.x, GLSymbols.y );

this.model = model;
this.viewProperties = viewProperties;
Expand Down
3 changes: 2 additions & 1 deletion js/linegame/view/ChallengeGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import graphingLines from '../../graphingLines.js';
import LineGameConstants from '../LineGameConstants.js';
import Challenge from '../model/Challenge.js';
import NotALine from '../model/NotALine.js';
import GLSymbols from '../../common/GLSymbols.js';

type SelfOptions = {
answerLineVisible?: boolean;
Expand Down Expand Up @@ -60,7 +61,7 @@ export default class ChallengeGraphNode extends GraphNode {
slopeToolEnabled: true
}, providedOptions );

super( challenge.graph, challenge.modelViewTransform );
super( challenge.graph, challenge.modelViewTransform, GLSymbols.x, GLSymbols.y );

// To reduce brain damage during development, show the answer as a translucent gray line.
if ( phet.chipper.queryParameters.showAnswers ) {
Expand Down

0 comments on commit 0aad176

Please sign in to comment.