charming/element/
axis_pointer.rs

1use crate::{
2    datatype::CompositeValue,
3    element::{Label, LineStyle},
4};
5use charming_macros::CharmingSetters;
6use serde::{Deserialize, Serialize};
7
8#[derive(Serialize, Deserialize, Debug, PartialEq, PartialOrd, Clone, Copy)]
9#[serde(rename_all = "snake_case")]
10pub enum AxisPointerType {
11    Line,
12    Shadow,
13    Cross,
14    None,
15}
16
17#[derive(Serialize, Deserialize, Debug, PartialEq, PartialOrd, Clone, Copy)]
18#[serde(rename_all = "snake_case")]
19pub enum AxisPointerAxis {
20    X,
21    Y,
22    Radius,
23    Angle,
24}
25
26#[serde_with::apply(
27  Option => #[serde(skip_serializing_if = "Option::is_none")],
28  Vec => #[serde(default, skip_serializing_if = "Vec::is_empty")]
29)]
30#[derive(Serialize, Deserialize, CharmingSetters, Debug, PartialEq, PartialOrd, Clone)]
31#[serde(rename_all = "camelCase")]
32pub struct AxisPointerLink {
33    x_axis_index: Option<CompositeValue>,
34    x_axis_name: Option<String>,
35    y_axis_index: Option<CompositeValue>,
36    y_axis_name: Option<String>,
37}
38
39/// Axis Pointer is a tool for displaying reference line and axis value under
40/// mouse pointer.
41#[serde_with::apply(
42  Option => #[serde(skip_serializing_if = "Option::is_none")],
43  Vec => #[serde(default, skip_serializing_if = "Vec::is_empty")]
44)]
45#[derive(Serialize, Deserialize, CharmingSetters, Debug, PartialEq, Clone)]
46#[serde(rename_all = "camelCase")]
47pub struct AxisPointer {
48    /// Component ID.
49    id: Option<String>,
50    /// Whether to show the axis pointer.
51    show: Option<bool>,
52    /// Indicator type.
53    #[serde(rename = "type")]
54    type_: Option<AxisPointerType>,
55    snap: Option<bool>,
56    animation: Option<bool>,
57    z: Option<f64>,
58    axis: Option<AxisPointerAxis>,
59    /// Label of axis pointer.
60    label: Option<Label>,
61    /// Line style of axis pointer.
62    line_style: Option<LineStyle>,
63    /// Axis pointer can be linked to each other.
64    #[charming_set_vec]
65    link: Vec<AxisPointerLink>,
66}