Refactor visualizer to use shared config ref, add DPR canvas scaling and stable draw updates - #10
Open
joesterne wants to merge 1 commit into
Open
Conversation
### Motivation - Ensure the popout visualizer renders crisply on high-DPI displays by sizing the canvas backing store to the device pixel ratio and keeping drawing coordinates in CSS pixels. ### Description - Use `const dpr = window.devicePixelRatio || 1` when resizing the canvas and in the draw path. - Set the backing store size with `canvas.width = window.innerWidth * dpr` and `canvas.height = window.innerHeight * dpr` while preserving CSS size with `canvas.style.width = '100vw'` and `canvas.style.height = '100vh'`. - Scale the 2D context with `ctx.setTransform(dpr, 0, 0, dpr, 0, 0)` so renderer coordinates remain in CSS pixels and drawing remains correctly sized. - Compute logical drawing dimensions as `const width = canvas.width / dpr` and `const height = canvas.height / dpr` and clear/draw using those values. ### Testing - Ran `git diff --check` which passed without issues. - Ran `npm run lint` (`tsc --noEmit`) which failed due to pre-existing duplicate block-scoped declarations in `src/components/Visualizer.tsx` unrelated to these changes, so lint did not complete successfully on the full project.
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.
Motivation
Description
visualizerConfigRefto hold{ mode, color, density, speed }and add update helpersupdateMode,updateColor,updateDensity, andupdateSpeedto keep ref and React state in sync.drawfunction to read configuration fromvisualizerConfigRef, useplaybackSpeedderived from the ref, and applyctx.setTransformfor proper DPR-aware rendering.messageevent handler to update the ref safely, only callset*when values change, and calldrawwith the stored speed.window.devicePixelRatio, set CSS size, and preapply transform in the resize handler.Testing
Codex Task