Skip to content

Commit

Permalink
Add units to photon slider and angle readout label, see #81
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jan 17, 2025
1 parent 3496f4f commit c03aefd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion js/photons/view/FlatPolarizationAngleIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import DerivedStringProperty from '../../../../axon/js/DerivedStringProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Utils from '../../../../dot/js/Utils.js';
import Vector2 from '../../../../dot/js/Vector2.js';
Expand All @@ -16,6 +17,7 @@ import ArrowNode, { ArrowNodeOptions } from '../../../../scenery-phet/js/ArrowNo
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Circle, Color, Node, NodeOptions, Text } from '../../../../scenery/js/imports.js';
import QuantumMeasurementColors from '../../common/QuantumMeasurementColors.js';
import QuantumMeasurementConstants from '../../common/QuantumMeasurementConstants.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js';
import VectorTailNode from './VectorTailNode.js';
Expand Down Expand Up @@ -95,6 +97,16 @@ export default class FlatPolarizationAngleIndicator extends Node {
fill: QuantumMeasurementColors.photonBaseColorProperty
} );

// Create and position the angle readout label
const angleReadoutLabel = new Text( new DerivedStringProperty(
[ polarizationAngleProperty ],
angle => angle === null ? '' : `${QuantumMeasurementConstants.THETA} = ${angle}°`
), {
centerX: horizontalAxis.centerX + 35,
centerY: verticalAxis.top + 5,
font: new PhetFont( 12 )
} );

const options = optionize<PolarizationPlaneRepresentationOptions, SelfOptions, NodeOptions>()( {
children: [
unitCircle,
Expand All @@ -103,7 +115,8 @@ export default class FlatPolarizationAngleIndicator extends Node {
horizontalAxisLabel,
verticalAxisLabel,
polarizationVectorNode,
vectorTailSymbol
vectorTailSymbol,
angleReadoutLabel
]
}, providedOptions );

Expand Down
6 changes: 3 additions & 3 deletions js/photons/view/PhotonPolarizationAngleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ export default class PhotonPolarizationAngleControl extends Panel {
trackFillEnabled: Color.BLACK,
majorTickLength: 10,
majorTickLineWidth: 1.5,
constrainValue: value => Utils.roundToInterval( value, 1 ),
constrainValue: value => Utils.roundToInterval( value, 5 ),
tandem: providedOptions.tandem.createTandem( 'customAngleSlider' )
} );

// slider tick marks
customAngleSlider.addMajorTick( 0, new Text( 0, TICK_MARK_TEXT_OPTIONS ) );
customAngleSlider.addMajorTick( 90, new Text( 90, TICK_MARK_TEXT_OPTIONS ) );
customAngleSlider.addMajorTick( 0, new Text( '0°', TICK_MARK_TEXT_OPTIONS ) );
customAngleSlider.addMajorTick( 90, new Text( '90°', TICK_MARK_TEXT_OPTIONS ) );

// Assemble the title, radio button group, and slider into a VBox.
const leftPortionOfPanel = new VBox( {
Expand Down

0 comments on commit c03aefd

Please sign in to comment.