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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! Stacking preview — stacked bars and stacked areas.
use *;
use component_doc;
use crate;
use crate;
/// Stack series when each category total is meaningful and segments show contribution.
///
/// **Decision guide:** Same `stack_group` id → stacked. Negative values → `StackOffset::Diverging`
/// (bar default). Share of whole → `StackOffset::Expand`. Unsure about layer order → try
/// `StackOrder::Ascending`.
///
/// # When to use
///
/// Assign the same `stack_group` on multiple series to stack segments per
/// category. Bar stacks default to [`StackOffset::Diverging`] for signed data;
/// lines and areas default to [`StackOffset::None`].
///
/// # Usage
///
/// 1. Assign the same `stack_group` string on series that should stack per category.
/// 2. Set `stack_offset` on any member — `Diverging` for signed bars, `Expand` for 100% stacks.
/// 3. Set `stack_order` when layer sequence at the baseline matters.
/// 4. Use [`ChartStacking`] preview variants to compare bar vs area stacking side by side.
///
/// # Best Practices
///
/// ## Do's
///
/// * Include zero in the value axis domain for diverging stacks with negatives.
/// * Use `stack_order: Ascending` when the smallest segment should anchor the baseline.
/// * Link to `area-chart` percent stacked example for normalized area stacks.
///
/// ## Don'ts
///
/// * Do not stack unrelated series — they must share categories and a stack group id.
/// * Do not use expand offset when absolute totals must remain readable.
///
/// # Examples
///
/// ## Stacked bar chart (diverging default)
/// Three stacked segments per month including signed adjustments. Bar stacks default to
/// diverging offset so negative segments mirror below the baseline.
/// <!-- preview -->
/// ```rust,ignore
/// use crate::ChartStacking;
/// use crate::preview::fixtures::{full_grid, revenue_y_axis, stacked_bar_series, stacked_bar_x_axis};
/// view! {
/// <div data-testid="chart-stacking-preview">
/// <ChartStacking
/// variant=ChartStackingVariant::StackedBar
/// series=stacked_bar_series()
/// x_axis=vec![stacked_bar_x_axis()]
/// y_axis=vec![revenue_y_axis()]
/// grid=full_grid()
/// width=560.0
/// height=320.0
/// />
/// </div>
/// }
/// ```
///
/// ## Stacked area chart
/// Multiple filled series sharing a stack group. Compare with `area-chart-percent-preview`
/// when you need `stack_offset: Expand` normalization.
/// <!-- preview -->
/// ```rust,ignore
/// use crate::ChartStacking;
/// use crate::preview::fixtures::{full_grid, month_categories, quarter_x_axis, revenue_y_axis, stacked_area_series};
/// view! {
/// <div data-testid="chart-stacking-area-preview">
/// <ChartStacking
/// variant=ChartStackingVariant::StackedArea
/// series=stacked_area_series()
/// x_axis=vec![{
/// let mut a = quarter_x_axis();
/// a.data = Some(month_categories());
/// a
/// }]
/// y_axis=vec![revenue_y_axis()]
/// grid=full_grid()
/// width=560.0
/// height=320.0
/// />
/// </div>
/// }
/// ```
]
series: ,
/// X-axis definitions.
x_axis: ,
/// Y-axis definitions.
y_axis: ,
/// Background grid configuration.
grid: crateGridConfig,
/// Chart width in pixels.
width: f64,
/// Chart height in pixels.
height: f64,
/// Optional CSS class on the root element.
class: ,
)
/// Stacking preview variants.