Skip to main content

perspective_viewer/config/
datetime_column_style.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13mod color_mode;
14mod custom;
15mod custom_format;
16mod simple;
17mod simple_format;
18
19pub use color_mode::*;
20pub use custom::*;
21pub use custom_format::*;
22use serde::{Deserialize, Serialize};
23pub use simple::*;
24pub use simple_format::*;
25use ts_rs::TS;
26
27/// `Simple` case has all default-able keys and must be last!
28#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
29// #[serde(tag = "format", content = "date_format")]
30#[serde(untagged)]
31pub enum DatetimeFormatType {
32    // #[serde(rename = "custom")]
33    Custom(CustomDatetimeStyleConfig),
34    Simple(SimpleDatetimeStyleConfig),
35}
36
37impl Default for DatetimeFormatType {
38    fn default() -> Self {
39        Self::Simple(SimpleDatetimeStyleConfig::default())
40    }
41}
42
43impl DatetimeFormatType {
44    pub fn time_zone(&self) -> &Option<String> {
45        match self {
46            DatetimeFormatType::Custom(x) => &x.time_zone,
47            DatetimeFormatType::Simple(x) => &x.time_zone,
48        }
49    }
50
51    pub fn time_zone_mut(&mut self) -> &mut Option<String> {
52        match self {
53            DatetimeFormatType::Custom(x) => &mut x.time_zone,
54            DatetimeFormatType::Simple(x) => &mut x.time_zone,
55        }
56    }
57}
58
59/// A model for the JSON serialized style configuration for a column of type
60/// `datetime`.
61#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, TS)]
62// #[derive(WasmDescribe!, FromWasmAbi!)]
63pub struct DatetimeColumnStyleConfig {
64    #[serde(default)]
65    #[serde(skip_serializing_if = "Option::is_none")]
66    #[ts(optional, as = "Option<_>")]
67    pub date_format: Option<DatetimeFormatType>,
68
69    #[serde(default)]
70    #[serde(skip_serializing_if = "DatetimeColorMode::is_none")]
71    pub datetime_color_mode: DatetimeColorMode,
72
73    #[serde(default)]
74    #[serde(skip_serializing_if = "Option::is_none")]
75    #[ts(skip)]
76    pub color: Option<String>,
77}