MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / draw_lines

Function draw_lines

src/plot_renderer/canvas.rs:136–189  ·  view source on GitHub ↗
(frame: &mut Frame, state: &PlotState, bounds: Rectangle)

Source from the content-addressed store, hash-verified

134}
135
136fn draw_lines(frame: &mut Frame, state: &PlotState, bounds: Rectangle) {
137 for series in state.series.iter() {
138 let Some(line_style) = series.line_style else {
139 continue;
140 };
141 if series.len < 2 {
142 continue;
143 }
144
145 let width = line_style.width.to_px(&state.camera, &bounds).max(0.5);
146 let points = &state.points[series.start..series.start + series.len];
147 let mut distance_along_strip = 0.0;
148
149 for index in 1..points.len() {
150 let break_segment = series
151 .point_indices
152 .get(index)
153 .zip(series.point_indices.get(index - 1))
154 .is_some_and(|(curr, prev)| *curr != *prev + 1);
155
156 if break_segment {
157 distance_along_strip = 0.0;
158 continue;
159 }
160
161 let p0 = world_to_canvas_point(points[index - 1].position, &state.camera, &bounds);
162 let p1 = world_to_canvas_point(points[index].position, &state.camera, &bounds);
163 let delta = iced::Vector::new(p1.x - p0.x, p1.y - p0.y);
164 let segment_length = (delta.x * delta.x + delta.y * delta.y).sqrt();
165 if segment_length <= f32::EPSILON {
166 continue;
167 }
168
169 let c0 = *state
170 .point_colors
171 .get(series.start + index - 1)
172 .unwrap_or(&series.color);
173 let c1 = *state
174 .point_colors
175 .get(series.start + index)
176 .unwrap_or(&series.color);
177 draw_styled_line_segment(
178 frame,
179 p0,
180 p1,
181 line_style.line_type,
182 width,
183 blend_colors(c0, c1),
184 distance_along_strip,
185 );
186 distance_along_strip += segment_length;
187 }
188 }
189}
190
191fn draw_reference_lines(frame: &mut Frame, state: &PlotState, bounds: Rectangle) {
192 for vline in state.vlines.iter() {

Callers 1

drawFunction · 0.85

Calls 6

world_to_canvas_pointFunction · 0.85
draw_styled_line_segmentFunction · 0.85
blend_colorsFunction · 0.85
to_pxMethod · 0.80
getMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected