From bf209adcd66e8fdb01b6376904b8924913d80b49 Mon Sep 17 00:00:00 2001 From: jbphet Date: Mon, 25 Nov 2024 17:26:49 -0700 Subject: [PATCH] improve phet-io tree, see https://github.com/phetsims/quantum-measurement/issues/63 --- js/photons/model/PhotonDetector.ts | 12 ++++++++++-- js/photons/model/PhotonsModel.ts | 3 ++- js/photons/view/PhotonDetectorNode.ts | 7 +++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/photons/model/PhotonDetector.ts b/js/photons/model/PhotonDetector.ts index 044dcbc..0921b7f 100644 --- a/js/photons/model/PhotonDetector.ts +++ b/js/photons/model/PhotonDetector.ts @@ -8,6 +8,7 @@ */ import NumberProperty from '../../../../axon/js/NumberProperty.js'; +import Range from '../../../../dot/js/Range.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import { Line } from '../../../../kite/js/imports.js'; import { combineOptions } from '../../../../phet-core/js/optionize.js'; @@ -32,6 +33,9 @@ export type DetectionDirection = ( [ 'up', 'down' ] )[number]; // detection. export type DisplayMode = ( [ 'count', 'rate' ] )[number]; +export const COUNT_RANGE = new Range( 0, 999 ); +export const RATE_RANGE = new Range( 0, 999 ); // in events per second + export default class PhotonDetector implements TPhotonInteraction { // The position of the detector in two-dimensional space. Units are in meters. @@ -71,11 +75,15 @@ export default class PhotonDetector implements TPhotonInteraction { ); this.detectionRateProperty = new AveragingCounterNumberProperty( { - tandem: options.tandem.createTandem( 'detectionRateProperty' ) + tandem: options.tandem.createTandem( 'detectionRateProperty' ), + phetioReadOnly: true, + range: RATE_RANGE } ); this.detectionCountProperty = new NumberProperty( 0, { - tandem: options.tandem.createTandem( 'detectionCountProperty' ) + tandem: options.tandem.createTandem( 'detectionCountProperty' ), + phetioReadOnly: true, + range: COUNT_RANGE } ); } diff --git a/js/photons/model/PhotonsModel.ts b/js/photons/model/PhotonsModel.ts index ce6094e..cc1688d 100644 --- a/js/photons/model/PhotonsModel.ts +++ b/js/photons/model/PhotonsModel.ts @@ -49,7 +49,8 @@ export default class PhotonsModel implements TModel { this.experimentModeProperty = new Property( 'singlePhoton', { tandem: providedOptions.tandem.createTandem( 'experimentModeProperty' ), - phetioValueType: StringUnionIO( ExperimentModeTypeValues ) + phetioValueType: StringUnionIO( ExperimentModeTypeValues ), + validValues: ExperimentModeTypeValues } ); this.singlePhotonSceneModel = new PhotonsExperimentSceneModel( { photonEmissionMode: 'singlePhoton', diff --git a/js/photons/view/PhotonDetectorNode.ts b/js/photons/view/PhotonDetectorNode.ts index 7a37b63..487ed9b 100644 --- a/js/photons/view/PhotonDetectorNode.ts +++ b/js/photons/view/PhotonDetectorNode.ts @@ -12,7 +12,6 @@ import stepTimer from '../../../../axon/js/stepTimer.js'; import { TimerListener } from '../../../../axon/js/Timer.js'; import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import Dimension2 from '../../../../dot/js/Dimension2.js'; -import Range from '../../../../dot/js/Range.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; @@ -25,7 +24,7 @@ import isSettingPhetioStateProperty from '../../../../tandem/js/isSettingPhetioS import QuantumMeasurementColors from '../../common/QuantumMeasurementColors.js'; import quantumMeasurement from '../../quantumMeasurement.js'; import QuantumMeasurementStrings from '../../QuantumMeasurementStrings.js'; -import PhotonDetector, { DetectionDirection } from '../model/PhotonDetector.js'; +import PhotonDetector, { COUNT_RANGE, DetectionDirection, RATE_RANGE } from '../model/PhotonDetector.js'; type SelfOptions = EmptySelfOptions; type PhotonDetectorNodeOptions = SelfOptions & PickRequired; @@ -193,7 +192,7 @@ class PhotonCountDisplay extends HBox { } ); // Create a NumberDisplay that will show the count. - const numberDisplay = new NumberDisplay( photonCountProperty, new Range( 0, 999 ), { + const numberDisplay = new NumberDisplay( photonCountProperty, COUNT_RANGE, { align: 'center', backgroundFill: QuantumMeasurementColors.photonDetectorBodyColor, backgroundStroke: null, @@ -241,7 +240,7 @@ class PhotonRateDisplay extends NumberDisplay { maxWidth: number, center: Vector2 ) { - super( photonRateProperty, new Range( 0, 999 ), { + super( photonRateProperty, RATE_RANGE, { valuePattern: QuantumMeasurementStrings.eventsPerSecondPatternStringProperty, align: 'center', center: center,