Skip to content

Commit

Permalink
improve phet-io tree, see #63
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Nov 26, 2024
1 parent dba43a9 commit bf209ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions js/photons/model/PhotonDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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
} );
}

Expand Down
3 changes: 2 additions & 1 deletion js/photons/model/PhotonsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default class PhotonsModel implements TModel {

this.experimentModeProperty = new Property<ExperimentModeType>( 'singlePhoton', {
tandem: providedOptions.tandem.createTandem( 'experimentModeProperty' ),
phetioValueType: StringUnionIO( ExperimentModeTypeValues )
phetioValueType: StringUnionIO( ExperimentModeTypeValues ),
validValues: ExperimentModeTypeValues
} );
this.singlePhotonSceneModel = new PhotonsExperimentSceneModel( {
photonEmissionMode: 'singlePhoton',
Expand Down
7 changes: 3 additions & 4 deletions js/photons/view/PhotonDetectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<NodeOptions, 'tandem'>;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bf209ad

Please sign in to comment.