1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Bar chart builder methods.
//!
//! Provides a fluent builder API for configuring [`BarArtist`] instances.
//! Each method returns `&mut Self`, allowing calls to be chained together
//! for concise, readable chart construction.
use crate::artist::BarArtist;
use crate::primitives::Color;
impl BarArtist {
/// Sets the bar color.
///
/// Applies the given [`Color`] to every bar rendered by this artist.
///
/// # Arguments
///
/// * `color` - The [`Color`] to fill each bar with.
pub fn color(&mut self, color: Color) -> &mut Self {
self.color = color;
self
}
/// Sets the legend label.
///
/// When a legend is displayed on the figure, this label will appear
/// next to the color swatch for this bar series. Passing a new value
/// overwrites any previously set label.
///
/// # Arguments
///
/// * `label` - A string slice that will be stored as the legend entry.
pub fn label(&mut self, label: &str) -> &mut Self {
self.label = Some(label.to_string());
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.
pub fn alpha(&mut self, alpha: f64) -> &mut Self {
self.alpha = alpha.clamp(0.0, 1.0);
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.
pub fn bar_width(&mut self, width: f64) -> &mut Self {
self.bar_width = width.clamp(0.1, 1.0);
self
}
/// Sets the bottom offset for each bar (for stacking).
///
/// When stacking multiple bar series, set `bottom` for each subsequent
/// series to the cumulative heights of the series below it. Each bar
/// then starts at `bottom[i]` instead of `0.0` and extends to
/// `bottom[i] + height[i]`.
///
/// # Arguments
///
/// * `bottom` - A vector of base offsets, one per bar. Must have the same
/// length as the heights vector.
///
/// # Example
///
/// ```ignore
/// // Stack series B on top of series A:
/// ax.bar(cats, &heights_a)?.label("A");
/// ax.bar(cats, &heights_b)?.bottom(heights_a.clone()).label("B");
/// ```
pub fn bottom(&mut self, bottom: Vec<f64>) -> &mut Self {
self.bottom = Some(bottom);
self
}
/// Sets the per-bar position offset for grouped (side-by-side) bars.
///
/// Each bar's category center is shifted by `offset[i]` units along the
/// category axis. This is useful for placing multiple bar series next to
/// each other within the same categories.
///
/// For most grouped-bar use cases, prefer [`Axes::bar_group`] which
/// computes offsets automatically.
///
/// # Arguments
///
/// * `offset` - A vector of position offsets, one per bar.
pub fn offset(&mut self, offset: Vec<f64>) -> &mut Self {
self.offset = Some(offset);
self
}
}