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
use serde::{ser::SerializeSeq, Serialize};
/// The boundary gap on both sides of a coordinate axis. The setting and
/// behavior of category axes and non-category axes are different.
///
/// The `BoundaryGap` of category axis can be set to either `true` or `false`.
/// Default value is `true`.
///
/// For non-category axis, including time, numerical value, and log axes,
/// `BoundaryGap` is an array of two values, representing the spanning range
/// between minimum and maximum value.
pub enum BoundaryGap {
CategoryAxis(bool),
NonCategoryAxis(String, String),
}
impl Serialize for BoundaryGap {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
match self {
BoundaryGap::CategoryAxis(b) => b.serialize(serializer),
BoundaryGap::NonCategoryAxis(min, max) => {
let mut s = serializer.serialize_seq(Some(2))?;
s.serialize_element(min)?;
s.serialize_element(max)?;
s.end()
}
}
}
}
impl From<bool> for BoundaryGap {
fn from(b: bool) -> Self {
BoundaryGap::CategoryAxis(b)
}
}
impl From<(&str, &str)> for BoundaryGap {
fn from((min, max): (&str, &str)) -> Self {
BoundaryGap::NonCategoryAxis(min.to_string(), max.to_string())
}
}