Skip to main content

fission_charts/components/
mark.rs

1use fission_core::op::Color;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct MarkPoint {
6    pub name: String,
7    pub x: Option<f32>,
8    pub y: f32,
9    pub color: Color,
10}
11
12impl MarkPoint {
13    pub fn y(name: impl Into<String>, y: f32) -> Self {
14        Self {
15            name: name.into(),
16            x: None,
17            y,
18            color: Color::RED,
19        }
20    }
21
22    pub fn xy(name: impl Into<String>, x: f32, y: f32) -> Self {
23        Self {
24            name: name.into(),
25            x: Some(x),
26            y,
27            color: Color::RED,
28        }
29    }
30
31    pub fn color(mut self, color: Color) -> Self {
32        self.color = color;
33        self
34    }
35}
36
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38pub struct MarkLine {
39    pub name: String,
40    pub y: f32,
41    pub color: Color,
42    pub width: f32,
43}
44
45impl MarkLine {
46    pub fn y(name: impl Into<String>, y: f32) -> Self {
47        Self {
48            name: name.into(),
49            y,
50            color: Color::RED,
51            width: 1.5,
52        }
53    }
54
55    pub fn color(mut self, color: Color) -> Self {
56        self.color = color;
57        self
58    }
59
60    pub fn width(mut self, width: f32) -> Self {
61        self.width = width;
62        self
63    }
64}
65
66#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
67pub struct MarkArea {
68    pub name: String,
69    pub y_min: f32,
70    pub y_max: f32,
71    pub color: Color,
72}
73
74impl MarkArea {
75    pub fn y_range(name: impl Into<String>, y_min: f32, y_max: f32) -> Self {
76        Self {
77            name: name.into(),
78            y_min,
79            y_max,
80            color: Color {
81                r: 250,
82                g: 204,
83                b: 21,
84                a: 50,
85            },
86        }
87    }
88
89    pub fn color(mut self, color: Color) -> Self {
90        self.color = color;
91        self
92    }
93}