Skip to content

Commit

Permalink
add referenceLineNode.xDisplayProperty, #305
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Mar 28, 2023
1 parent e23fab3 commit 77717e8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/common/view/ReferenceLineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import ReferenceLine from '../model/ReferenceLine.js';
import ScrubberNode from './ScrubberNode.js';
import Multilink from '../../../../axon/js/Multilink.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import Utils from '../../../../dot/js/Utils.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';

// number of decimal places shown for the x value, dragging snaps to this interval
const X_DECIMAL_PLACES = 1;
Expand All @@ -47,8 +49,14 @@ export default class ReferenceLineNode extends ScrubberNode {
phetioHandleNodeVisiblePropertyInstrumented: false
} );

const xDisplayProperty = new DerivedProperty( [ referenceLine.xProperty ],
x => Utils.roundToInterval( x, Math.pow( 10, -X_DECIMAL_PLACES ) ), {
tandem: tandem.createTandem( 'xDisplayProperty' ),
phetioValueType: NumberIO
} );

// Create and add a numerical label at the top of the vertical line
const numberDisplay = new NumberDisplay( referenceLine.xProperty,
const numberDisplay = new NumberDisplay( xDisplayProperty,
CalculusGrapherConstants.CURVE_X_RANGE, {
align: 'center',
decimalPlaces: X_DECIMAL_PLACES,
Expand Down

0 comments on commit 77717e8

Please sign in to comment.