Skip to content

Commit

Permalink
Fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 22, 2019
1 parent e466eff commit 1821c1e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
7 changes: 7 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ def _plot_properties(self, key, element):
pass
elif self.data_aspect or self.aspect == 'equal':
match_aspect = True
if fixed_width or not fixed_height:
height = None
if fixed_height or not fixed_width:
width = None
aspect_scale = 1 if self.aspect == 'equal' else self.data_aspect
if self.dynamic:
# Sync the plot size on dynamic plots to support accurate
Expand Down Expand Up @@ -864,6 +868,7 @@ def _update_ranges(self, element, ranges):
xaxis, yaxis = self.handles['xaxis'], self.handles['yaxis']
categorical = isinstance(xaxis, CategoricalAxis) or isinstance(yaxis, CategoricalAxis)
datetime = isinstance(xaxis, DatetimeAxis) or isinstance(yaxis, CategoricalAxis)

if data_aspect and fixed_width and fixed_height:
pass
elif data_aspect and (categorical or datetime):
Expand Down Expand Up @@ -911,9 +916,11 @@ def _update_ranges(self, element, ranges):
if fixed_height:
plot.frame_height = height
plot.frame_width = int(height*aspect)
plot.plot_width, plot.plot_height = None, None
elif fixed_width:
plot.frame_width = width
plot.frame_height = int(width/aspect)
plot.plot_width, plot.plot_height = None, None
else:
plot.aspect_ratio = aspect

Expand Down
38 changes: 32 additions & 6 deletions holoviews/tests/plotting/bokeh/testelementplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,71 +376,91 @@ def test_active_tools_draw_stream(self):
def test_element_aspect(self):
curve = Curve([1, 2, 3]).opts(aspect=2)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 300)
self.assertEqual(plot.state.frame_width, 600)
self.assertEqual(plot.state.aspect_ratio, None)

def test_element_aspect_width(self):
curve = Curve([1, 2, 3]).opts(aspect=2, width=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 200)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_ratio, None)

def test_element_aspect_height(self):
curve = Curve([1, 2, 3]).opts(aspect=2, height=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 800)
self.assertEqual(plot.state.aspect_ratio, None)

def test_element_aspect_width_height(self):
curve = Curve([1, 2, 3]).opts(aspect=2, height=400, width=400)
plot = bokeh_renderer.get_plot(curve)
self.log_handler.assertContains('WARNING', "aspect value was ignored")
self.assertEqual(plot.state.plot_height, 400)
self.assertEqual(plot.state.plot_width, 400)
self.assertEqual(plot.state.frame_height, None)
self.assertEqual(plot.state.frame_width, None)
self.assertEqual(plot.state.aspect_ratio, None)
self.log_handler.assertContains('WARNING', "aspect value was ignored")

def test_element_aspect_frame_width(self):
curve = Curve([1, 2, 3]).opts(aspect=2, frame_width=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 200)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_ratio, None)

def test_element_aspect_frame_height(self):
curve = Curve([1, 2, 3]).opts(aspect=2, frame_height=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 800)
self.assertEqual(plot.state.aspect_ratio, None)

def test_element_aspect_frame_width_frame_height(self):
curve = Curve([1, 2, 3]).opts(aspect=2, frame_height=400, frame_width=400)
plot = bokeh_renderer.get_plot(curve)
self.log_handler.assertContains('WARNING', "aspect value was ignored")
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_ratio, None)
self.log_handler.assertContains('WARNING', "aspect value was ignored")

def test_element_data_aspect(self):
curve = Curve([0, 0.5, 1, 1.5]).opts(data_aspect=2)
curve = Curve([0, 0.5, 1, 1.5]).opts(data_aspect=1.5)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 300)
self.assertEqual(plot.state.frame_width, 300)
self.assertEqual(plot.state.aspect_scale, 2)
self.assertEqual(plot.state.frame_width, 225)
self.assertEqual(plot.state.aspect_scale, 1.5)

def test_element_data_aspect_width(self):
curve = Curve([0, 0.5, 1, 1.5]).opts(data_aspect=2, width=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_scale, 2)

def test_element_data_aspect_height(self):
curve = Curve([0, 0.5, 1, 1.5]).opts(data_aspect=2, height=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_scale, 2)
Expand All @@ -456,24 +476,30 @@ def test_element_data_aspect_width_height(self):
def test_element_data_aspect_frame_width(self):
curve = Curve([1, 2, 3]).opts(data_aspect=2, frame_width=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 200)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_scale, 2)

def test_element_data_aspect_frame_height(self):
curve = Curve([1, 2, 3]).opts(data_aspect=2, frame_height=400)
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 800)
self.assertEqual(plot.state.aspect_scale, 2)

def test_element_data_aspect_frame_width_frame_height(self):
curve = Curve([1, 2, 3]).opts(data_aspect=2, frame_height=400, frame_width=400)
plot = bokeh_renderer.get_plot(curve)
self.log_handler.assertContains('WARNING', "data_aspect value was ignored")
self.assertEqual(plot.state.plot_height, None)
self.assertEqual(plot.state.plot_width, None)
self.assertEqual(plot.state.frame_height, 400)
self.assertEqual(plot.state.frame_width, 400)
self.assertEqual(plot.state.aspect_scale, 1)
self.log_handler.assertContains('WARNING', "data_aspect value was ignored")

#################################################################
# Aspect tests
Expand Down

0 comments on commit 1821c1e

Please sign in to comment.