Skip to content

Refactor constants and playback rate handling - #13

Merged
veillette merged 2 commits into
mainfrom
claude/refactor-model-view-separation-JkHj2
Feb 20, 2026
Merged

Refactor constants and playback rate handling#13
veillette merged 2 commits into
mainfrom
claude/refactor-model-view-separation-JkHj2

Conversation

@veillette

Copy link
Copy Markdown
Collaborator

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):

    • Moved VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_CENTER_X, VIDEO_CENTER_Y from SimModel.ts to shared constants file
    • Moved CALIB_HALF_LENGTH (renamed from CALIB_HALF_LEN) to shared constants
    • Updated all imports across view files (VideoPlayerNode, AutoTrackerNode, DigitizingOverlayNode, CoordinateSystemNode)
  • Kinematic graph simplification (KinematicsGraphNode.ts):

    • Removed 9 dummy NumberProperty instances (tProperty, xProperty, yProperty, vxProperty, vyProperty, speedProperty, axProperty, ayProperty, aMagProperty)
    • Updated createPlottableProperty() to no longer require a dummy property parameter
    • Simplified plottable property creation calls (removed property arguments)
    • Removed property disposal in cleanup
  • Playback rate handling (SimModel.ts & PlaybackControlsNode.ts):

    • Added playbackRateProperty to model with range [0.1, 4] and default value of 1
    • Implemented bidirectional sync between view's TimeSpeed enum and model's numeric playbackRateProperty
    • View → model: timeSpeedProperty updates playbackRateProperty
    • Model → view: playbackRateProperty updates timeSpeedProperty (enables reset behavior)
    • Updated VideoPlayerNode to apply model's playback rate to video element
  • PlottableProperty type refinement (PlottableProperty.ts):

    • Made property field optional (marked with ?)
    • Added documentation explaining when property can be omitted (when subStepAccessor covers all usage)
  • Graph data handling (ConfigurableGraph.ts):

    • Added null-safety checks for optional property field
    • Return early from addDataPoint() if either axis value is undefined
    • Use optional chaining and nullish coalescing in getAxisValue()

Implementation Details

The kinematic graph no longer maintains dummy properties because data is always pushed via addDataPointsFromSubSteps() rather than polled. The subStepAccessor functions provide all necessary data extraction.

The playback rate refactoring keeps the view-specific TimeSpeed enum 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

…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
@veillette
veillette merged commit 2922217 into main Feb 20, 2026
@veillette
veillette deleted the claude/refactor-model-view-separation-JkHj2 branch February 22, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants