Skip to content

Commit 1991c95

Browse files
committed
add Icicle, Indicator and Histogram2d examples
Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
1 parent 4a9ec18 commit 1991c95

10 files changed

Lines changed: 339 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1515
- [[#417](https://github.com/plotly/plotly.rs/issues/417)] Add `ScatterMap` (MapLibre `map` subplot) trace type — the modern counterpart to `ScatterMapbox`
1616
- [[#418](https://github.com/plotly/plotly.rs/issues/418)] Add native point clustering to `ScatterMap` via a `Cluster` option
1717
- [[#421](https://github.com/plotly/plotly.rs/pull/421)] Backfill trace attributes on trace types to bring them to parity with plotly.js 3.7
18-
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add `Indicator` trace type (number / delta / gauge KPI displays) with `Gauge`, `Delta`, `Number` config
19-
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add `Histogram2d` trace type (2D histogram heatmap) with `histfunc`/`histnorm`/`nbinsx`/`nbinsy`/`xbins`/`ybins`
20-
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add `Icicle` trace type (hierarchical icicle chart; sibling of `Treemap`/`Sunburst`)
21-
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add layout-level `uirevision` to preserve UI state (zoom/pan/selection) across re-renders (complements the trace-level `uirevision` added in #421)
18+
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add `Indicator`, `Histogram2d`, `Icicle` trace types
2219

2320
### Changed
2421

2522
- [[#406](https://github.com/plotly/plotly.rs/issues/406)] Upgrade bundled plotly.js from 3.0.1 to 3.6.0
2623
- [[#419](https://github.com/plotly/plotly.rs/issues/419)] Upgrade bundled plotly.js from 3.6.0 to 3.7.0
24+
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add layout-level `uirevision` to preserve UI state (zoom/pan/selection) across re-renders (complements the trace-level `uirevision` added in #421)
2725

2826
## [0.14.1] - 2026-02-15
2927

docs/book/src/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
- [Sankey Diagrams](./recipes/basic_charts/sankey_diagrams.md)
1919
- [Treemap Charts](./recipes/basic_charts/treemap_charts.md)
2020
- [Sunburst Charts](./recipes/basic_charts/sunburst_charts.md)
21+
- [Icicle Charts](./recipes/basic_charts/icicle_charts.md)
22+
- [Indicator Charts](./recipes/basic_charts/indicator_charts.md)
2123
- [Statistical Charts](./recipes/statistical_charts.md)
2224
- [Error Bars](./recipes/statistical_charts/error_bars.md)
2325
- [Box Plots](./recipes/statistical_charts/box_plots.md)
2426
- [Violin Plots](./recipes/statistical_charts/violin_plots.md)
2527
- [Histograms](./recipes/statistical_charts/histograms.md)
28+
- [2D Histograms](./recipes/statistical_charts/histogram2d.md)
2629
- [Scientific Charts](./recipes/scientific_charts.md)
2730
- [Contour Plots](./recipes/scientific_charts/contour_plots.md)
2831
- [Heatmaps](./recipes/scientific_charts/heatmaps.md)

docs/book/src/recipes/basic_charts.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Pie Charts | [![Pie Charts](./img/pie_charts.png)](./basic_charts/pie_charts.md)
1111
Sankey Diagrams | [![Sankey Diagrams](./img/basic_sankey.png)](./basic_charts/sankey_diagrams.md)
1212
Treemap Charts | [Treemap Charts](./basic_charts/treemap_charts.md)
1313
Sunburst Charts | [Sunburst Charts](./basic_charts/sunburst_charts.md)
14+
Icicle Charts | [Icicle Charts](./basic_charts/icicle_charts.md)
15+
Indicator Charts | [Indicator Charts](./basic_charts/indicator_charts.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Icicle Charts
2+
3+
The following imports have been used to produce the plots below:
4+
5+
```rust,no_run
6+
use plotly::color::NamedColor;
7+
use plotly::common::{Line, Orientation};
8+
use plotly::icicle::{BranchValues, Leaf, Marker, PathBar, Side, Tiling};
9+
use plotly::{Icicle, Plot};
10+
```
11+
12+
The `to_inline_html` method is used to produce the html plot displayed in this page.
13+
14+
## Basic Icicle
15+
```rust,no_run
16+
{{#include ../../../../../examples/basic_charts/src/main.rs:basic_icicle}}
17+
```
18+
19+
{{#include ../../../../../examples/basic_charts/output/inline_basic_icicle.html}}
20+
21+
22+
## Styled Icicle with Tiling and Path Bar
23+
```rust,no_run
24+
{{#include ../../../../../examples/basic_charts/src/main.rs:styled_icicle}}
25+
```
26+
27+
{{#include ../../../../../examples/basic_charts/output/inline_styled_icicle.html}}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Indicator Charts
2+
3+
The following imports have been used to produce the plots below:
4+
5+
```rust,no_run
6+
use plotly::color::NamedColor;
7+
use plotly::common::{Domain, Line};
8+
use plotly::layout::Layout;
9+
use plotly::traces::indicator::{
10+
Align, Delta, DeltaPosition, Direction, Gauge, GaugeAxis, GaugeBar, GaugeShape,
11+
IndicatorTitle, Mode, Number, Step, Threshold,
12+
};
13+
use plotly::{Indicator, Plot};
14+
```
15+
16+
The `to_inline_html` method is used to produce the html plot displayed in this page.
17+
18+
## Basic Indicator with Number and Delta
19+
```rust,no_run
20+
{{#include ../../../../../examples/basic_charts/src/main.rs:basic_indicator}}
21+
```
22+
23+
{{#include ../../../../../examples/basic_charts/output/inline_basic_indicator.html}}
24+
25+
26+
## Indicator Gauge
27+
```rust,no_run
28+
{{#include ../../../../../examples/basic_charts/src/main.rs:indicator_gauge}}
29+
```
30+
31+
{{#include ../../../../../examples/basic_charts/output/inline_indicator_gauge.html}}
30.6 KB
Loading

docs/book/src/recipes/statistical_charts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Error Bars |[![Scatter Plots](./img/error_bars.png)](./statistical_charts/error_
88
Box Plots | [![Line Charts](./img/box_plot.png)](./statistical_charts/box_plots.md)
99
Violin Plots | [![Violin Plots](./img/violin_plot.png)](./statistical_charts/violin_plots.md)
1010
Histograms | [![Scatter Plots](./img/overlaid_histogram.png)](./statistical_charts/histograms.md)
11+
2D Histograms | [![2D Histograms](./img/basic_histogram2d.png)](./statistical_charts/histogram2d.md)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 2D Histograms
2+
3+
The following imports have been used to produce the plots below:
4+
5+
```rust,no_run
6+
use plotly::common::{ColorScale, ColorScalePalette};
7+
use plotly::histogram::{Bins, HistFunc, HistNorm};
8+
use plotly::layout::{Axis, Layout};
9+
use plotly::{Histogram2d, Plot};
10+
```
11+
12+
The `to_inline_html` method is used to produce the html plot displayed in this page.
13+
14+
## Basic 2D Histogram
15+
```rust,no_run
16+
{{#include ../../../../../examples/statistical_charts/src/main.rs:basic_histogram2d}}
17+
```
18+
19+
{{#include ../../../../../examples/statistical_charts/output/inline_basic_histogram2d.html}}
20+
21+
22+
## Styled 2D Histogram
23+
```rust,no_run
24+
{{#include ../../../../../examples/statistical_charts/src/main.rs:styled_histogram2d}}
25+
```
26+
27+
{{#include ../../../../../examples/statistical_charts/output/inline_styled_histogram2d.html}}
28+
29+
30+
## 2D Histogram with Per-Sample Aggregation
31+
```rust,no_run
32+
{{#include ../../../../../examples/statistical_charts/src/main.rs:histogram2d_aggregation}}
33+
```
34+
35+
{{#include ../../../../../examples/statistical_charts/output/inline_histogram2d_aggregation.html}}

examples/basic_charts/src/main.rs

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ use plotly::{
77
ColorScale, ColorScalePalette, DashType, Domain, Fill, Font, HoverInfo, Line, LineShape,
88
Marker, Mode, Orientation, Pattern, PatternShape,
99
},
10+
icicle::{
11+
BranchValues as IcicleBranchValues, Leaf as IcicleLeaf, Marker as IcicleMarker,
12+
PathBar as IciclePathBar, Side as IcicleSide, Tiling as IcicleTiling,
13+
},
1014
layout::{
1115
AngularAxis, Annotation, Axis, AxisRange, BarMode, CategoryOrder, Layout, LayoutGrid,
1216
LayoutPolar, Legend, PolarAxisAttributes, PolarAxisTicks, PolarDirection, RadialAxis,
1317
TicksDirection, TraceOrder,
1418
},
1519
sankey::{Line as SankeyLine, Link, Node},
1620
sunburst::{InsideTextOrientation, Leaf},
21+
traces::indicator::{
22+
Align, Delta, DeltaPosition, Direction, Gauge, GaugeAxis, GaugeBar, GaugeShape,
23+
IndicatorTitle, Mode as IndicatorMode, Number, Step, Threshold,
24+
},
1725
traces::table::{
1826
Align as TableAlign, Cells, Fill as TableFill, Font as TableFont, Header, Line as TableLine,
1927
},
2028
treemap::{BranchValues, Marker as TreemapMarker, Packing, PathBar, Side, Tiling},
21-
Bar, Pie, Plot, Sankey, Scatter, ScatterPolar, Sunburst, Table, Treemap,
29+
Bar, Icicle, Indicator, Pie, Plot, Sankey, Scatter, ScatterPolar, Sunburst, Table, Treemap,
2230
};
2331
use plotly_utils::write_example_to_html;
2432
use rand_distr::{Distribution, Normal, Uniform};
@@ -1147,6 +1155,137 @@ fn styled_sunburst(show: bool, file_name: &str) {
11471155
}
11481156
// ANCHOR_END: styled_sunburst
11491157

1158+
// Icicle Charts
1159+
// ANCHOR: basic_icicle
1160+
fn basic_icicle(show: bool, file_name: &str) {
1161+
let labels = vec![
1162+
"Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura",
1163+
];
1164+
let parents = vec![
1165+
"", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve",
1166+
];
1167+
let trace = Icicle::new(labels, parents)
1168+
.values(vec![10.0, 14.0, 12.0, 10.0, 2.0, 6.0, 6.0, 4.0, 4.0])
1169+
.text_info("label+value");
1170+
1171+
let mut plot = Plot::new();
1172+
plot.add_trace(trace);
1173+
1174+
let path = write_example_to_html(&plot, file_name);
1175+
if show {
1176+
plot.show_html(path);
1177+
}
1178+
}
1179+
// ANCHOR_END: basic_icicle
1180+
1181+
// ANCHOR: styled_icicle
1182+
fn styled_icicle(show: bool, file_name: &str) {
1183+
let labels = vec![
1184+
"Total",
1185+
"Tech",
1186+
"Health",
1187+
"Finance",
1188+
"Software",
1189+
"Hardware",
1190+
"Pharma",
1191+
"Devices",
1192+
"Banking",
1193+
"Insurance",
1194+
];
1195+
let parents = vec![
1196+
"", "Total", "Total", "Total", "Tech", "Tech", "Health", "Health", "Finance", "Finance",
1197+
];
1198+
let trace = Icicle::new(labels, parents)
1199+
.values(vec![0.0, 0.0, 0.0, 0.0, 40.0, 30.0, 25.0, 15.0, 20.0, 18.0])
1200+
.branch_values(IcicleBranchValues::Remainder)
1201+
.marker(IcicleMarker::new().line(Line::new().width(1.0).color(NamedColor::White)))
1202+
.tiling(
1203+
IcicleTiling::new()
1204+
.orientation(Orientation::Horizontal)
1205+
.pad(2.0),
1206+
)
1207+
.path_bar(IciclePathBar::new().visible(true).side(IcicleSide::Top))
1208+
.leaf(IcicleLeaf::new().opacity(0.7))
1209+
.text_info("label+value+percent parent");
1210+
1211+
let mut plot = Plot::new();
1212+
plot.add_trace(trace);
1213+
1214+
let path = write_example_to_html(&plot, file_name);
1215+
if show {
1216+
plot.show_html(path);
1217+
}
1218+
}
1219+
// ANCHOR_END: styled_icicle
1220+
1221+
// Indicator Charts
1222+
// ANCHOR: basic_indicator
1223+
fn basic_indicator(show: bool, file_name: &str) {
1224+
let trace = Indicator::new(120.0)
1225+
.mode(IndicatorMode::NumberAndDelta)
1226+
.align(Align::Center)
1227+
.title(IndicatorTitle::new().text("Revenue"))
1228+
.number(Number::new().prefix("$").value_format(".2f"))
1229+
.delta(
1230+
Delta::new()
1231+
.reference(100.0)
1232+
.relative(true)
1233+
.position(DeltaPosition::Top)
1234+
.increasing(Direction::new().color(NamedColor::Green).symbol("▲"))
1235+
.decreasing(Direction::new().color(NamedColor::Red).symbol("▼")),
1236+
)
1237+
.domain(Domain::new());
1238+
1239+
let layout = Layout::new().title("Basic Indicator");
1240+
let mut plot = Plot::new();
1241+
plot.set_layout(layout);
1242+
plot.add_trace(trace);
1243+
1244+
let path = write_example_to_html(&plot, file_name);
1245+
if show {
1246+
plot.show_html(path);
1247+
}
1248+
}
1249+
// ANCHOR_END: basic_indicator
1250+
1251+
// ANCHOR: indicator_gauge
1252+
fn indicator_gauge(show: bool, file_name: &str) {
1253+
let trace = Indicator::new(270.0)
1254+
.mode(IndicatorMode::Gauge)
1255+
.title(IndicatorTitle::new().text("Speed"))
1256+
.gauge(
1257+
Gauge::new()
1258+
.shape(GaugeShape::Angular)
1259+
.axis(GaugeAxis::new().range([0.0, 500.0]))
1260+
.bar(GaugeBar::new().color("darkblue").thickness(0.75))
1261+
.background_color(NamedColor::White)
1262+
.border_color(NamedColor::Gray)
1263+
.border_width(1.0)
1264+
.steps(vec![
1265+
Step::new().range([0.0, 250.0]).color("lightgray"),
1266+
Step::new().range([250.0, 400.0]).color("gray"),
1267+
])
1268+
.threshold(
1269+
Threshold::new()
1270+
.line(Line::new().color(NamedColor::Red).width(4.0))
1271+
.thickness(0.75)
1272+
.value(490.0),
1273+
),
1274+
)
1275+
.domain(Domain::new());
1276+
1277+
let layout = Layout::new().title("Indicator Gauge");
1278+
let mut plot = Plot::new();
1279+
plot.set_layout(layout);
1280+
plot.add_trace(trace);
1281+
1282+
let path = write_example_to_html(&plot, file_name);
1283+
if show {
1284+
plot.show_html(path);
1285+
}
1286+
}
1287+
// ANCHOR_END: indicator_gauge
1288+
11501289
// ANCHOR: set_lower_or_upper_bound_on_axis
11511290
fn set_lower_or_upper_bound_on_axis(show: bool, file_name: &str) {
11521291
use std::fs::File;
@@ -1312,6 +1451,14 @@ fn main() {
13121451
basic_sunburst(false, "basic_sunburst");
13131452
styled_sunburst(false, "styled_sunburst");
13141453

1454+
// Icicle Charts
1455+
basic_icicle(false, "basic_icicle");
1456+
styled_icicle(false, "styled_icicle");
1457+
1458+
// Indicator Charts
1459+
basic_indicator(false, "basic_indicator");
1460+
indicator_gauge(false, "indicator_gauge");
1461+
13151462
// Set Lower or Upper Bound on Axis
13161463
set_lower_or_upper_bound_on_axis(false, "set_lower_or_upper_bound_on_axis");
13171464
}

0 commit comments

Comments
 (0)