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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use crate::{Color, LineStyle, LineType, Size, series::ShapeId, transform::Transform};
/// A vertical line at a fixed x-coordinate.
#[derive(Debug, Clone)]
pub struct VLine {
/// Unique identifier for the line.
pub id: ShapeId,
/// The x-coordinate where the vertical line is drawn.
pub x: f64,
/// How to interpret or convert the x value before drawing.
pub transform: Option<Transform>,
/// Optional label for the line (appears in legend if provided).
pub label: Option<String>,
/// Color of the line.
pub color: Color,
/// Line styling options, including width and pattern (solid, dashed, dotted).
pub line_style: LineStyle,
}
impl VLine {
/// Create a new vertical line at the given x-coordinate.
pub fn new(x: f64) -> Self {
Self {
id: ShapeId::new(),
x,
transform: None,
label: None,
color: Color::from_rgb(0.5, 0.5, 0.5),
line_style: LineStyle::default(),
}
}
/// Set the label for this line (will appear in legend).
pub fn with_label(mut self, label: impl Into<String>) -> Self {
let l = label.into();
if !l.is_empty() {
self.label = Some(l);
}
self
}
/// Set the color of the line.
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
/// Set how this reference line interprets or converts its x value before drawing.
///
/// For normal data values, conversion runs before the plot's x-axis scale.
/// `Transform::axes()` uses normalized plot positions instead.
pub fn with_transform(mut self, transform: Transform) -> Self {
self.transform = Some(transform);
self
}
/// Interpret the x position as a normalized plot coordinate.
pub fn with_axes_transform(mut self) -> Self {
self.transform = Some(Transform::axes());
self
}
/// Set the line width in pixels.
pub fn with_width(mut self, width: f32) -> Self {
self.line_style.width = Size::Pixels(width.max(0.5));
self
}
/// Set the line width in world units.
pub fn with_width_world(mut self, width: f64) -> Self {
self.line_style.width = Size::World(width.max(f64::EPSILON));
self
}
/// Set the line style.
pub fn with_style(mut self, style: LineStyle) -> Self {
let old_width = self.line_style.width;
let preserve_width = style.width == LineStyle::default().width;
self.line_style = style;
if preserve_width {
self.line_style.width = old_width;
}
self
}
/// Set only the line type while preserving the current width.
pub fn with_line_type(mut self, line_type: LineType) -> Self {
self.line_style.line_type = line_type;
self
}
}
/// A horizontal line at a fixed y-coordinate.
#[derive(Debug, Clone)]
pub struct HLine {
/// Unique identifier for the line.
pub id: ShapeId,
/// The y-coordinate where the horizontal line is drawn.
pub y: f64,
/// How to interpret or convert the y value before drawing.
pub transform: Option<Transform>,
/// Optional label for the line (appears in legend if provided).
pub label: Option<String>,
/// Color of the line.
pub color: Color,
/// Line styling options, including width and pattern (solid, dashed, dotted).
pub line_style: LineStyle,
}
impl HLine {
/// Create a new horizontal line at the given y-coordinate.
pub fn new(y: f64) -> Self {
Self {
id: ShapeId::new(),
y,
transform: None,
label: None,
color: Color::from_rgb(0.5, 0.5, 0.5),
line_style: LineStyle::default(),
}
}
/// Set the label for this line (will appear in legend).
pub fn with_label(mut self, label: impl Into<String>) -> Self {
let l = label.into();
if !l.is_empty() {
self.label = Some(l);
}
self
}
/// Set the color of the line.
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
/// Set how this reference line interprets or converts its y value before drawing.
///
/// For normal data values, conversion runs before the plot's y-axis scale.
/// `Transform::axes()` uses normalized plot positions instead.
pub fn with_transform(mut self, transform: Transform) -> Self {
self.transform = Some(transform);
self
}
/// Interpret the y position as a normalized plot coordinate.
pub fn with_axes_transform(mut self) -> Self {
self.transform = Some(Transform::axes());
self
}
/// Set the line width in pixels.
pub fn with_width(mut self, width: f32) -> Self {
self.line_style.width = Size::Pixels(width.max(0.5));
self
}
/// Set the line width in world units.
pub fn with_width_world(mut self, width: f64) -> Self {
self.line_style.width = Size::World(width.max(f64::EPSILON));
self
}
/// Set the line style.
pub fn with_style(mut self, style: LineStyle) -> Self {
let old_width = self.line_style.width;
let preserve_width = style.width == LineStyle::default().width;
self.line_style = style;
if preserve_width {
self.line_style.width = old_width;
}
self
}
/// Set only the line type while preserving the current width.
pub fn with_line_type(mut self, line_type: LineType) -> Self {
self.line_style.line_type = line_type;
self
}
}