diff --git a/egui/src/widgets/plot/items/values.rs b/egui/src/widgets/plot/items/values.rs index 946d203a..07ad4097 100644 --- a/egui/src/widgets/plot/items/values.rs +++ b/egui/src/widgets/plot/items/values.rs @@ -264,11 +264,19 @@ impl Values { } pub(super) fn get_bounds(&self) -> PlotBounds { - let mut bounds = PlotBounds::NOTHING; - self.values - .iter() - .for_each(|value| bounds.extend_with(value)); - bounds + if self.values.is_empty() { + if let Some(generator) = &self.generator { + generator.estimate_bounds() + } else { + PlotBounds::NOTHING + } + } else { + let mut bounds = PlotBounds::NOTHING; + for value in &self.values { + bounds.extend_with(value); + } + bounds + } } } @@ -333,6 +341,20 @@ struct ExplicitGenerator { points: usize, } +impl ExplicitGenerator { + fn estimate_bounds(&self) -> PlotBounds { + let min_x = *self.x_range.start(); + let max_x = *self.x_range.end(); + let min_y = (self.function)(min_x); + let max_y = (self.function)(max_x); + // TODO: sample some more points + PlotBounds { + min: [min_x, min_y], + max: [max_x, max_y], + } + } +} + // ---------------------------------------------------------------------------- /// Result of [`super::PlotItem::find_closest()`] search, identifies an element inside the item for immediate use