(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>)
| 240 | |
| 241 | impl 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 |
no test coverage detected