Skip to content

fix: clear chart canvas independently of pixel ratio - #646

Open
TXyy2023 wants to merge 1 commit into
aradzie:masterfrom
TXyy2023:codex/issue-630-clear-scaled-canvas
Open

TXyy2023 wants to merge 1 commit into
aradzie:masterfrom
TXyy2023:codex/issue-630-clear-scaled-canvas

Conversation

@TXyy2023

@TXyy2023 TXyy2023 commented Oct 18, 2026 •

Copy link
Copy Markdown

Fixes #630.

Canvas scales its context by devicePixelRatio, but Shapes.clear() passes the already scaled canvas width and height to clearRect. When the ratio is below 1 (for example, browser zoom on a standard-density display), the clear rectangle is scaled a second time and leaves the right and bottom edges of the previous chart visible.

Save the context, reset its transform while clearing the full backing store, then restore it so subsequent chart drawing keeps the same coordinates and styles.

Validation:

  • Real Chrome Canvas using the repository's bundled Graphics/Shapes implementation at DPR 0.5, 0.8, 1, 1.25 and 2. Before the fix, DPR 0.5/0.8 left 60,000/73,728 stale pixels; after the fix, every ratio leaves zero. Transform, styles and subsequent scaled drawing are preserved. This checks the shared rendering primitive, not a full signed-in profile session.
  • npm run compile, npm run stylelint, npm run build -- --no-stats and DATABASE_CLIENT=sqlite npm test pass (all 58 test tasks).
  • ESLint and Prettier pass for the changed file.

Known upstream CI limitation: repository-wide npm run lint still reports 24 existing errors in 19 files that are byte-identical to upstream 05a37bc5. The upstream CI run also fails at that commit. No checks were skipped or disabled. The focused change is ready for review; the fork workflow awaits maintainer approval.

Implemented and validated with OpenAI Codex.

@semanticdiff-com

semanticdiff-com Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  packages/keybr-widget/lib/components/canvas/graphics.ts  33% smaller

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.

Visual artifacts remain on the right side when charts are redrawn

1 participant