fix sankey trace x/y node fields · plotly/plotly.rs@a168028 · GitHub
Skip to content

Commit a168028

Browse files
committed
fix sankey trace x/y node fields
Closes #308 Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
1 parent 8ee31bc commit a168028

3 files changed

Lines changed: 60 additions & 115 deletions

File tree

‎docs/book/src/recipes/basic_charts/sankey_diagrams.md‎

Lines changed: 9 additions & 107 deletions

‎examples/basic_charts/src/main.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,44 @@ fn basic_sankey_diagram(show: bool, file_name: &str) {
810810
}
811811
// ANCHOR_END: basic_sankey_diagram
812812

813+
// ANCHOR: custom_node_sankey_diagram
814+
fn custom_node_sankey_diagram(show: bool, file_name: &str) {
815+
// https://plotly.com/javascript/sankey-diagram/#basic-sankey-diagram
816+
let trace = Sankey::new()
817+
.orientation(Orientation::Horizontal)
818+
.arrangement(plotly::sankey::Arrangement::Snap)
819+
.node(
820+
Node::new()
821+
.pad(15)
822+
.thickness(30)
823+
.line(SankeyLine::new().color(NamedColor::Black).width(0.5))
824+
.label(vec!["A", "B", "C", "D", "E", "F"])
825+
.x(vec![0.2, 0.1, 0.5, 0.7, 0.3, 0.5])
826+
.y(vec![0.2, 0.1, 0.5, 0.7, 0.3, 0.5])
827+
.pad(20),
828+
)
829+
.link(
830+
Link::new()
831+
.source(vec![0, 0, 1, 2, 5, 4, 3, 5])
832+
.target(vec![5, 3, 4, 3, 0, 2, 2, 3])
833+
.value(vec![1, 2, 1, 1, 1, 1, 1, 2]),
834+
);
835+
836+
let layout = Layout::new()
837+
.title("Define Node Position")
838+
.font(Font::new().size(10));
839+
840+
let mut plot = Plot::new();
841+
plot.add_trace(trace);
842+
plot.set_layout(layout);
843+
844+
let path = write_example_to_html(&plot, file_name);
845+
if show {
846+
plot.show_html(path);
847+
}
848+
}
849+
// ANCHOR_END: custom_node_sankey_diagram
850+
813851
// ANCHOR: table_chart
814852
fn table_chart(show: bool, file_name: &str) {
815853
let trace = Table::new(
@@ -1006,6 +1044,7 @@ fn main() {
10061044

10071045
// Sankey Diagrams
10081046
basic_sankey_diagram(false, "basic_sankey_diagram");
1047+
custom_node_sankey_diagram(false, "custom_node_sankey_diagram");
10091048

10101049
// Pie Charts
10111050
basic_pie_chart(false, "basic_pie_chart");

‎plotly/src/traces/sankey.rs‎

Lines changed: 12 additions & 8 deletions

0 commit comments

Comments
 (0)