Skip to main content

rust_ppm/plot/
style.rs

1use crate::Pixel;
2
3/// Styling for a connected line series.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct LineStyle {
6    /// Line color in RGB.
7    pub color: Pixel,
8    /// Line thickness in pixels.
9    pub width: usize,
10}
11
12impl LineStyle {
13    /// Creates a default blue line style.
14    pub const fn new() -> Self {
15        Self {
16            color: Pixel::rgb(0, 0, 255),
17            width: 1,
18        }
19    }
20
21    /// Sets the line color.
22    pub const fn color(mut self, color: Pixel) -> Self {
23        self.color = color;
24        self
25    }
26
27    /// Sets the line width in pixels.
28    pub const fn width(mut self, width: usize) -> Self {
29        self.width = width;
30        self
31    }
32}
33
34impl Default for LineStyle {
35    fn default() -> Self {
36        Self::new()
37    }
38}
39
40/// Styling for a scatter marker series.
41#[derive(Clone, Copy, Debug, Eq, PartialEq)]
42pub struct MarkerStyle {
43    /// Marker color in RGB.
44    pub color: Pixel,
45    /// Marker diameter in pixels.
46    pub size: usize,
47}
48
49impl MarkerStyle {
50    /// Creates a default red marker style.
51    pub const fn new() -> Self {
52        Self {
53            color: Pixel::rgb(255, 0, 0),
54            size: 1,
55        }
56    }
57
58    /// Sets the marker color.
59    pub const fn color(mut self, color: Pixel) -> Self {
60        self.color = color;
61        self
62    }
63
64    /// Sets the marker size in pixels.
65    pub const fn size(mut self, size: usize) -> Self {
66        self.size = size;
67        self
68    }
69}
70
71impl Default for MarkerStyle {
72    fn default() -> Self {
73        Self::new()
74    }
75}