Skip to content

Commit

Permalink
use common function to create display arrows, see #337
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jul 21, 2023
1 parent ae16f62 commit e428996
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions js/common/view/FluxMeterNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,9 @@ class EnergyFluxDisplay extends Node {
// Set a clip area so that the arrows don't go outside the background.
boundsRectangle.clipArea = Shape.bounds( boundsRectangle.getRectBounds() );

// Create and add the arrows.
this.downArrow = new ArrowNode(
boundsRectangle.width / 2,
boundsRectangle.height / 2,
boundsRectangle.width / 2,
boundsRectangle.height / 2,
options.arrowNodeOptions
);
this.upArrow = new ArrowNode(
boundsRectangle.width / 2,
boundsRectangle.height / 2,
boundsRectangle.width / 2,
boundsRectangle.height / 2,
options.arrowNodeOptions
);
// Create and add the arrows that will be used to indicate the magnitude of the flux in the up and down directions.
this.downArrow = EnergyFluxDisplay.createDisplayArrowNode( boundsRectangle, options.arrowNodeOptions );
this.upArrow = EnergyFluxDisplay.createDisplayArrowNode( boundsRectangle, options.arrowNodeOptions );
boundsRectangle.addChild( this.downArrow );
boundsRectangle.addChild( this.upArrow );

Expand Down Expand Up @@ -516,6 +504,20 @@ class EnergyFluxDisplay extends Node {
return flux * this.fluxToArrowLengthMultiplierProperty.value;
}

private static createDisplayArrowNode( boundsRectangle: Rectangle, options: ArrowNodeOptions ) : ArrowNode {

// Create an arrow node with no length that is positioned in the center of the provided bounds rectangle. Other
// code will set the tip to different values to indicate a magnitude.
return new ArrowNode(
boundsRectangle.width / 2,
boundsRectangle.height / 2,
boundsRectangle.width / 2,
boundsRectangle.height / 2,
options
);

}

// an empirically determined value used in part to set the overall width of the panel
public static readonly WIDTH = 45;
}
Expand Down

0 comments on commit e428996

Please sign in to comment.