Skip to content

feat: add canvas rendering for Arrow, Link, Vector, and Image marks#530

Merged
gka merged 3 commits into
svelteplot:mainfrom
RobertFrenken:feat/canvas-marks
Mar 29, 2026
Merged

feat: add canvas rendering for Arrow, Link, Vector, and Image marks#530
gka merged 3 commits into
svelteplot:mainfrom
RobertFrenken:feat/canvas-marks

Conversation

@RobertFrenken

Copy link
Copy Markdown
Contributor

Summary

Add canvas rendering helpers for the four remaining marks that lacked canvas support, completing canvas coverage for all renderable marks.

  • ArrowCanvas — reuses existing arrowPath() geometry helper via new Path2D(pathString), no geometry duplication
  • LinkCanvas — uses d3-shape line().context(ctx) with curve factories for cartesian links
  • VectorCanvas — uses Path2D(shapePath()) with ctx.translate()/rotate() for positioned shapes; supports all three built-in shapes (arrow, spike, arrow-filled) plus custom ShapeRenderer
  • ImageCanvas — async image loading with Map<string, HTMLImageElement> cache; $state counter triggers redraws on load; circular clipping via ctx.arc()/clip() when r is set

Refactoring

  • Extracted shared vector shape definitions (arrow, spike, arrow-filled) and helpers (maybeShape, shapePath) from Vector.svelte to src/lib/helpers/vectorShapes.ts — both Vector.svelte (SVG) and VectorCanvas.svelte (canvas) import from the same source
  • Vector.svelte is net -53 lines after extraction

Convention

All four new helpers follow a standardized pattern (documented in CANVAS_GUIDE.md, included as a separate droppable commit):

  • Named interface with Datum extends DataRecord generics
  • options prop (not mark) — receives only what the helper needs
  • resolveScaledStyleProps() for style resolution + resolveColor() for CSS variable/currentColor handling
  • const render: Attachment = (canvasEl: Element) => lifecycle pattern
  • clearRect cleanup in $effect return

Existing canvas coverage (already in main)

The Tier 2 marks (BarX, BarY, Cell, RectX, RectY, AreaX, AreaY, RegressionX, RegressionY) already have canvas wired — they're thin wrappers that pass the canvas prop through to their parent marks (Rect, Area, Line) which handle it. No changes needed.

Test plan

  • pnpm test — 758 tests pass (91 files)
  • pnpm check — 0 type errors
  • pnpm lint — 0 errors (after prettier)

Closes #26, closes #28, closes #31, closes #473.
Prerequisite for #32 (<Plot canvas> toggle).

🤖 Generated with Claude Code

RobertFrenken and others added 2 commits March 23, 2026 22:59
Add canvas helpers for the four remaining marks without canvas support:

- ArrowCanvas: uses Path2D(arrowPath()) to reuse existing geometry
- LinkCanvas: uses d3-shape line().context() with curve factories
- VectorCanvas: uses Path2D(shapePath()) with canvas translate/rotate
- ImageCanvas: async image loading with cache + circular clipping

Extract shared vector shape definitions (arrow, spike, arrow-filled) to
src/lib/helpers/vectorShapes.ts to avoid duplication between Vector.svelte
and VectorCanvas.svelte.

All helpers follow a standardized convention: typed interface with
generics, options prop (not mark), resolveScaledStyleProps for styles,
Attachment pattern for lifecycle.

Closes svelteplot#26, closes svelteplot#28, closes svelteplot#31, closes svelteplot#473.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Standalone guide explaining how to add canvas rendering to a mark.
Covers the standardized convention, common patterns (Path2D, d3-shape
context, transforms), and a reference table of all canvas helpers.

Can be merged into CONTRIBUTING or kept as a standalone reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Mar 24, 2026

Copy link
Copy Markdown

Deploy Preview for svelteplot ready!

Name Link
🔨 Latest commit edee49e
🔍 Latest deploy log https://app.netlify.com/projects/svelteplot/deploys/69c3fcdfa53f64000898cb60
😎 Deploy Preview https://deploy-preview-530--svelteplot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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

@gka gka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks good, thanks

Comment thread CANVAS_GUIDE.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we move this into the AI instructions?

@gka gka merged commit bc173eb into svelteplot:main Mar 29, 2026
8 checks passed
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.

Add canvas rendering for Image mark Canvas rendering for Vector marks Canvas rendering for Link marks Canvas rendering for Arrow mark

2 participants