pub struct SankeyDiagram { /* private fields */ }Expand description
A structure representing a Sankey diagram.
The SankeyDiagram struct enables the creation of Sankey diagrams, which visualize flows
between discrete nodes with link widths proportional to the magnitude of the flow. It
offers extensive configuration options for flow orientation, node arrangement, spacing,
thickness, and coloring, as well as axis and title customization. Users can specify a
single uniform color or per-item colors for both nodes and links, adjust padding between
nodes, set node thickness, and supply custom titles and axis labels to produce clear,
publication-quality flow visualizations.
§Arguments
data– A reference to theDataFramecontaining the data to be plotted.sources– A string slice naming the column indatathat contains the source node for each flow.targets– A string slice naming the column indatathat contains the target node for each flow.values– A string slice naming the column indatathat contains the numeric value of each flow.orientation– An optionalOrientationenum to set the overall direction of the diagram (e.g.Orientation::HorizontalorOrientation::Vertical).arrangement– An optionalArrangementenum to choose the node-layout algorithm (e.g.Arrangement::Snap,Arrangement::Perpendicular, etc.).pad– An optionalusizespecifying the padding (in pixels) between adjacent nodes.thickness– An optionalusizedefining the uniform thickness (in pixels) of all nodes.node_color– An optionalRgbvalue to apply a single uniform color to every node.node_colors– An optionalVec<Rgb>supplying individual colors for each node in order.link_color– An optionalRgbvalue to apply a single uniform color to every link.link_colors– An optionalVec<Rgb>supplying individual colors for each link in order.plot_title– An optionalTextstruct for setting the overall title of the plot.
§Example
use polars::prelude::*;
use plotlars::{Arrangement, SankeyDiagram, Orientation, Plot, Rgb, Text};
let dataset = df![
"source" => ["A1", "A2", "A1", "B1", "B2", "B2"],
"target" => &["B1", "B2", "B2", "C1", "C1", "C2"],
"value" => &[8, 4, 2, 8, 4, 2],
]
.unwrap();
SankeyDiagram::builder()
.data(&dataset)
.sources("source")
.targets("target")
.values("value")
.orientation(Orientation::Horizontal)
.arrangement(Arrangement::Freeform)
.node_colors(vec![
Rgb(222, 235, 247),
Rgb(198, 219, 239),
Rgb(158, 202, 225),
Rgb(107, 174, 214),
Rgb( 66, 146, 198),
Rgb( 33, 113, 181),
])
.link_colors(vec![
Rgb(222, 235, 247),
Rgb(198, 219, 239),
Rgb(158, 202, 225),
Rgb(107, 174, 214),
Rgb( 66, 146, 198),
Rgb( 33, 113, 181),
])
.pad(20)
.thickness(30)
.plot_title(
Text::from("Sankey Diagram")
.font("Arial")
.size(18)
)
.build()
.plot();
Implementations§
Source§impl SankeyDiagram
impl SankeyDiagram
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4>() -> SankeyDiagramBuilder<'f1, 'f2, 'f3, 'f4>
pub fn builder<'f1, 'f2, 'f3, 'f4>() -> SankeyDiagramBuilder<'f1, 'f2, 'f3, 'f4>
Examples found in repository?
examples/sankeydiagram.rs (line 13)
5fn main() {
6 let dataset = df![
7 "source" => ["A1", "A2", "A1", "B1", "B2", "B2"],
8 "target" => &["B1", "B2", "B2", "C1", "C1", "C2"],
9 "value" => &[8, 4, 2, 8, 4, 2],
10 ]
11 .unwrap();
12
13 SankeyDiagram::builder()
14 .data(&dataset)
15 .sources("source")
16 .targets("target")
17 .values("value")
18 .orientation(Orientation::Horizontal)
19 .arrangement(Arrangement::Freeform)
20 .node_colors(vec![
21 Rgb(222, 235, 247),
22 Rgb(198, 219, 239),
23 Rgb(158, 202, 225),
24 Rgb(107, 174, 214),
25 Rgb(66, 146, 198),
26 Rgb(33, 113, 181),
27 ])
28 .link_colors(vec![
29 Rgb(222, 235, 247),
30 Rgb(198, 219, 239),
31 Rgb(158, 202, 225),
32 Rgb(107, 174, 214),
33 Rgb(66, 146, 198),
34 Rgb(33, 113, 181),
35 ])
36 .pad(20)
37 .thickness(30)
38 .plot_title(Text::from("Sankey Diagram").font("Arial").size(18))
39 .build()
40 .plot();
41}Trait Implementations§
Source§impl Clone for SankeyDiagram
impl Clone for SankeyDiagram
Source§fn clone(&self) -> SankeyDiagram
fn clone(&self) -> SankeyDiagram
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SankeyDiagram
impl !RefUnwindSafe for SankeyDiagram
impl !Send for SankeyDiagram
impl !Sync for SankeyDiagram
impl Unpin for SankeyDiagram
impl !UnwindSafe for SankeyDiagram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more