From 77063b91cf2ba35540661e7ceb0c6212b6f3b573 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Fri, 10 May 2024 15:44:05 -0400 Subject: [PATCH] Fix up some issues with z-order manipulation. --- glue_plotly/viewers/histogram/dotplot_layer_artist.py | 9 ++++----- glue_plotly/viewers/histogram/layer_artist.py | 9 ++++----- glue_plotly/viewers/scatter/layer_artist.py | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/glue_plotly/viewers/histogram/dotplot_layer_artist.py b/glue_plotly/viewers/histogram/dotplot_layer_artist.py index cc2f590..e957fa2 100644 --- a/glue_plotly/viewers/histogram/dotplot_layer_artist.py +++ b/glue_plotly/viewers/histogram/dotplot_layer_artist.py @@ -40,6 +40,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None): self._viewer_state.add_global_callback(self._update_dotplot) self.state.add_global_callback(self._update_dotplot) + self.state.add_callback("zorder", self._update_zorder) def _get_dots(self): return self.view.figure.select_traces(dict(meta=self._dots_id)) @@ -126,11 +127,12 @@ def _update_data(self): self._dots_id = dots[0].meta if dots else None self.view.figure.add_traces(dots) - def _update_zorder(self): + def _update_zorder(self, *args): + current_traces = self.view.figure.data traces = [self.view.selection_layer] for layer in self.view.layers: traces += list(layer.traces()) - self.view.figure.data = traces + self.view.figure.data = traces + [t for t in current_traces if t not in traces] def _update_dotplot(self, force=False, **kwargs): if (self._viewer_state.hist_x_min is None or @@ -156,9 +158,6 @@ def _update_dotplot(self, force=False, **kwargs): if force or len(changed & VISUAL_PROPERTIES) > 0: self._update_visual_attributes(changed, force=force) - if force or "zorder" in changed: - self._update_zorder() - def update(self): self.state.reset_cache() self._update_dotplot(force=True) diff --git a/glue_plotly/viewers/histogram/layer_artist.py b/glue_plotly/viewers/histogram/layer_artist.py index 870c506..d629107 100644 --- a/glue_plotly/viewers/histogram/layer_artist.py +++ b/glue_plotly/viewers/histogram/layer_artist.py @@ -35,6 +35,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None): self._viewer_state.add_global_callback(self._update_histogram) self.state.add_global_callback(self._update_histogram) + self.state.add_callback("zorder", self._update_zorder) def _get_bars(self): return self.view.figure.select_traces(dict(meta=self._bars_id)) @@ -122,11 +123,12 @@ def _update_data(self): self._bars_id = bars[0].meta if bars else None self.view.figure.add_traces(bars) - def _update_zorder(self): + def _update_zorder(self, *args): + current_traces = self.view.figure.data traces = [self.view.selection_layer] for layer in self.view.layers: traces += list(layer.traces()) - self.view.figure.data = traces + self.view.figure.data = traces + [t for t in current_traces if t not in traces] def _update_histogram(self, force=False, **kwargs): if (self._viewer_state.hist_x_min is None or @@ -152,9 +154,6 @@ def _update_histogram(self, force=False, **kwargs): if force or len(changed & VISUAL_PROPERTIES) > 0: self._update_visual_attributes(changed, force=force) - if force or "zorder" in changed: - self._update_zorder() - def update(self): self.state.reset_cache() self._update_histogram(force=True) diff --git a/glue_plotly/viewers/scatter/layer_artist.py b/glue_plotly/viewers/scatter/layer_artist.py index 506b0d0..e229def 100644 --- a/glue_plotly/viewers/scatter/layer_artist.py +++ b/glue_plotly/viewers/scatter/layer_artist.py @@ -69,6 +69,7 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None): self._viewer_state.add_global_callback(self._update_display) self.state.add_global_callback(self._update_display) + self.state.add_callback("zorder", self._update_zorder) self.view = view @@ -166,14 +167,12 @@ def _update_display(self, force=False, **kwargs): if force or len(changed & LINE_PROPERTIES) > 0: self._update_lines(changed, force=force) - if force or "zorder" in changed: - self._update_zorder() - - def _update_zorder(self): + def _update_zorder(self, *args): + current_traces = self.view.figure.data traces = [self.view.selection_layer] for layer in self.view.layers: traces += list(layer.traces()) - self.view.figure.data = traces + self.view.figure.data = traces + [t for t in current_traces if t not in traces] def _update_lines(self, changed, force=False): scatter = self._get_scatter()