Skip to content

Commit

Permalink
Fixes when specifying both data_aspect and responsive modes (#3575)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Mar 25, 2019
1 parent 643df2c commit 031a39a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
16 changes: 8 additions & 8 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,14 @@ def _update_ranges(self, element, ranges):
plot.frame_height = int(width/aspect)
plot.plot_width, plot.plot_height = None, None
else:
plot.aspect_ratio = aspect

box_zoom = plot.select(type=tools.BoxZoomTool)
scroll_zoom = plot.select(type=tools.WheelZoomTool)
if box_zoom:
box_zoom.match_aspect = True
if scroll_zoom:
scroll_zoom.zoom_on_axis = False
plot.aspect_ratio = 1./aspect

box_zoom = plot.select(type=tools.BoxZoomTool)
scroll_zoom = plot.select(type=tools.WheelZoomTool)
if box_zoom:
box_zoom.match_aspect = True
if scroll_zoom:
scroll_zoom.zoom_on_axis = False

if not self.drawn or xupdate:
self._update_range(x_range, l, r, xfactors, self.invert_xaxis,
Expand Down
7 changes: 6 additions & 1 deletion holoviews/plotting/bokeh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ def compute_layout_properties(
height = None
if fixed_height or not fixed_width:
width = None
aspect_scale = 1 if aspect == 'equal' else data_aspect

aspect_scale = data_aspect
if aspect == 'equal':
aspect_scale = 1
elif responsive:
aspect_ratio = aspect
elif isnumeric(aspect):
if responsive:
aspect_ratio = aspect
Expand Down
19 changes: 16 additions & 3 deletions holoviews/tests/plotting/bokeh/testelementplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,24 @@ def test_element_frame_width_frame_height_responsive(self):
self.log_handler.assertContains('WARNING', "responsive mode could not be enabled")

def test_element_data_aspect_responsive(self):
curve = Curve([0, 0.5, 1, 1.5]).opts(data_aspect=2, responsive=True)
curve = Curve([0, 2]).opts(data_aspect=1, responsive=True)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.aspect_ratio, 1)
self.assertEqual(plot.state.aspect_scale, 2)
self.assertEqual(plot.state.aspect_ratio, 0.5)
self.assertEqual(plot.state.aspect_scale, 1)
self.assertEqual(plot.state.sizing_mode, 'scale_both')

def test_element_data_aspect_and_aspect_responsive(self):
curve = Curve([0, 2]).opts(data_aspect=1, aspect=2, responsive=True)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.aspect_ratio, 2)
self.assertEqual(plot.state.aspect_scale, 1)
self.assertEqual(plot.state.sizing_mode, 'scale_both')
x_range = plot.handles['x_range']
y_range = plot.handles['y_range']
self.assertEqual(x_range.start, -1.5)
self.assertEqual(x_range.end, 2.5)
self.assertEqual(y_range.start, 0)
self.assertEqual(y_range.end, 2)

def test_element_data_aspect_width_responsive(self):
curve = Curve([0, 0.5, 1, 1.5]).opts(data_aspect=2, width=400, responsive=True)
Expand Down

0 comments on commit 031a39a

Please sign in to comment.