Skip to main content

WaterfallArtist

Struct WaterfallArtist 

Source
pub struct WaterfallArtist {
    pub categories: Categories,
    pub values: Series,
    pub total_indices: Vec<usize>,
    pub increase_color: Color,
    pub decrease_color: Color,
    pub total_color: Color,
    pub connector_lines: bool,
    pub show_values: bool,
    pub bar_width: f64,
    pub label: Option<String>,
    pub color: Color,
    pub alpha: f64,
}
Expand description

A waterfall chart showing how an initial value is affected by a series of positive and negative changes.

Each bar represents an incremental change from the previous cumulative total. Bars that increase the total are colored with increase_color, bars that decrease it use decrease_color, and bars explicitly marked as totals (via total_indices) are drawn from zero using total_color.

Fields§

§categories: Categories

Category labels for each bar.

§values: Series

Change values: positive values increase the running total, negative values decrease it. For total bars, the value is the absolute total.

§total_indices: Vec<usize>

Indices of bars that represent totals (drawn from zero).

§increase_color: Color

Fill color for bars showing positive changes.

§decrease_color: Color

Fill color for bars showing negative changes.

§total_color: Color

Fill color for total bars.

§connector_lines: bool

When true, thin horizontal connector lines are drawn from each bar’s top to the next bar’s base.

§show_values: bool

When true, value labels are rendered on each bar.

§bar_width: f64

Bar width as a fraction of the category spacing (0.0, 1.0].

§label: Option<String>

Optional legend label.

§color: Color

Primary color used for legend swatch rendering.

§alpha: f64

Opacity from 0.0 (fully transparent) to 1.0 (fully opaque).

Implementations§

Source§

impl WaterfallArtist

Source

pub fn data_bounds(&self) -> (f64, f64, f64, f64)

Computes the data-space bounding box (xmin, xmax, ymin, ymax).

The x-axis spans from -0.5 to n - 0.5 so that bars are centered on integer positions. The y-axis covers the full range of the running cumulative sum (including zero) so that all bars are visible.

Source§

impl WaterfallArtist

Source

pub fn increase_color(&mut self, color: Color) -> &mut Self

Sets the color for bars representing positive (increasing) changes.

§Arguments
  • color - The Color to fill increase bars with.
Source

pub fn decrease_color(&mut self, color: Color) -> &mut Self

Sets the color for bars representing negative (decreasing) changes.

§Arguments
  • color - The Color to fill decrease bars with.
Source

pub fn total_color(&mut self, color: Color) -> &mut Self

Sets the color for total bars (bars drawn from zero).

§Arguments
  • color - The Color to fill total bars with.
Source

pub fn connector_lines(&mut self, enabled: bool) -> &mut Self

Enables or disables connector lines between consecutive bar tops.

When enabled (the default), thin horizontal lines are drawn from the end of each bar to the start of the next, visually connecting the running total across the chart.

§Arguments
  • enabled - true to draw connector lines, false to hide them.
Source

pub fn show_values(&mut self, enabled: bool) -> &mut Self

Enables or disables value labels displayed on each bar.

When enabled, each bar shows its change value (or total value for total bars) as a text label positioned at the bar’s top edge.

§Arguments
  • enabled - true to show value labels, false to hide them.
Source

pub fn bar_width(&mut self, width: f64) -> &mut Self

Sets the bar width as a fraction of the category spacing (0.0 to 1.0).

Smaller values produce thinner bars with more whitespace between them, while larger values make the bars wider. The value is clamped to the range [0.1, 1.0] so that bars are never invisibly thin nor overlap their neighbours.

§Arguments
  • width - The fraction of available category space each bar should occupy.
Source

pub fn label(&mut self, label: &str) -> &mut Self

Sets the legend label.

When a legend is displayed on the figure, this label will appear next to the color swatch for this waterfall series. Passing a new value overwrites any previously set label.

§Arguments
  • label - A string slice that will be stored as the legend entry.
Source

pub fn total(&mut self, indices: &[usize]) -> &mut Self

Marks the given bar indices as “total” bars.

Total bars are drawn from zero to the current cumulative sum, rather than showing the incremental change. Typically the first and/or last bar in a waterfall chart are marked as totals.

§Arguments
  • indices - A slice of zero-based category indices to treat as totals.
Source

pub fn alpha(&mut self, alpha: f64) -> &mut Self

Sets the opacity.

The value is clamped to the range [0.0, 1.0], where 0.0 is fully transparent and 1.0 is fully opaque.

§Arguments
  • alpha - The desired opacity level.
Source

pub fn cumulative_sums(&self) -> Vec<f64>

Computes the running cumulative sum from the change values.

For total bars, the cumulative sum equals the bar’s value directly. For non-total bars, each value is added to the running total.

Returns a vector of cumulative sums, one per category.

Source

pub fn bar_positions(&self) -> Vec<(f64, f64)>

Returns the bar base and top positions for each category.

For non-total bars: base is the previous cumulative sum, top is the current cumulative sum (base + change).

For total bars: base is 0, top is the cumulative sum value.

Returns a vector of (base, top) tuples.

Source

pub fn connector_positions(&self) -> Vec<(usize, f64)>

Returns the connector line positions as pairs of y-values.

Each connector runs from the top of bar i to the start of bar i+1. Returns a vector of (from_y, to_x_index) tuples where from_y is the y-value the connector line runs at.

Trait Implementations§

Source§

impl Clone for WaterfallArtist

Source§

fn clone(&self) -> WaterfallArtist

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WaterfallArtist

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.