Skip to content

feat: density mark#532

Merged
gka merged 9 commits intomainfrom
feat/density-mark
Apr 7, 2026
Merged

feat: density mark#532
gka merged 9 commits intomainfrom
feat/density-mark

Conversation

@gka
Copy link
Copy Markdown
Contributor

@gka gka commented Mar 25, 2026

Summary

  • Adds a new Density mark for two-dimensional kernel density estimation
  • Computes KDE in pixel space using d3's contourDensity, renders iso-density contour bands via marching squares and geoPath
  • Supports fill="density" / stroke="density" to map density levels through the plot's color scale
  • Full faceting support via fx/fy — thresholds are derived from the global density maximum across all facet groups so the color scale stays consistent between panels
  • Optional weight channel for weighted KDE
  • Configurable bandwidth (Gaussian kernel σ in pixels, default 20) and thresholds (count or explicit array)
  • Canvas rendering via canvas prop (backed by DensityCanvas.svelte, following the GeoCanvas pattern)
  • Fixes null-facet bug: bootstrap records and color-scale anchor records are emitted once per facet group (with correct fxVal/fyVal), preventing a spurious undefined panel from appearing in faceted plots
  • Fixes temporal x/y domains: the extent computation now explicitly reconstructs Date objects from millisecond min/max values so inferScaleType correctly returns 'time'

New files

File Purpose
src/lib/marks/Density.svelte Mark component
src/lib/marks/helpers/DensityCanvas.svelte Canvas rendering helper
src/routes/marks/density/+page.md Docs page
src/routes/marks/density/+page.ts Data loader for docs
src/routes/examples/density/basic.svelte Isolines + scatter overlay
src/routes/examples/density/filled.svelte Filled bands with color scale
src/routes/examples/density/faceted.svelte Faceted by species
src/tests/density.test.ts 12 unit tests
src/tests/density.test.svelte Test harness component
src/tests/densitySharedScale.test.svelte Shared-scale edge case harness
static/data/cherryblossom.csv Dataset for temporal example

Modified files

  • src/lib/marks/index.ts — export Density
  • src/lib/types/mark.ts — add 'density' to MarkType
  • src/lib/types/plot.ts — add Density import and density key to PlotDefaults
  • src/lib/marks/ColorLegend.svelte — minor related fix
  • src/routes/marks/density/+page.md — docs: bandwidth, thresholds, faceting, weight, temporal example
  • src/routes/transforms/density/+page.md — cross-link to 2D density mark

Test plan

  • pnpm test — all unit tests pass
  • pnpm check — 0 type errors
  • Visual check: basic density isolines render correctly
  • Visual check: fill="density" with a color scheme shows filled bands
  • Visual check: faceted density produces per-panel estimates with a consistent color scale and no extra null panel
  • Visual check: temporal x domain (cherry blossom example) shows year labels on x axis
  • Canvas mode: canvas prop renders contour bands to a <canvas> element

🤖 Generated with Claude Code

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 25, 2026

Deploy Preview for svelteplot ready!

Name Link
🔨 Latest commit ed002d3
🔍 Latest deploy log https://app.netlify.com/projects/svelteplot/deploys/69d570513603bc000854c934
😎 Deploy Preview https://deploy-preview-532--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.

@gka gka marked this pull request as draft March 25, 2026 07:02
@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.12.0-pr-532.0

Install it with:

npm install svelteplot@pr-532
# or install the specific version
npm install svelteplot@0.12.0-pr-532.0

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: 925ec8d460

ℹ️ 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".

Comment thread src/lib/marks/Density.svelte Outdated
Comment thread src/lib/marks/Density.svelte Outdated
@gka gka force-pushed the feat/density-mark branch from 925ec8d to bacc8ba Compare April 2, 2026 22:09
@gka gka marked this pull request as ready for review April 6, 2026 17:25
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

📦 Preview package for this PR is published!

Version: 0.12.0-pr-532.1

Install it with:

npm install svelteplot@pr-532
# or install the specific version
npm install svelteplot@0.12.0-pr-532.1

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: ccb62e3d13

ℹ️ 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".

Comment thread src/lib/marks/Density.svelte Outdated
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

📦 Preview package for this PR is published!

Version: 0.12.0-pr-532.2

Install it with:

npm install svelteplot@pr-532
# or install the specific version
npm install svelteplot@0.12.0-pr-532.2

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

📦 Preview package for this PR is published!

Version: 0.12.0-pr-532.3

Install it with:

npm install svelteplot@pr-532
# or install the specific version
npm install svelteplot@0.12.0-pr-532.3

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

📦 Preview package for this PR is published!

Version: 0.12.0-pr-532.4

Install it with:

npm install svelteplot@pr-532
# or install the specific version
npm install svelteplot@0.12.0-pr-532.4

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

📦 Preview package for this PR is published!

Version: 0.12.0-pr-532.5

Install it with:

npm install svelteplot@pr-532
# or install the specific version
npm install svelteplot@0.12.0-pr-532.5

@gka gka merged commit f43aa61 into main Apr 7, 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.

1 participant