iced_plot/
reference_lines.rs1use crate::{Color, LineStyle, series::ShapeId};
2
3#[derive(Debug, Clone)]
5pub struct VLine {
6 pub id: ShapeId,
8 pub x: f64,
10 pub label: Option<String>,
12 pub color: Color,
14 pub width: f32,
16 pub line_style: LineStyle,
18}
19
20impl VLine {
21 pub fn new(x: f64) -> Self {
23 Self {
24 id: ShapeId::new(),
25 x,
26 label: None,
27 color: Color::from_rgb(0.5, 0.5, 0.5),
28 width: 1.0,
29 line_style: LineStyle::Solid,
30 }
31 }
32
33 pub fn with_label(mut self, label: impl Into<String>) -> Self {
35 let l = label.into();
36 if !l.is_empty() {
37 self.label = Some(l);
38 }
39 self
40 }
41
42 pub fn with_color(mut self, color: Color) -> Self {
44 self.color = color;
45 self
46 }
47
48 pub fn with_width(mut self, width: f32) -> Self {
50 self.width = width.max(0.5);
51 self
52 }
53
54 pub fn with_style(mut self, style: LineStyle) -> Self {
56 self.line_style = style;
57 self
58 }
59}
60
61#[derive(Debug, Clone)]
63pub struct HLine {
64 pub id: ShapeId,
66 pub y: f64,
68 pub label: Option<String>,
70 pub color: Color,
72 pub width: f32,
74 pub line_style: LineStyle,
76}
77
78impl HLine {
79 pub fn new(y: f64) -> Self {
81 Self {
82 id: ShapeId::new(),
83 y,
84 label: None,
85 color: Color::from_rgb(0.5, 0.5, 0.5),
86 width: 1.0,
87 line_style: LineStyle::Solid,
88 }
89 }
90
91 pub fn with_label(mut self, label: impl Into<String>) -> Self {
93 let l = label.into();
94 if !l.is_empty() {
95 self.label = Some(l);
96 }
97 self
98 }
99
100 pub fn with_color(mut self, color: Color) -> Self {
102 self.color = color;
103 self
104 }
105
106 pub fn with_width(mut self, width: f32) -> Self {
108 self.width = width.max(0.5);
109 self
110 }
111
112 pub fn with_style(mut self, style: LineStyle) -> Self {
114 self.line_style = style;
115 self
116 }
117}