Refactor constants and playback rate handling - #13
Merged
Conversation
…ttableProperty Two concrete violations of model/view separation were addressed: 1. VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_CENTER_X, VIDEO_CENTER_Y and CALIB_HALF_LENGTH were defined in SimModel.ts — a model file — even though they describe screen pixel layout. They are now canonical in TrackLabConstants.ts (alongside the other layout constants already there). SimModel imports what it needs (video dimensions for the tracker, center positions for the initial tool positions); view files (CoordinateSystemNode, VideoPlayerNode, DigitizingOverlayNode, AutoTrackerNode) now import directly from TrackLabConstants without touching the model file. 2. KinematicsGraphNode created nine dummy NumberProperty instances whose sole purpose was to satisfy the required property field on PlottableProperty, even though none of their values were ever read (all kinematic data is fed via addDataPointsFromSubSteps / subStepAccessor). PlottableProperty.property is now optional — callers that provide a subStepAccessor covering all data paths may omit it. ConfigurableGraph.addDataPoint() and getValueForAxis() handle the absent-property case. The nine dummy properties are removed from KinematicsGraphNode. No behaviour changes; error count in tsc --noEmit is identical to the baseline. https://claude.ai/code/session_014wtoa1APrzTAN9xNFUe2cc
timeSpeedProperty (EnumerationProperty<TimeSpeed>) in PlaybackControlsNode
was directly setting videoElement.playbackRate. model.reset() already resets
the analogous frameRateProperty, but the playback speed was silently skipped,
so after Reset All the video could continue at half speed.
Fix:
- Add playbackRateProperty (NumberProperty, default 1.0) to SimModel alongside
frameRateProperty. Include it in reset().
- VideoPlayerNode links model.playbackRateProperty → videoElement.playbackRate
(the single point where the DOM element is updated).
- PlaybackControlsNode keeps its view-local timeSpeedProperty (TimeSpeed is a
scenery-phet type that must not enter the model) and syncs bidirectionally:
view → model: timeSpeedProperty.link sets model.playbackRateProperty
model → view: model.playbackRateProperty.lazyLink updates timeSpeedProperty
This mirrors the isDigitizingProperty pattern in TrackListPanel and is safe
because Axon deduplicates same-value writes.
https://claude.ai/code/session_014wtoa1APrzTAN9xNFUe2cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR consolidates shared constants into a centralized location, removes unnecessary dummy properties from the kinematic graph, and improves playback rate handling by syncing a view-local enum with a model property.
Key Changes
Centralized constants (
TrackLabConstants.ts):VIDEO_WIDTH,VIDEO_HEIGHT,VIDEO_CENTER_X,VIDEO_CENTER_YfromSimModel.tsto shared constants fileCALIB_HALF_LENGTH(renamed fromCALIB_HALF_LEN) to shared constantsVideoPlayerNode,AutoTrackerNode,DigitizingOverlayNode,CoordinateSystemNode)Kinematic graph simplification (
KinematicsGraphNode.ts):NumberPropertyinstances (tProperty,xProperty,yProperty,vxProperty,vyProperty,speedProperty,axProperty,ayProperty,aMagProperty)createPlottableProperty()to no longer require a dummy property parameterPlayback rate handling (
SimModel.ts&PlaybackControlsNode.ts):playbackRatePropertyto model with range [0.1, 4] and default value of 1TimeSpeedenum and model's numericplaybackRatePropertytimeSpeedPropertyupdatesplaybackRatePropertyplaybackRatePropertyupdatestimeSpeedProperty(enables reset behavior)VideoPlayerNodeto apply model's playback rate to video elementPlottableProperty type refinement (
PlottableProperty.ts):propertyfield optional (marked with?)subStepAccessorcovers all usage)Graph data handling (
ConfigurableGraph.ts):propertyfieldaddDataPoint()if either axis value is undefinedgetAxisValue()Implementation Details
The kinematic graph no longer maintains dummy properties because data is always pushed via
addDataPointsFromSubSteps()rather than polled. ThesubStepAccessorfunctions provide all necessary data extraction.The playback rate refactoring keeps the view-specific
TimeSpeedenum out of the model while maintaining proper synchronization. The model's numeric property allows clean reset behavior and decouples the model from scenery-phet dependencies.https://claude.ai/code/session_014wtoa1APrzTAN9xNFUe2cc