1use bitcode::{Decode, Encode};
2use serde::{Deserialize, Serialize};
3
4use crate::types::{Color, Dxf, Style};
5
6#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
7pub enum ValueOperator {
8 Equal,
9 GreaterThan,
10 GreaterThanOrEqual,
11 LessThan,
12 LessThanOrEqual,
13 NotEqual,
14 Between,
15 NotBetween,
16}
17
18#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
19pub enum TextOperator {
20 Contains, DoesNotContain,
22 BeginsWith,
23 EndsWith, Equals,
25}
26
27#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
28pub enum PeriodType {
29 Between,
30 NotBetween,
31 Yesterday,
32 Today,
33 Tomorrow,
34 Last7Days,
35 Next7Days,
36 LastWeek,
37 ThisWeek,
38 NextWeek,
39 LastMonth,
40 ThisMonth,
41 NextMonth,
42 LastYear,
43 ThisYear,
44 NextYear,
45}
46
47#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
49pub enum Cfvo {
50 Min,
51 Max,
52 Number(f64),
53 Percent(f64),
54 Percentile(f64),
55 Formula(String),
56}
57
58#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
59pub enum Icon {
60 ArrowUp,
61 ArrowRight,
62 ArrowDown,
63 ArrowAngleUp,
64 ArrowAngleDown,
65 Circle,
66 TriangleUp,
67 TriangleDown,
68 TriangleUpFilled,
69 TriangleDownFilled,
70 FlatRectangle,
71 Rhombus,
72 Flag,
73 Check,
74 Cross,
75 Exclamation,
76 Star,
77 Heart,
78 ThumbsUp,
79 ThumbsDown,
80}
81
82#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
83pub struct ColorScaleThreshold {
84 pub cfvo: Cfvo,
85 pub color: Color,
86}
87
88#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
89pub struct IconThreshold {
90 pub icon: Icon,
91 pub cfvo: Cfvo,
92 pub color: Color,
93 pub is_strict: bool,
96}
97
98#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
99#[serde(tag = "type")]
100pub enum CfRule {
101 ColorScale {
102 thresholds: Vec<ColorScaleThreshold>,
103 },
104 CellIs {
105 operator: ValueOperator,
106 formula: String,
107 formula2: Option<String>,
109 dxf_id: u32,
110 stop_if_true: bool,
111 },
112 Formula {
113 formula: String,
114 dxf_id: u32,
115 stop_if_true: bool,
116 },
117 Text {
118 operator: TextOperator,
119 value: String,
120 dxf_id: u32,
121 stop_if_true: bool,
122 },
123 TimePeriod {
124 time_period: PeriodType,
125 date1: Option<String>,
126 date2: Option<String>,
127 dxf_id: u32,
128 stop_if_true: bool,
129 },
130 DuplicateValues {
131 dxf_id: u32,
132 stop_if_true: bool,
133 },
134 UniqueValues {
135 dxf_id: u32,
136 stop_if_true: bool,
137 },
138 Blanks {
139 dxf_id: u32,
140 stop_if_true: bool,
141 },
142 NotBlanks {
143 dxf_id: u32,
144 stop_if_true: bool,
145 },
146 Errors {
147 dxf_id: u32,
148 stop_if_true: bool,
149 },
150 NoErrors {
151 dxf_id: u32,
152 stop_if_true: bool,
153 },
154 AboveAverage {
155 dxf_id: u32,
156 stop_if_true: bool,
157 },
158 BelowAverage {
159 dxf_id: u32,
160 stop_if_true: bool,
161 },
162 Top10 {
163 rank: u32,
164 percent: bool,
165 dxf_id: u32,
166 stop_if_true: bool,
167 },
168 Bottom10 {
169 rank: u32,
170 percent: bool,
171 dxf_id: u32,
172 stop_if_true: bool,
173 },
174 DataBar {
175 min: Option<Cfvo>,
178 max: Option<Cfvo>,
179 positive_color: Color,
180 negative_color: Color,
181 is_gradient: bool,
182 show_value: bool,
189 },
190 IconSet {
191 thresholds: Vec<IconThreshold>,
199 show_value: bool,
200 },
201 IconRating {
202 icon: Icon,
204 color: Color,
205 thresholds: Vec<(Cfvo, bool)>,
208 show_value: bool,
209 },
210}
211
212#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
217#[serde(tag = "type")]
218pub enum CfRuleInput {
219 ColorScale {
220 thresholds: Vec<ColorScaleThreshold>,
221 },
222 CellIs {
223 operator: ValueOperator,
224 formula: String,
225 formula2: Option<String>,
226 format: Dxf,
227 stop_if_true: bool,
228 },
229 Text {
230 operator: TextOperator,
231 value: String,
232 format: Dxf,
233 stop_if_true: bool,
234 },
235 Formula {
236 formula: String,
237 format: Dxf,
238 stop_if_true: bool,
239 },
240 TimePeriod {
241 time_period: PeriodType,
242 date1: Option<String>,
243 date2: Option<String>,
244 format: Dxf,
245 stop_if_true: bool,
246 },
247 DuplicateValues {
248 format: Dxf,
249 stop_if_true: bool,
250 },
251 UniqueValues {
252 format: Dxf,
253 stop_if_true: bool,
254 },
255 Blanks {
256 format: Dxf,
257 stop_if_true: bool,
258 },
259 NotBlanks {
260 format: Dxf,
261 stop_if_true: bool,
262 },
263 Errors {
264 format: Dxf,
265 stop_if_true: bool,
266 },
267 NoErrors {
268 format: Dxf,
269 stop_if_true: bool,
270 },
271 AboveAverage {
272 format: Dxf,
273 stop_if_true: bool,
274 },
275 BelowAverage {
276 format: Dxf,
277 stop_if_true: bool,
278 },
279 Top10 {
280 rank: u32,
281 percent: bool,
282 format: Dxf,
283 stop_if_true: bool,
284 },
285 Bottom10 {
286 rank: u32,
287 percent: bool,
288 format: Dxf,
289 stop_if_true: bool,
290 },
291 DataBar {
292 min: Option<Cfvo>,
293 max: Option<Cfvo>,
294 positive_color: Color,
295 negative_color: Color,
296 is_gradient: bool,
297 show_value: bool,
298 },
299 IconSet {
300 thresholds: Vec<IconThreshold>,
301 show_value: bool,
302 },
303 IconRating {
304 icon: Icon,
305 color: Color,
306 thresholds: Vec<(Cfvo, bool)>,
307 show_value: bool,
308 },
309}
310
311#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
312pub struct ConditionalFormatting {
313 pub range: String,
314 pub cf_rule: CfRule,
315 pub priority: u32,
316}
317
318#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
328pub struct ConditionalFormattingView {
329 pub index: usize,
330 pub range: String,
331 pub cf_rule: CfRule,
332 pub priority: u32,
333}
334
335#[derive(Clone, Debug)]
341pub(crate) enum CfCellResult {
342 Dxf(u32),
344 ColorScale(Color),
346 DataBar {
348 positive_color: Color,
349 negative_color: Color,
350 is_gradient: bool,
351 value: f64,
352 axis_position: f64,
354 show_value: bool,
355 },
356 Icon {
358 icon: Icon,
359 color: Color,
360 show_value: bool,
361 },
362 Rating {
364 icon: Icon,
365 count: u32,
366 max: u32,
367 color: Color,
368 show_value: bool,
369 },
370}
371
372#[derive(Serialize, Deserialize, Clone, Debug)]
378pub struct CfIcon {
379 pub icon: Icon,
380 pub color: Color,
381 pub show_value: bool,
382}
383
384#[derive(Serialize, Deserialize, Clone, Debug)]
386pub struct CfDataBar {
387 pub positive_color: Color,
388 pub negative_color: Color,
389 pub is_gradient: bool,
390 pub value: f64,
392 pub axis_position: f64,
394 pub show_value: bool,
395}
396
397#[derive(Serialize, Deserialize, Clone, Debug)]
399pub struct CfRating {
400 pub icon: Icon,
402 pub count: u32,
404 pub max: u32,
406 pub color: Color,
407 pub show_value: bool,
408}
409
410pub fn icon_set_icons(name: &str) -> Option<Vec<(Icon, Color)>> {
415 let s = |c: &'static str| Color::Rgb(c.to_string());
416 match name {
417 "3Arrows" => Some(vec![
418 (Icon::ArrowDown, s("#e43400")),
419 (Icon::ArrowRight, s("#ffeb84")),
420 (Icon::ArrowUp, s("#84cb1f")),
421 ]),
422 "3ArrowsGray" => Some(vec![
423 (Icon::ArrowDown, s("#808080")),
424 (Icon::ArrowRight, s("#808080")),
425 (Icon::ArrowUp, s("#808080")),
426 ]),
427 "4Arrows" => Some(vec![
428 (Icon::ArrowDown, s("#e43400")),
429 (Icon::ArrowAngleDown, s("#ffeb84")),
430 (Icon::ArrowAngleUp, s("#ffeb84")),
431 (Icon::ArrowUp, s("#84cb1f")),
432 ]),
433 "4ArrowsGray" => Some(vec![
434 (Icon::ArrowDown, s("#808080")),
435 (Icon::ArrowAngleDown, s("#808080")),
436 (Icon::ArrowAngleUp, s("#808080")),
437 (Icon::ArrowUp, s("#808080")),
438 ]),
439 "5Arrows" => Some(vec![
440 (Icon::ArrowDown, s("#e43400")),
441 (Icon::ArrowAngleDown, s("#ffeb84")),
442 (Icon::ArrowRight, s("#ffeb84")),
443 (Icon::ArrowAngleUp, s("#ffeb84")),
444 (Icon::ArrowUp, s("#84cb1f")),
445 ]),
446 "5ArrowsGray" => Some(vec![
447 (Icon::ArrowDown, s("#808080")),
448 (Icon::ArrowAngleDown, s("#808080")),
449 (Icon::ArrowRight, s("#808080")),
450 (Icon::ArrowAngleUp, s("#808080")),
451 (Icon::ArrowUp, s("#808080")),
452 ]),
453 "3Triangles" => Some(vec![
454 (Icon::TriangleDown, s("#f8696b")),
455 (Icon::FlatRectangle, s("#ffeb84")),
456 (Icon::TriangleUp, s("#63be7b")),
457 ]),
458 "3TrafficLights1" | "3TrafficLights" | "3TrafficLights2" => Some(vec![
459 (Icon::Circle, s("#f8696b")),
460 (Icon::Circle, s("#ffeb84")),
461 (Icon::Circle, s("#63be7b")),
462 ]),
463 "4TrafficLights" => Some(vec![
464 (Icon::Circle, s("#000000")),
465 (Icon::Circle, s("#f8696b")),
466 (Icon::Circle, s("#ffeb84")),
467 (Icon::Circle, s("#63be7b")),
468 ]),
469 "3Signs" => Some(vec![
470 (Icon::Cross, s("#f8696b")),
471 (Icon::TriangleUp, s("#ffeb84")),
472 (Icon::Circle, s("#63be7b")),
473 ]),
474 "4RedToBlack" => Some(vec![
475 (Icon::Circle, s("#000000")),
476 (Icon::Circle, s("#808080")),
477 (Icon::Circle, s("#f66f00")),
478 (Icon::Circle, s("#e43400")),
479 ]),
480 "3Symbols" => Some(vec![
481 (Icon::Cross, s("#f8696b")),
482 (Icon::Exclamation, s("#ffeb84")),
483 (Icon::Check, s("#63be7b")),
484 ]),
485 "3Symbols2" => Some(vec![
486 (Icon::Cross, s("#f8696b")),
487 (Icon::Exclamation, s("#ffeb84")),
488 (Icon::Check, s("#63be7b")),
489 ]),
490 "3Flags" => Some(vec![
491 (Icon::Flag, s("#f8696b")),
492 (Icon::Flag, s("#ffeb84")),
493 (Icon::Flag, s("#63be7b")),
494 ]),
495 _ => None,
496 }
497}
498
499#[derive(Serialize, Deserialize, Clone, Debug)]
501pub struct ExtendedStyle {
502 pub style: Style,
504 pub icon: Option<CfIcon>,
506 pub data_bar: Option<CfDataBar>,
508 pub rating: Option<CfRating>,
510}