Skip to content

Commit

Permalink
Reset RangeXY when framewise is set (#4585)
Browse files Browse the repository at this point in the history
* Reset RangeXY when framewise is set

* Test RangeXY stream reset
  • Loading branch information
philippjfr authored Sep 1, 2020
1 parent 60c96aa commit 90bd54b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,11 +1420,28 @@ def _update_glyphs(self, element, ranges, style):
self._update_datasource(source, data)


def _reset_ranges(self):
"""
Resets RangeXY streams if norm option is set to framewise
"""
if self.overlaid:
return
for el, callbacks in self.traverse(lambda x: (x.current_frame, x.callbacks)):
if el is None:
continue
for callback in callbacks:
norm = self.lookup_options(el, 'norm').options
if norm.get('framewise'):
for s in callback.streams:
if isinstance(s, RangeXY):
s.reset()

def update_frame(self, key, ranges=None, plot=None, element=None):
"""
Updates an existing plot with data corresponding
to the key.
"""
self._reset_ranges()
reused = isinstance(self.hmap, DynamicMap) and (self.overlaid or self.batched)
if not reused and element is None:
element = self._get_frame(key)
Expand Down Expand Up @@ -2302,6 +2319,7 @@ def update_frame(self, key, ranges=None, element=None):
key tuple (where integers represent frames). Returns this
state.
"""
self._reset_ranges()
reused = isinstance(self.hmap, DynamicMap) and self.overlaid
if not reused and element is None:
element = self._get_frame(key)
Expand Down
8 changes: 8 additions & 0 deletions holoviews/tests/plotting/bokeh/testcallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ def test_rangexy_datetime(self):
self.assertEqual(stream.x_range[1], curve.iloc[3, 0])
self.assertEqual(stream.y_range, (0.2, 0.8))

def test_rangexy_framewise_reset(self):
stream = RangeXY(x_range=(0, 2), y_range=(0, 1))
curve = DynamicMap(lambda z, x_range, y_range: Curve([1, 2, z]),
kdims=['z'], streams=[stream]).redim.range(z=(0, 3))
plot = bokeh_server_renderer.get_plot(curve.opts(framewise=True))
plot.update((1,))
self.assertEqual(stream.y_range, None)


class TestBokehCustomJSCallbacks(CallbackTestCase):

Expand Down

0 comments on commit 90bd54b

Please sign in to comment.