MCPcopy Create free account
hub / github.com/emilk/egui_plot / shapes

Method shapes

egui_plot/src/items/span.rs:242–292  ·  view source on GitHub ↗
(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>)

Source from the content-addressed store, hash-verified

240
241impl PlotItem for Span {
242 fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
243 let plot_bounds = match self.axis {
244 Axis::X => transform.bounds().range_x(),
245 Axis::Y => transform.bounds().range_y(),
246 };
247
248 let (range_min, range_max) = self.range_sorted();
249
250 // If the span is outside of the visible range, don't draw anything.
251 if range_max < *plot_bounds.start() || range_min > *plot_bounds.end() {
252 return;
253 }
254
255 let mut stroke = self.border_stroke;
256 let mut fill = self.fill;
257 if self.base.highlight {
258 (stroke, fill) = highlighted_color(stroke, fill);
259 }
260
261 // Clamp the range to support (half-)infinite spans
262 let range_min_clamped = range_min.max(*plot_bounds.start());
263 let range_max_clamped = range_max.min(*plot_bounds.end());
264
265 // Draw the rect first with the clamped range
266 let span_rect = match self.axis {
267 Axis::X => transform.rect_from_values(
268 &PlotPoint::new(range_min_clamped, transform.bounds().min[1]),
269 &PlotPoint::new(range_max_clamped, transform.bounds().max[1]),
270 ),
271 Axis::Y => transform.rect_from_values(
272 &PlotPoint::new(transform.bounds().min[0], range_min_clamped),
273 &PlotPoint::new(transform.bounds().max[0], range_max_clamped),
274 ),
275 };
276
277 if fill != Color32::TRANSPARENT && span_rect.is_positive() {
278 shapes.push(Shape::rect_filled(span_rect, 0.0, fill));
279 }
280
281 // Draw the first border if it is in bounds
282 if plot_bounds.contains(&range_min) {
283 self.draw_border(range_min, stroke, transform, shapes);
284 }
285
286 // Draw the second border if it is in bounds
287 if plot_bounds.contains(&range_max) {
288 self.draw_border(range_max, stroke, transform, shapes);
289 }
290
291 self.draw_name(ui, transform, shapes, &span_rect);
292 }
293
294 fn initialize(&mut self, _x_range: RangeInclusive<f64>) {}
295

Callers 1

collect_shapesMethod · 0.45

Calls 10

highlighted_colorFunction · 0.85
range_xMethod · 0.80
range_yMethod · 0.80
range_sortedMethod · 0.80
maxMethod · 0.80
minMethod · 0.80
rect_from_valuesMethod · 0.80
draw_borderMethod · 0.80
draw_nameMethod · 0.80
boundsMethod · 0.45

Tested by

no test coverage detected