Skip to content

feat(Treemap): Add selected prop to zoom into a node without distorting tiles or padding - #1017

Merged
techniq merged 2 commits into
mainfrom
techniq/nested-zoom-issue
Nov 22, 2026
Merged

techniq merged 2 commits into
mainfrom
techniq/nested-zoom-issue

Conversation

@techniq

@techniq techniq commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Zooming the Treemap nested zoom example distorts the tiles and blows up the padding.

Why

The treemap was tiled once at full size, then Bounds stretched the selected node to fill the chart. The stretch differs in x and y, so squarified tiles lose their shape, and padding (layout pixels) is scaled with it: the 20px headers became ~70px and the 4px gaps ~16px.

Fix

Treemap gets a selected prop (matched by data):

  1. Everything is scaled so the selected node fills the chart, pushing its siblings off-screen.
  2. The selected subtree is tiled again at full chart size, so tiles are squarified for the space they actually get and padding stays in pixels.

The nested-zoom example drops Bounds and passes {selected}. It animates with the existing motion props on Group, Rect and RectClipPath, with the nodes keyed by data, so each node tweens from its old rectangle to its new one.

Tradeoff

With squarify, the arrangement of tiles at the zoomed size can differ from the overview, so siblings can briefly slide across each other during the 800ms tween. They always stay inside their parents. With Maintain Aspect Ratio on, the arrangement is unchanged and the transition is a clean scale.

Comparison

Before

CleanShot.2026-11-22.at.12.26.20.AM.mp4

After

CleanShot.2026-11-22.at.12.27.04.AM.mp4

🤖 Generated with Claude Code

…ting tiles or padding

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 331c4d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
layerchart Minor
@layerchart/webgl Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/layerchart@1017
npm i https://pkg.pr.new/@layerchart/webgl@1017

commit: 331c4d8

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

⚠️ Warnings (1 significant size increase)

Item Current New Change
🔴 Treemap 7.50 KB
2.66 gz
8.10 KB
2.87 gz
+0.60 KB (+7.9%)
+0.21 gz (+8.0%)

Use-Case Scenarios

Hierarchy (1 changed)
Scenario Current New Change
🟡 hierarchy-treemap 356.27 KB
83.88 gz
356.87 KB
84.08 gz
+0.61 KB (+0.2%)
+0.20 gz (+0.2%)
Graph / network (1 changed)
Scenario Current New Change
🟡 sankey 361.59 KB
84.87 gz
359.72 KB
84.53 gz
-1.87 KB (-0.5%)
-0.33 gz (-0.4%)
Components (2 changed)
Scenario Current New Change
🟢 Sankey 9.65 KB
2.94 gz
8.29 KB
2.69 gz
-1.35 KB (-14.0%)
-0.25 gz (-8.6%)
🔴 Treemap 7.50 KB
2.66 gz
8.10 KB
2.87 gz
+0.60 KB (+7.9%)
+0.21 gz (+8.0%)
Worst case (1 changed)
Scenario Current New Change
🟡 all 1108.18 KB
263.55 gz
1103.60 KB
262.33 gz
-4.58 KB (-0.4%)
-1.22 gz (-0.5%)

Understanding this report
  • Use-case scenarios measure the bundle cost of common chart configurations (e.g. a line chart with axes)
  • Individual components measure each component imported in isolation
  • Svelte runtime is excluded; sizes reflect layerchart + its dependencies (d3, etc.)
  • When multiple components share dependencies (e.g. d3-scale), the real-world cost is lower than the sum of individual sizes
  • Changes smaller than 10 bytes or 0.1% are considered insignificant

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@techniq
techniq merged commit 4c1825b into main Nov 22, 2026
10 checks passed
@techniq
techniq deleted the techniq/nested-zoom-issue branch November 22, 2026 06:50
@github-actions github-actions Bot mentioned this pull request Nov 22, 2026
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