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: CategoriesCategory labels for each bar.
values: SeriesChange 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: ColorFill color for bars showing positive changes.
decrease_color: ColorFill color for bars showing negative changes.
total_color: ColorFill color for total bars.
connector_lines: boolWhen true, thin horizontal connector lines are drawn from each bar’s
top to the next bar’s base.
show_values: boolWhen true, value labels are rendered on each bar.
bar_width: f64Bar width as a fraction of the category spacing (0.0, 1.0].
label: Option<String>Optional legend label.
color: ColorPrimary color used for legend swatch rendering.
alpha: f64Opacity from 0.0 (fully transparent) to 1.0 (fully opaque).
Implementations§
Source§impl WaterfallArtist
impl WaterfallArtist
Sourcepub fn data_bounds(&self) -> (f64, f64, f64, f64)
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
impl WaterfallArtist
Sourcepub fn increase_color(&mut self, color: Color) -> &mut Self
pub fn increase_color(&mut self, color: Color) -> &mut Self
Sourcepub fn decrease_color(&mut self, color: Color) -> &mut Self
pub fn decrease_color(&mut self, color: Color) -> &mut Self
Sourcepub fn total_color(&mut self, color: Color) -> &mut Self
pub fn total_color(&mut self, color: Color) -> &mut Self
Sourcepub fn connector_lines(&mut self, enabled: bool) -> &mut Self
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-trueto draw connector lines,falseto hide them.
Sourcepub fn show_values(&mut self, enabled: bool) -> &mut Self
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-trueto show value labels,falseto hide them.
Sourcepub fn bar_width(&mut self, width: f64) -> &mut Self
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.
Sourcepub fn label(&mut self, label: &str) -> &mut Self
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.
Sourcepub fn total(&mut self, indices: &[usize]) -> &mut Self
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.
Sourcepub fn alpha(&mut self, alpha: f64) -> &mut Self
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.
Sourcepub fn cumulative_sums(&self) -> Vec<f64>
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.
Sourcepub fn bar_positions(&self) -> Vec<(f64, f64)>
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.
Sourcepub fn connector_positions(&self) -> Vec<(usize, f64)>
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
impl Clone for WaterfallArtist
Source§fn clone(&self) -> WaterfallArtist
fn clone(&self) -> WaterfallArtist
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more