Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

https://github.com/plotly/plotly.rs/pull/350

## [Unreleased]

### Added

- [[#NNN](https://github.com/plotly/plotly.rs/pull/NNN)] Add `Treemap` trace type, with `Tiling`/`PathBar` helpers, a dedicated `treemap::Marker` (`pad`/`corner_radius`/`depth_fade`), and `treemapcolorway`/`extendtreemapcolors` layout options
- [[#NNN](https://github.com/plotly/plotly.rs/pull/NNN)] Add `Sunburst` trace type

## [0.14.1] - 2026-02-15

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- [Bar Charts](./recipes/basic_charts/bar_charts.md)
- [Pie Charts](./recipes/basic_charts/pie_charts.md)
- [Sankey Diagrams](./recipes/basic_charts/sankey_diagrams.md)
- [Treemap Charts](./recipes/basic_charts/treemap_charts.md)
- [Sunburst Charts](./recipes/basic_charts/sunburst_charts.md)
- [Statistical Charts](./recipes/statistical_charts.md)
- [Error Bars](./recipes/statistical_charts/error_bars.md)
- [Box Plots](./recipes/statistical_charts/box_plots.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/book/src/recipes/basic_charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Line Charts | [![Line Charts](./img/line_shape_options_for_interpolation.png)](.
Bar Charts | [![Bar Charts](./img/bar_chart_with_error_bars.png)](./basic_charts/scatter_plots.md)
Pie Charts | [![Pie Charts](./img/pie_charts.png)](./basic_charts/pie_charts.md)
Sankey Diagrams | [![Sankey Diagrams](./img/basic_sankey.png)](./basic_charts/sankey_diagrams.md)
Treemap Charts | [Treemap Charts](./basic_charts/treemap_charts.md)
Sunburst Charts | [Sunburst Charts](./basic_charts/sunburst_charts.md)
27 changes: 27 additions & 0 deletions docs/book/src/recipes/basic_charts/sunburst_charts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Sunburst Charts

The following imports have been used to produce the plots below:

```rust,no_run
use plotly::common::Orientation;
use plotly::sunburst::Leaf;
use plotly::treemap::BranchValues;
use plotly::{Plot, Sunburst};
```

The `to_inline_html` method is used to produce the html plot displayed in this page.

## Basic Sunburst
```rust,no_run
{{#include ../../../../../examples/basic_charts/src/main.rs:basic_sunburst}}
```

{{#include ../../../../../examples/basic_charts/output/inline_basic_sunburst.html}}


## Styled Sunburst with Branch Values and Leaf Opacity
```rust,no_run
{{#include ../../../../../examples/basic_charts/src/main.rs:styled_sunburst}}
```

{{#include ../../../../../examples/basic_charts/output/inline_styled_sunburst.html}}
25 changes: 25 additions & 0 deletions docs/book/src/recipes/basic_charts/treemap_charts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Treemap Charts

The following imports have been used to produce the plots below:

```rust,no_run
use plotly::treemap::{BranchValues, Packing, PathBar, Side, Tiling};
use plotly::{Plot, Treemap};
```

The `to_inline_html` method is used to produce the html plot displayed in this page.

## Basic Treemap
```rust,no_run
{{#include ../../../../../examples/basic_charts/src/main.rs:basic_treemap}}
```

{{#include ../../../../../examples/basic_charts/output/inline_basic_treemap.html}}


## Styled Treemap with Tiling and Path Bar
```rust,no_run
{{#include ../../../../../examples/basic_charts/src/main.rs:styled_treemap}}
```

{{#include ../../../../../examples/basic_charts/output/inline_styled_treemap.html}}
114 changes: 113 additions & 1 deletion examples/basic_charts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ use plotly::{
TicksDirection, TraceOrder,
},
sankey::{Line as SankeyLine, Link, Node},
sunburst::Leaf,
traces::table::{
Align as TableAlign, Cells, Fill as TableFill, Font as TableFont, Header, Line as TableLine,
},
Bar, Pie, Plot, Sankey, Scatter, ScatterPolar, Table,
treemap::{BranchValues, Marker as TreemapMarker, Packing, PathBar, Side, Tiling},
Bar, Pie, Plot, Sankey, Scatter, ScatterPolar, Sunburst, Table, Treemap,
};
use plotly_utils::write_example_to_html;
use rand_distr::{Distribution, Normal, Uniform};
Expand Down Expand Up @@ -1043,6 +1045,108 @@ fn grouped_donout_pie_charts(show: bool, file_name: &str) {
}
// ANCHOR_END: grouped_donout_pie_charts

// ANCHOR: basic_treemap
fn basic_treemap(show: bool, file_name: &str) {
let labels = vec![
"Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura",
];
let parents = vec![
"", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve",
];
let trace = Treemap::new(labels, parents)
.values(vec![10.0, 14.0, 12.0, 10.0, 2.0, 6.0, 6.0, 4.0, 4.0])
.text_info("label+value");

let mut plot = Plot::new();
plot.add_trace(trace);

let path = write_example_to_html(&plot, file_name);
if show {
plot.show_html(path);
}
}
// ANCHOR_END: basic_treemap

// ANCHOR: styled_treemap
fn styled_treemap(show: bool, file_name: &str) {
let labels = vec![
"Total",
"Tech",
"Health",
"Finance",
"Software",
"Hardware",
"Pharma",
"Devices",
"Banking",
"Insurance",
];
let parents = vec![
"", "Total", "Total", "Total", "Tech", "Tech", "Health", "Health", "Finance", "Finance",
];
let trace = Treemap::new(labels, parents)
.values(vec![0.0, 0.0, 0.0, 0.0, 40.0, 30.0, 25.0, 15.0, 20.0, 18.0])
.branch_values(BranchValues::Remainder)
.marker(
TreemapMarker::new()
.corner_radius(5.0)
.line(Line::new().width(1.0).color(NamedColor::White)),
)
.tiling(Tiling::new().packing(Packing::Binary).pad(2.0))
.path_bar(PathBar::new().visible(true).side(Side::Top))
.text_info("label+value+percent parent");

let mut plot = Plot::new();
plot.add_trace(trace);

let path = write_example_to_html(&plot, file_name);
if show {
plot.show_html(path);
}
}
// ANCHOR_END: styled_treemap

// ANCHOR: basic_sunburst
fn basic_sunburst(show: bool, file_name: &str) {
let labels = vec![
"Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura",
];
let parents = vec![
"", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve",
];
let trace = Sunburst::new(labels, parents)
.values(vec![10.0, 14.0, 12.0, 10.0, 2.0, 6.0, 6.0, 4.0, 4.0]);

let mut plot = Plot::new();
plot.add_trace(trace);

let path = write_example_to_html(&plot, file_name);
if show {
plot.show_html(path);
}
}
// ANCHOR_END: basic_sunburst

// ANCHOR: styled_sunburst
fn styled_sunburst(show: bool, file_name: &str) {
let labels = vec!["Root", "Branch A", "Branch B", "Leaf A1", "Leaf B1"];
let parents = vec!["", "Root", "Root", "Branch A", "Branch B"];
let trace = Sunburst::new(labels, parents)
.values(vec![8.0, 3.0, 5.0, 3.0, 5.0])
.branch_values(BranchValues::Total)
.leaf(Leaf::new().opacity(0.7))
.inside_text_orientation(Orientation::Radial);

let mut plot = Plot::new();
plot.add_trace(trace);

let path = write_example_to_html(&plot, file_name);
if show {
plot.show_html(path);
}
}
// ANCHOR_END: styled_sunburst

// ANCHOR: set_lower_or_upper_bound_on_axis
fn set_lower_or_upper_bound_on_axis(show: bool, file_name: &str) {
use std::fs::File;
Expand Down Expand Up @@ -1200,6 +1304,14 @@ fn main() {

grouped_donout_pie_charts(false, "grouped_donout_pie_charts");

// Treemap Charts
basic_treemap(false, "basic_treemap");
styled_treemap(false, "styled_treemap");

// Sunburst Charts
basic_sunburst(false, "basic_sunburst");
styled_sunburst(false, "styled_sunburst");

// Set Lower or Upper Bound on Axis
set_lower_or_upper_bound_on_axis(false, "set_lower_or_upper_bound_on_axis");
}
2 changes: 2 additions & 0 deletions plotly/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ pub enum PlotType {
DensityMapbox,
Table,
Pie,
Treemap,
Sunburst,
}

#[derive(Serialize, Clone, Debug)]
Expand Down
12 changes: 12 additions & 0 deletions plotly/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ pub struct LayoutFields {
sunburst_colorway: Option<Vec<Box<dyn Color>>>,
#[serde(rename = "extendsunburstcolors")]
extend_sunburst_colors: Option<bool>,
#[serde(rename = "treemapcolorway")]
treemap_colorway: Option<Vec<Box<dyn Color>>>,
#[serde(rename = "extendtreemapcolors")]
extend_treemap_colors: Option<bool>,
mapbox: Option<Mapbox>,
#[serde(rename = "updatemenus")]
update_menus: Option<Vec<UpdateMenu>>,
Expand Down Expand Up @@ -545,6 +549,8 @@ mod tests {
.extend_pie_colors(true)
.sunburst_colorway(vec!["#654654"])
.extend_sunburst_colors(false)
.treemap_colorway(vec!["#321321"])
.extend_treemap_colors(true)
.mapbox(Mapbox::new())
.update_menus(vec![UpdateMenu::new()])
.sliders(vec![Slider::new()]);
Expand Down Expand Up @@ -620,6 +626,8 @@ mod tests {
"extendpiecolors": true,
"sunburstcolorway": ["#654654"],
"extendsunburstcolors": false,
"treemapcolorway": ["#321321"],
"extendtreemapcolors": true,
"mapbox": {},
"updatemenus": [{}],
"sliders": [{}],
Expand Down Expand Up @@ -704,6 +712,8 @@ mod tests {
.extend_pie_colors(true)
.sunburst_colorway(vec!["#654654"])
.extend_sunburst_colors(false)
.treemap_colorway(vec!["#321321"])
.extend_treemap_colors(true)
.z_axis(Axis::new())
.scene(LayoutScene::new());

Expand Down Expand Up @@ -771,6 +781,8 @@ mod tests {
"extendpiecolors": true,
"sunburstcolorway": ["#654654"],
"extendsunburstcolors": false,
"treemapcolorway": ["#321321"],
"extendtreemapcolors": true,
"zaxis": {},
"scene": {}
});
Expand Down
5 changes: 3 additions & 2 deletions plotly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ pub use plot::{Plot, Trace, Traces};
// Also provide easy access to modules which contain additional trace-specific types
pub use traces::{
box_plot, contour, heat_map, histogram, image, mesh3d, sankey, scatter, scatter3d,
scatter_mapbox, surface,
scatter_mapbox, sunburst, surface, treemap,
};
// Bring the different trace types into the top-level scope
pub use traces::{
Bar, BoxPlot, Candlestick, Contour, DensityMapbox, HeatMap, Histogram, Image, Mesh3D, Ohlc,
Pie, Sankey, Scatter, Scatter3D, ScatterGeo, ScatterMapbox, ScatterPolar, Surface, Table,
Pie, Sankey, Scatter, Scatter3D, ScatterGeo, ScatterMapbox, ScatterPolar, Sunburst, Surface,
Table, Treemap,
};

pub trait Restyle: serde::Serialize {}
Expand Down
4 changes: 4 additions & 0 deletions plotly/src/traces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ pub mod scatter3d;
pub mod scatter_geo;
pub mod scatter_mapbox;
mod scatter_polar;
pub mod sunburst;
pub mod surface;
pub mod table;
pub mod treemap;

pub use bar::Bar;
pub use box_plot::BoxPlot;
Expand All @@ -36,7 +38,9 @@ pub use scatter3d::Scatter3D;
pub use scatter_geo::ScatterGeo;
pub use scatter_mapbox::ScatterMapbox;
pub use scatter_polar::ScatterPolar;
pub use sunburst::Sunburst;
pub use surface::Surface;
pub use table::Table;
pub use treemap::Treemap;

pub use self::image::Image;
Loading