Skip to content

feat: raster mark#520

Merged
gka merged 25 commits intomainfrom
feat/raster-mark
Mar 13, 2026
Merged

feat: raster mark#520
gka merged 25 commits intomainfrom
feat/raster-mark

Conversation

@gka
Copy link
Copy Markdown
Contributor

@gka gka commented Mar 10, 2026

resolves #88

Summary

  • Adds a new Raster mark that renders data as an SVG <image> element, mapping values through the color scale onto a pixel grid
  • Supports three modes: dense grid (flat array + width/height), scatter interpolation (x/y channel data spatially interpolated via none/nearest/barycentric/random-walk), and function sampling (fill as an (x, y) => value function)
  • Adds rasterInterpolate.ts helper with four interpolation strategies (none, nearest, Delaunay barycentric, random-walk / walk-on-spheres)
  • Fixes Line mark: when both z and stroke channels are set, lines are now segmented by changes in either channel (multi-colored lines), with sub-segments sharing endpoints to avoid gaps
  • Adds docs page at /marks/raster with live examples for all three modes, blur, and pixelSize
  • Adds four raster examples to the examples gallery

Test plan

  • pnpm test passes (729 tests including new line segmentation test)
  • /marks/raster doc page renders correctly with live examples
  • /examples/raster gallery shows all four examples
  • Dense grid (volcano), scatter interpolation (CA55), and function sampling (Mandelbrot) examples all render correctly
  • Line mark: z + stroke channels produce multi-colored segmented lines

🤖 Generated with Claude Code

gka and others added 5 commits March 10, 2026 19:37
When both z and stroke channels are specified, group lines by changes in
either channel. Sub-segments share an endpoint with the next sub-segment
so multi-colored lines render without gaps.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 10, 2026

Deploy Preview for svelteplot ready!

Name Link
🔨 Latest commit edf1db9
🔍 Latest deploy log https://app.netlify.com/projects/svelteplot/deploys/69b4368ecaf197000895974f
😎 Deploy Preview https://deploy-preview-520--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 Sonnet 4.6 <noreply@anthropic.com>
@gka gka added this to the 1.0 milestone Mar 10, 2026
@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.0

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.0

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.1

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.1

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.2

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.2

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.3

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.3

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c0450c678

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let Fraw: any[];
if (typeof fill === 'function') {
Fraw = (data as any[]).map(fill as (d: any) => any);
} else if (fill != null && typeof fill !== 'string') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle string fill accessors in dense raster mode

The dense-grid fill extraction excludes string accessors (fill != null && typeof fill !== 'string'), so fill="value" skips accessor resolution and leaves Fraw as the original objects; later color mapping then receives objects instead of scalar values and renders incorrect/transparent pixels. This breaks the documented dense-grid object-data usage (and also misbehaves for constant string fills).

Useful? React with 👍 / 👎.

Comment thread src/lib/marks/Raster.svelte Outdated
Comment on lines +210 to +211
const xData = xScale(bx1 + xi * kx);
const yData = yScale(by1 + yi * ky);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Sample function over raster indices without extra scaling

In sampler mode, pixel centers are multiplied by kx/ky before being passed to scales whose domains are already [0,w] and [0,h]. When pixelSize differs from 1 (or explicit width/height changes canvas resolution), this evaluates fill(x,y) outside the requested [x1,x2] × [y1,y2] bounds and distorts sampled outputs.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.4

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.4

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.5

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.5

… Raster

Two bugs caused `effect_update_depth_exceeded` and NaN pixel coordinates
when combining the Raster mark's function-sampling mode with `aspectRatio`:

1. Reactive oscillation: `height` (from aspectRatio) depended on `plotWidth`
   which depended on `autoMarginLeft` (AxisY label widths) which depended on
   y-tick count which depended on `plotHeight` → circular. Fixed by introducing
   `plotWidthForAspectRatio` that uses only user-specified margins (zero when
   set to 'auto'), breaking the feedback cycle.

2. NaN initialization: before any marks mount, x/y domains are empty so
   `heightFromAspect` computed `Math.abs(undefined - undefined) = NaN`. Since
   NaN is not nullish, this propagated through scale range computation giving
   every datum NaN pixel coordinates. Fixed by guarding `heightFromAspect` to
   return `DEFAULTS.height` when domains are degenerate or non-finite.

Also adds a test case covering aspectRatio + sampler mode, and updates the
sampled raster example to use aspectRatio={1}.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.6

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.6

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.7

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.7

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.8

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.8

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.11.1-pr-520.9

Install it with:

npm install svelteplot@pr-520
# or install the specific version
npm install svelteplot@0.11.1-pr-520.9

@gka gka merged commit 7da5a35 into main Mar 13, 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.

feature: add raster mark

1 participant