diff --git a/egui/src/widgets/plot/items/mod.rs b/egui/src/widgets/plot/items/mod.rs index 0e703788e..ea4dee6ae 100644 --- a/egui/src/widgets/plot/items/mod.rs +++ b/egui/src/widgets/plot/items/mod.rs @@ -1658,6 +1658,7 @@ pub(super) fn rulers_at_value( let x_decimals = ((-scale[0].abs().log10()).ceil().at_least(0.0) as usize).at_most(6); let y_decimals = ((-scale[1].abs().log10()).ceil().at_least(0.0) as usize).at_most(6); if let Some(custom_label) = custom_label_func { + let name = (!name.is_empty()).then(|| name); custom_label(name, &value) } else if plot.show_x && plot.show_y { format!( diff --git a/egui/src/widgets/plot/mod.rs b/egui/src/widgets/plot/mod.rs index 9e69e496e..061aa6d30 100644 --- a/egui/src/widgets/plot/mod.rs +++ b/egui/src/widgets/plot/mod.rs @@ -18,7 +18,7 @@ mod items; mod legend; mod transform; -type CustomLabelFunc = dyn Fn(&str, &Value) -> String; +type CustomLabelFunc = dyn Fn(Option<&str>, &Value) -> String; type CustomLabelFuncRef = Option>; // ---------------------------------------------------------------------------- @@ -199,7 +199,7 @@ impl Plot { /// let line = Line::new(Values::from_values_iter(sin)); /// Plot::new("my_plot").view_aspect(2.0) /// .custom_label_func(|name, value| { - /// if !name.is_empty() { + /// if let Some(name) = name { /// format!("{}: {:.*}%", name, 1, value.y).to_string() /// } else { /// "".to_string() @@ -208,7 +208,7 @@ impl Plot { /// .show(ui, |plot_ui| plot_ui.line(line)); /// # }); /// ``` - pub fn custom_label_func String>( + pub fn custom_label_func, &Value) -> String>( mut self, custom_lebel_func: F, ) -> Self {