ravenrs_sheet/model/features/
pivot.rs1use super::{CellRef, RangeRef};
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
8pub enum PivotLayout {
9 #[default]
11 Compact,
12 Outline,
14 Tabular,
16}
17
18#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
19pub enum PivotSort {
20 #[default]
21 Asc,
22 Desc,
23 None,
25}
26
27#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
29pub enum PivotDateGroup {
30 #[default]
31 None,
32 Years,
33 Quarters,
34 Months,
35 Days,
36}
37
38#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
40#[serde(default)]
41pub struct PivotField {
42 pub source_col: String,
44 pub sort: PivotSort,
45 pub date_group: PivotDateGroup,
46 pub collapsed_items: Vec<String>,
48}
49
50#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
52pub enum PivotFunc {
53 #[default]
54 Sum,
55 Count,
56 Average,
57 Max,
58 Min,
59 Product,
60 CountNumbers,
61 StdDev,
62 StdDevP,
63 Var,
64 VarP,
65}
66
67#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
69pub enum PivotShowAs {
70 #[default]
71 Normal,
72 PercentOfGrandTotal,
73 PercentOfColumnTotal,
74 PercentOfRowTotal,
75 RunningTotal,
77 Rank,
79}
80
81#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
83#[serde(default)]
84pub struct PivotValue {
85 pub source_col: String,
86 pub func: PivotFunc,
87 pub name: String,
89 pub show_as: PivotShowAs,
90 pub number_format: Option<String>,
91}
92
93#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
95#[serde(default)]
96pub struct PivotFilter {
97 pub source_col: String,
98 pub selected: Option<Vec<String>>,
100}
101
102#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
105#[serde(default)]
106pub struct PivotTable {
107 pub id: u32,
108 pub name: String,
109 pub source: String,
111 pub anchor: CellRef,
113 pub rows: Vec<PivotField>,
114 pub columns: Vec<PivotField>,
115 pub values: Vec<PivotValue>,
116 pub filters: Vec<PivotFilter>,
117 pub layout: PivotLayout,
118 pub enable_show_details: bool,
121 pub grand_totals_rows: bool,
123 pub grand_totals_cols: bool,
125 pub subtotals: bool,
126 pub subtotals_top: bool,
128 pub style: String,
129 pub show_headers: bool,
130 pub last_range: Option<RangeRef>,
132 pub calculated_fields: Vec<PivotCalcField>,
134 pub values_on_rows: bool,
137 pub values_position: Option<usize>,
140}
141
142#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
145#[serde(default)]
146pub struct PivotCalcField {
147 pub name: String,
148 pub formula: String,
150}
151
152impl Default for PivotTable {
153 fn default() -> Self {
154 PivotTable {
155 id: 0,
156 name: "PivotTable1".into(),
157 source: String::new(),
158 anchor: CellRef::default(),
159 rows: vec![],
160 columns: vec![],
161 values: vec![],
162 filters: vec![],
163 layout: PivotLayout::Compact,
164 enable_show_details: true,
165 grand_totals_rows: true,
166 grand_totals_cols: true,
167 subtotals: true,
168 subtotals_top: true,
169 style: "PivotStyleLight16".into(),
170 show_headers: true,
171 last_range: None,
172 calculated_fields: vec![],
173 values_on_rows: false,
174 values_position: None,
175 }
176 }
177}