Skip to content

feat: add Treemap and Sunburst trace types#1

Open
jqnatividad wants to merge 8 commits into
masterfrom
feat/treemap-sunburst-traces
Open

feat: add Treemap and Sunburst trace types#1
jqnatividad wants to merge 8 commits into
masterfrom
feat/treemap-sunburst-traces

Conversation

@jqnatividad

Copy link
Copy Markdown

Summary

Adds two hierarchical trace types — Treemap and Sunburst — to the plotly crate, following the existing Pie trace pattern.

Library

  • Treemap<V> (plotly/src/traces/treemap.rs): labels/parents/values hierarchy with branch_values, count, level, max_depth, domain, shared Marker, full text/hover field set, plus treemap-specific Tiling (with Packing) and PathBar (with Side) helper structs and a shared BranchValues enum.
  • Sunburst<V> (plotly/src/traces/sunburst.rs): same hierarchy/text/hover set plus Leaf (opacity), rotation, and inside_text_orientation.
  • New PlotType::Treemap / PlotType::Sunburst variants and top-level re-exports (plotly::Treemap, plotly::Sunburst, and the treemap/sunburst modules).
  • New Layout options treemapcolorway / extendtreemapcolors (mirroring the existing sunburst pair).

Tests, examples & docs

  • Unit tests + doctests for both traces; layout serialization tests extended to cover the new colorway options.
  • Four runnable examples in examples/basic_charts (basic_treemap, styled_treemap, basic_sunburst, styled_sunburst).
  • Book pages treemap_charts.md and sunburst_charts.md, linked in SUMMARY.md and the basic-charts overview table.

Verification

  • cargo test -p plotly — new unit tests + doctests pass (pre-existing browser static-export tests are unaffected).
  • cargo clippy --features ... -- -D warnings clean (lib + examples).
  • cargo +nightly fmt --all applied to both workspaces.
  • Examples build & run, generating the inline HTML the book embeds.

Notes

  • marker.pad/cornerradius/depthfade (treemap-only) are not yet exposed — documented in the Treemap doc comment; the shared Marker covers colors/colorscale/colorbar/line.
  • No CHANGELOG.md entry is included (the working-tree edit was reverted intentionally); happy to add one referencing this PR's number.

🤖 Generated with Claude Code

jqnatividad and others added 8 commits June 25, 2026 16:20
Add hierarchical Treemap and Sunburst traces, mirroring the existing Pie
trace pattern:

- Treemap<V>: labels/parents/values hierarchy with BranchValues, plus
  Tiling (Packing) and PathBar (Side) helper structs
- Sunburst<V>: same hierarchy plus Leaf, rotation and
  inside_text_orientation
- New Treemap/Sunburst PlotType variants and top-level re-exports
- treemapcolorway/extendtreemapcolors Layout options
- Unit tests, doctests, basic_charts examples and book pages

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the shared common::Marker on Treemap with a treemap-specific
Marker exposing the treemap-only attributes: pad (Pad{t,l,r,b}),
corner_radius, and depth_fade (true/false/"reversed"). The shared
color/colorscale/colorbar/line/pattern machinery is retained, and the
scatter-only fields (size, symbol, ...) that don't apply to treemaps are
dropped. Showcased in the styled_treemap example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replaces the three vendored plotly.min.js copies (plotly, plotly_static,
docs/book) with v3.6.0 and bumps the pinned CDN version strings in
plot.rs, the jupyter notebook template, plotly_static template, and the
book header.

Closes plotly#407

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Surfaces the user-facing attributes added across plotly.js 3.1.0 through
3.6.0 (now bundled), following the existing Option<T> + FieldSetter pattern:

- Layout: hoversort (HoverSort), hoveranywhere, clickanywhere
- Axis: zerolinelayer (ZeroLineLayer), minorloglabels, modebardisable
  (ModeBarDisable), ticklabelposition (TickLabelPosition), unifiedhovertitle
  (UnifiedHoverTitle), and ExponentFormat::SIExtended
- Legend: maxheight
- Configuration: displayNotifier
- common::Label (hover labels): showarrow
- common::Pattern: path (arbitrary SVG path fill)
- Candlestick/Ohlc: hovertemplate
- hovertemplatefallback / texttemplatefallback across applicable traces

These are additive (new fields/enums/variants). Because FieldSetter and
layout_structs generate per-field Restyle/Relayout enum variants, adding any
field is a semver-breaking change; this targets the next breaking release
(0.15.0), consistent with the Treemap/Sunburst additions already on this
branch.

Refs plotly#407

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The Plotly.js pattern schema marks `path` as arrayOk (pathsrc present),
like shape/bgcolor/fgcolor/size/solidity. Modeling it as Option<String>
prevented per-point custom SVG path fills. Switch to Option<Dim<String>>
so FieldSetter generates both scalar and array setters, and add a
serialize_pattern_path test covering both forms.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Plotly's `insidetextorientation` attribute expects the full words
`horizontal`/`radial`/`tangential`/`auto`, but the field reused the
general `Orientation` enum which serializes to single-letter codes
(`h`/`v`/`r`/`t`). `Orientation::Radial` emitted `"r"`, which plotly.js
silently coerces to the default `"auto"` — so setting a radial sunburst
orientation was a no-op.

Add a sunburst-specific `InsideTextOrientation` enum
(`#[serde(rename_all = "lowercase")]` -> full words) and switch the
field to it. The shared `Orientation` enum is left untouched so bars,
boxes, legends and sankey keep their correct `h`/`v` codes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The Sunburst inside_text_orientation setter takes the Sunburst-specific
InsideTextOrientation enum, not common::Orientation. Update the example
import and call so the basic-charts example crate compiles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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