Skip to content

Make the visualizer rotation-aware (closes #1056)#1062

Merged
BioCam merged 3 commits into
PyLabRobot:mainfrom
BioCam:visualizer-iswap-orientation
May 26, 2026
Merged

Make the visualizer rotation-aware (closes #1056)#1062
BioCam merged 3 commits into
PyLabRobot:mainfrom
BioCam:visualizer-iswap-orientation

Conversation

@BioCam
Copy link
Copy Markdown
Collaborator

@BioCam BioCam commented May 25, 2026

Closes #1056. The Visualizer dropped rotation updates because Resource.rotate() had no notification channel and Resource.draw() never passed rotation to its Konva.Group.

Rotation becomes part of every resource's serialized state and rides the existing set_state channel: rotate() fires _state_updated(); base serialize_state() / load_state() include "rotation"; Container / TipSpot chain through super(). On the JS side, Resource.draw() and Resource.setState() apply rotation to the Konva.Group, and Container / TipSpot / LiquidHandler chain to super().setState(state).

Visualizer overlay markers follow rotation now. Outlines that should rotate with the resource (click and hover highlights) nest inside resource.group. Axis-aligned markers that must track a chosen anchor on a rotated resource (bullseye, delta-line endpoints, coords-tool readouts) go through three small rotation-aware helpers that mirror Python's Resource.get_absolute_* for the 2D z-only case; at zero rotation they reduce to the legacy math byte-for-byte, so the unrotated path is provably unchanged.

No public API change; pre-patch saved state JSONs still load.

Verified: 21 patch invariants, full pytest pylabrobot/ --ignore=pylabrobot/liquid_handling/backends (1405 tests), and the visualizer demo at 0°, 45°, 90°, 180°, 270° - plate body, both highlights, bullseye, and delta lines all track rotation.

🤖 Generated with Claude Code

Closes PyLabRobot#1056. The Visualizer dropped rotation updates because `Resource.rotate()` had no notification channel and `Resource.draw()` never passed `rotation` to its Konva.Group.

Rotation becomes part of every resource's serialized state and rides the existing `set_state` channel: `rotate()` fires `_state_updated()`; base `serialize_state()` / `load_state()` include `"rotation"`; `Container` / `TipSpot` chain through `super()`. On the JS side, `Resource.draw()` and `Resource.setState()` apply rotation to the Konva.Group, and `Container` / `TipSpot` / `LiquidHandler` chain to `super().setState(state)`.

Visualizer overlay markers follow rotation now. Outlines that should rotate with the resource (click and hover highlights) nest inside `resource.group`. Axis-aligned markers that must track a chosen anchor on a rotated resource (bullseye, delta-line endpoints, coords-tool readouts) go through three small rotation-aware helpers that mirror Python's `Resource.get_absolute_*` for the 2D z-only case; at zero rotation they reduce to the legacy math byte-for-byte, so the unrotated path is provably unchanged.

No public API change; pre-patch saved state JSONs still load.

Verified: 21 patch invariants, full `pytest pylabrobot/ --ignore=pylabrobot/liquid_handling/backends` (1405 tests), and the visualizer demo at 0°, 45°, 90°, 180°, 270° - plate body, both highlights, bullseye, and delta lines all track rotation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@BioCam BioCam requested review from Copilot and rickwierenga and removed request for rickwierenga May 25, 2026 22:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Makes the web visualizer correctly render and update resource rotation by propagating rotation through the existing Python set_state channel and applying it in the Konva render tree, including rotation-aware overlay/measurement markers.

Changes:

  • Python: rotation is now included in base Resource.serialize_state() / load_state(), and Resource.rotate() notifies via _state_updated().
  • JS visualizer: Resource.draw() and Resource.setState() apply rotation.z to the Konva Group; overlay marker math is updated to be rotation-aware.
  • State chaining: updated JS setState() overrides (e.g., Container, TipSpot, LiquidHandler) and Python tracker-based resources (e.g., Container, TipSpot) to incorporate super() rotation state.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pylabrobot/visualizer/lib.js Applies rotation to Konva groups; updates highlights and overlay/coords helpers to be rotation-aware.
pylabrobot/resources/resource.py Adds rotation to base state serialization/loading and emits state updates on rotate().
pylabrobot/resources/container.py Merges base state (rotation) with volume tracker state; calls super().load_state().
pylabrobot/resources/tip_rack.py Merges base state (rotation) with tip tracker state; calls super().load_state().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pylabrobot/resources/resource.py
BioCam and others added 2 commits May 25, 2026 23:32
Mirrors the Container/TipSpot pattern from this PR so `lh.rotate(...)` reaches
the visualizer via the existing `set_state` channel. Per Copilot review on PyLabRobot#1062.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…adout

Follow-up to the main rotation work on this PR. Three further
`getAbsoluteLocation()` callsites in lib.js were rotation-blind for the same
reason as the bullseye / highlights / delta lines:

- Tooltip position (`Resource.draw` mouseover) now centres on the rotated
  visual centre via `getResourceWorldReferencePoint`, so the tooltip floats
  above rotated resources instead of off to one side.
- `focusOnResource` (double-click zoom) now fits and centres on the rotated
  world AABB (small `getResourceWorldAABB` helper added) so the visible
  plate is what the viewport zooms to.
- Attribute panel `abs_location` readout now uses `getResourceWorldLocation`,
  so the value matches Python's `get_absolute_location()` for resources
  inside a rotated parent.

Unrotated path provably unchanged in all three: same `!xRefStr ||` fall-through
and at `totalRot=0` the cos/sin terms vanish. Verified: 21 invariants + 1405
broader tests + 38 stress assertions all green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@BioCam BioCam merged commit 31bcef2 into PyLabRobot:main May 26, 2026
21 checks passed
@BioCam BioCam deleted the visualizer-iswap-orientation branch May 26, 2026 08:07
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.

Visualizer does not render updated resource rotation (model reflects it correctly)

2 participants