From 9bba0944675b7375d63e0f1f94582a08813693bc Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 18 Sep 2026 11:07:50 +0200 Subject: [PATCH] `link_axis` and `link_cursor` take an `Id` instead of `impl Into` Also document that the group id must be globally unique, and that the very same id must be passed to each plot in the group. The link groups all live in one app-wide store, so a colliding id silently links unrelated plots. Co-Authored-By: Claude Opus 5 --- egui_plot/src/plot.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/egui_plot/src/plot.rs b/egui_plot/src/plot.rs index 00738336..05d1d74a 100644 --- a/egui_plot/src/plot.rs +++ b/egui_plot/src/plot.rs @@ -196,6 +196,8 @@ impl<'a> Plot<'a> { /// /// This will override the id set by [`Self::new`]. /// + /// This is the final widget id, so it must be globally unique. + /// /// This is the same `Id` that can be used for [`PlotMemory::load`]. #[inline] pub fn id(mut self, id: Id) -> Self { @@ -661,18 +663,28 @@ impl<'a> Plot<'a> { /// Add this plot to an axis link group so that this plot will share the /// bounds with other plots in the same group. A plot cannot belong to /// more than one axis group. + /// + /// The link groups are shared by the whole app, so `group_id` must be + /// globally unique, and the very same id must be passed to each plot you + /// want linked together. Create one with [`Id::new`], or derive one from + /// the surrounding [`Ui`] with [`Ui::make_persistent_id`]. #[inline] - pub fn link_axis(mut self, group_id: impl Into, link: impl Into) -> Self { - self.linked_axes = Some((group_id.into(), link.into())); + pub fn link_axis(mut self, group_id: Id, link: impl Into) -> Self { + self.linked_axes = Some((group_id, link.into())); self } /// Add this plot to a cursor link group so that this plot will share the /// cursor position with other plots in the same group. A plot cannot /// belong to more than one cursor group. + /// + /// The link groups are shared by the whole app, so `group_id` must be + /// globally unique, and the very same id must be passed to each plot you + /// want linked together. Create one with [`Id::new`], or derive one from + /// the surrounding [`Ui`] with [`Ui::make_persistent_id`]. #[inline] - pub fn link_cursor(mut self, group_id: impl Into, link: impl Into) -> Self { - self.linked_cursors = Some((group_id.into(), link.into())); + pub fn link_cursor(mut self, group_id: Id, link: impl Into) -> Self { + self.linked_cursors = Some((group_id, link.into())); self }