Skip to main content

SankeyChart

Struct SankeyChart 

Source
pub struct SankeyChart<T: 'static> { /* private fields */ }
Expand description

A Sankey diagram, layout modeled after d3-sankey.

Links reference nodes by their index in the node list; map string ids to indices before constructing.

Implementations§

Source§

impl<T> SankeyChart<T>

Source

pub fn new<I, L>(nodes: I, links: L) -> Self
where I: IntoIterator<Item = T>, L: IntoIterator<Item = SankeyLink>,

Create a chart from nodes and links; links reference nodes by their index in nodes (map string ids to indices before constructing).

Source

pub fn node_width(self, node_width: f32) -> Self

Set the node rectangle width. Defaults to 10.

Source

pub fn node_padding(self, node_padding: f32) -> Self

Set the vertical gap between nodes in a column. Defaults to 16.

Source

pub fn node_align(self, align: SankeyAlign) -> Self

Set the node alignment. Defaults to SankeyAlign::Justify.

Source

pub fn iterations(self, iterations: usize) -> Self

Set the number of relaxation passes. Defaults to 6.

Source

pub fn value_scale(self, value_scale: SankeyValueScale) -> Self

Set how flow values map to node heights.

Defaults to SankeyValueScale::Linear. Use SankeyValueScale::Sqrt to keep a dominant flow from dwarfing the small ones without pre-transforming the data; labels still receive the raw values.

Source

pub fn node_corner_radius(self, radius: impl Into<Pixels>) -> Self

Set the corner radius of the node rectangles. Defaults to 0.

Source

pub fn node_color<H>(self, color: impl Fn(&T) -> H + 'static) -> Self
where H: Into<Hsla> + 'static,

Set the color of each node.

Defaults to cycling the theme chart palette by node index.

Source

pub fn node_label(self, label: impl Fn(&T) -> SharedString + 'static) -> Self

Set the name label of each node, drawn in muted foreground. No name label is drawn unless set.

Source

pub fn value_label( self, label: impl Fn(&T, f64) -> SharedString + 'static, ) -> Self

Set the value label of each node, drawn above the name label. No value label is drawn unless set.

The closure receives the datum and the node’s raw computed throughput (max of incoming and outgoing flow, in unscaled units).

Source

pub fn labels( self, labels: impl Fn(&T, f64) -> Vec<SankeyLabel> + 'static, ) -> Self

Set fully custom node labels, one SankeyLabel per line, top to bottom. Takes precedence over node_label/value_label when set; unset by default.

The closure receives the datum and the node’s raw computed throughput (max of incoming and outgoing flow, in unscaled units).

Set the opacity of the link ribbons. Defaults to 0.3.

Set the minimum ribbon thickness, so tiny flows stay visible. Defaults to 1.

Source

pub fn label_gap(self, gap: f32) -> Self

Set the gap between a node and its labels. Defaults to 6.

Trait Implementations§

Source§

impl<T: 'static> Element for SankeyChart<T>

Source§

type RequestLayoutState = ()

The type of state returned from Element::request_layout. A mutable reference to this state is subsequently provided to Element::prepaint and Element::paint.
Source§

type PrepaintState = (Option<Hitbox>, Vec<AnyElement>, Option<AnyElement>)

The type of state returned from Element::prepaint. A mutable reference to this state is subsequently provided to Element::paint.
Source§

fn id(&self) -> Option<ElementId>

If this element has a unique identifier, return it here. This is used to track elements across frames, and will cause a GlobalElementId to be passed to the request_layout, prepaint, and paint methods. Read more
Source§

fn source_location(&self) -> Option<&'static Location<'static>>

Source location where this element was constructed, used to disambiguate elements in the inspector and navigate to their source code.
Source§

fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)

Before an element can be painted, we need to know where it’s going to be and how big it is. Use this method to request a layout from Taffy and initialize the element’s state.
Source§

fn prepaint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut Self::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> Self::PrepaintState

After laying out an element, we need to commit its bounds to the current frame for hitbox purposes. The state argument is the same state that was returned from Element::request_layout().
Source§

fn paint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut Self::RequestLayoutState, prepaint: &mut Self::PrepaintState, window: &mut Window, cx: &mut App, )

Once layout has been completed, this method will be called to paint the element to the screen. The state argument is the same state that was returned from Element::request_layout().
Source§

fn a11y_role(&self) -> Option<Role>

Returns the accessible role for this element, if any. Elements that return None are not included in the accessibility tree. Read more
Source§

fn write_a11y_info(&self, _node: &mut Node)

Write accessibility properties to the given node. Called only when a11y_role() returns Some. Read more
Source§

fn a11y_synthetic_children( &mut self, _prepaint: &mut Self::PrepaintState, _builder: &mut A11ySubtreeBuilder<'_>, )

Add synthetic child nodes to an Element that has an .id() and a .role(). Read more
Source§

fn into_any(self) -> AnyElement

Convert this element into a dynamically-typed AnyElement.
Source§

impl<T: 'static> IntoElement for SankeyChart<T>

Source§

type Element = SankeyChart<T>

The specific type of element into which the implementing type is converted. Useful for converting other types into elements automatically, like Strings
Source§

fn into_element(self) -> Self::Element

Convert self into a type that implements Element.
Source§

fn into_any_element(self) -> AnyElement

Convert self into a dynamically-typed AnyElement.
Source§

impl<T> Plot for SankeyChart<T>

Source§

fn paint(&mut self, bounds: Bounds<Pixels>, window: &mut Window, cx: &mut App)

Source§

fn prepaint( &mut self, _bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut App, ) -> Vec<AnyElement>

Lay out and place the child elements this plot hosts (e.g. element labels). Read more
Source§

fn id(&self) -> Option<ElementId>

A stable element id that enables interactive tooltip support for this plot. Read more
Source§

fn tooltip_state( &self, _position: Point<Pixels>, _bounds: Bounds<Pixels>, _cx: &App, ) -> Option<TooltipState>

Map the cursor to the tooltip state to display. Read more
Source§

fn tooltip( &self, _state: &TooltipState, _cursor: Point<Pixels>, _bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut App, ) -> Option<AnyElement>

Render the tooltip overlay for the active TooltipState. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SankeyChart<T>

§

impl<T> !Send for SankeyChart<T>

§

impl<T> !Sync for SankeyChart<T>

§

impl<T> !UnwindSafe for SankeyChart<T>

§

impl<T> Freeze for SankeyChart<T>
where Vec<T>: Freeze, Option<Rc<dyn Fn(&T) -> Hsla>>: Freeze, Option<Rc<dyn Fn(&T) -> SharedString>>: Freeze, Option<Rc<dyn Fn(&T, f64) -> SharedString>>: Freeze, Option<Rc<dyn Fn(&T, f64) -> Vec<SankeyLabel>>>: Freeze,

§

impl<T> Unpin for SankeyChart<T>
where Vec<T>: Unpin, Option<Rc<dyn Fn(&T) -> Hsla>>: Unpin, Option<Rc<dyn Fn(&T) -> SharedString>>: Unpin, Option<Rc<dyn Fn(&T, f64) -> SharedString>>: Unpin, Option<Rc<dyn Fn(&T, f64) -> Vec<SankeyLabel>>>: Unpin,

§

impl<T> UnsafeUnpin for SankeyChart<T>

Blanket Implementations§

Source§

impl<E> AnimationExt for E
where E: IntoElement + 'static,

Source§

fn with_animation( self, id: impl Into<ElementId>, animation: Animation, animator: impl Fn(Self, f32) -> Self + 'static, ) -> AnimationElement<Self>
where Self: Sized,

Render this component or element with an animation
Source§

fn with_animations( self, id: impl Into<ElementId>, animations: Vec<Animation>, animator: impl Fn(Self, usize, f32) -> Self + 'static, ) -> AnimationElement<Self>
where Self: Sized,

Render this component or element with a chain of animations
Source§

fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
where Self: Sized, T: SpringTarget, <T as SpringTarget>::Output: 'static,

Renders this component or element at the value produced by a spring. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> FluentBuilder for T
where T: IntoElement,

Source§

fn map<U>(self, f: impl FnOnce(Self) -> U) -> U
where Self: Sized,

Imperatively modify self with the given closure.
Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_some<T>( self, option: Option<T>, then: impl FnOnce(Self, T) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is Some.
Source§

fn when_none<T>( self, option: &Option<T>, then: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is None.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more