From 05d26d898d03f56bd956666faf09bee0edb7df03 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Fri, 10 May 2024 14:23:30 -0400 Subject: [PATCH] Initialize trace metadata IDs to avoid trace-getting methods picking up other traces (like those added by tools). --- glue_plotly/viewers/histogram/dotplot_layer_artist.py | 3 ++- glue_plotly/viewers/histogram/layer_artist.py | 3 ++- glue_plotly/viewers/scatter/layer_artist.py | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/glue_plotly/viewers/histogram/dotplot_layer_artist.py b/glue_plotly/viewers/histogram/dotplot_layer_artist.py index d032016..d22d07c 100644 --- a/glue_plotly/viewers/histogram/dotplot_layer_artist.py +++ b/glue_plotly/viewers/histogram/dotplot_layer_artist.py @@ -2,6 +2,7 @@ # normalized mode, as a dotplot only makes sense when the heights are integral. import numpy as np +from uuid import uuid4 from glue.core.exceptions import IncompatibleAttribute from glue.viewers.common.layer_artist import LayerArtist @@ -35,7 +36,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None): self.view = view self.bins = None - self._dots_id = None + self._dots_id = uuid4().hex self._viewer_state.add_global_callback(self._update_dotplot) self.state.add_global_callback(self._update_dotplot) diff --git a/glue_plotly/viewers/histogram/layer_artist.py b/glue_plotly/viewers/histogram/layer_artist.py index 1fcd345..870c506 100644 --- a/glue_plotly/viewers/histogram/layer_artist.py +++ b/glue_plotly/viewers/histogram/layer_artist.py @@ -1,4 +1,5 @@ import numpy as np +from uuid import uuid4 from glue.core.exceptions import IncompatibleAttribute from glue.viewers.common.layer_artist import LayerArtist @@ -30,7 +31,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None): self.view = view self.bins = None - self._bars_id = None + self._bars_id = uuid4().hex self._viewer_state.add_global_callback(self._update_histogram) self.state.add_global_callback(self._update_histogram) diff --git a/glue_plotly/viewers/scatter/layer_artist.py b/glue_plotly/viewers/scatter/layer_artist.py index 753c080..506b0d0 100644 --- a/glue_plotly/viewers/scatter/layer_artist.py +++ b/glue_plotly/viewers/scatter/layer_artist.py @@ -84,9 +84,13 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None): scatter = self._create_scatter() self.view.figure.add_trace(scatter) - self._lines_id = None - self._error_id = None - self._vector_id = None + # We want to initialize these to some dummy UUIDs so that + # _get_lines, _get_error_bars, _get_vectors, etc. don't pick up + # any other traces that tools have added to the viewer, which + # will happen if these IDs are None + self._lines_id = uuid4().hex + self._error_id = uuid4().hex + self._vector_id = uuid4().hex def remove(self): self.view._remove_traces([self._get_scatter()])