plotlars/components/arrangement.rs
1use plotly::sankey::Arrangement as ArrangementPlotly;
2
3/// An enumeration representing node arrangement strategies for Sankey diagrams.
4///
5/// The `Arrangement` enum controls how nodes are positioned relative to each other:
6///
7/// * `Snap` — If value is `snap` (the default), the node arrangement is assisted by
8/// automatic snapping of elements to preserve space between nodes specified via `nodepad`.
9/// * `Perpendicular` — Nodes can only move along a line perpendicular to the primary flow.
10/// * `Freeform` — Nodes can freely move anywhere on the plane without automatic constraints.
11/// * `Fixed` — Nodes remain stationary at their specified positions and are not adjusted by the layout algorithm.
12///
13/// # Example
14///
15/// ```rust
16/// use plotlars::{Arrangement, SankeyDiagram, Orientation, Plot, Rgb, Text};
17/// use polars::prelude::*;
18///
19/// let dataset = df![
20/// "source" => &["A1", "A2", "A1", "B1", "B2", "B2"],
21/// "target" => &["B1", "B2", "B2", "C1", "C1", "C2"],
22/// "value" => &[8, 4, 2, 8, 4, 2],
23/// ].unwrap();
24///
25/// SankeyDiagram::builder()
26/// .data(&dataset)
27/// .sources("source")
28/// .targets("target")
29/// .values("value")
30/// .orientation(Orientation::Horizontal)
31/// .arrangement(Arrangement::Freeform)
32/// .node_colors(vec![
33/// Rgb(222, 235, 247),
34/// Rgb(198, 219, 239),
35/// Rgb(158, 202, 225),
36/// Rgb(107, 174, 214),
37/// Rgb( 66, 146, 198),
38/// Rgb( 33, 113, 181),
39/// ])
40/// .link_colors(vec![
41/// Rgb(222, 235, 247),
42/// Rgb(198, 219, 239),
43/// Rgb(158, 202, 225),
44/// Rgb(107, 174, 214),
45/// Rgb( 66, 146, 198),
46/// Rgb( 33, 113, 181),
47/// ])
48/// .build()
49/// .plot();
50/// ```
51///
52/// 
53pub enum Arrangement {
54 Snap,
55 Perpendicular,
56 Freeform,
57 Fixed,
58}
59
60impl Arrangement {
61 pub(crate) fn to_plotly(&self) -> ArrangementPlotly {
62 match self {
63 Arrangement::Snap => ArrangementPlotly::Snap,
64 Arrangement::Perpendicular => ArrangementPlotly::Perpendicular,
65 Arrangement::Freeform => ArrangementPlotly::Freeform,
66 Arrangement::Fixed => ArrangementPlotly::Fixed,
67 }
68 }
69}