Skip to content

Commit

Permalink
Fixed hover bug when plotting on inverted axis (#4010)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 2, 2019
1 parent dbed242 commit 3e7d955
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def get_data(self, element, ranges, style):
if self.invert_axes:
l, b, r, t = b, l, t, r

dh, dw = t-b, r-l
if self.invert_xaxis:
l, r = r, l
if self.invert_yaxis:
b, t = t, b
dh, dw = t-b, r-l
data = dict(x=[l], y=[b], dw=[dw], dh=[dh])

for i, vdim in enumerate(element.vdims, 2):
Expand Down Expand Up @@ -166,13 +166,14 @@ def get_data(self, element, ranges, style):
if self.invert_axes:
img = img.T
l, b, r, t = b, l, t, r

dh, dw = t-b, r-l
if self.invert_xaxis:
l, r = r, l
img = img[:, ::-1]
if self.invert_yaxis:
img = img[::-1]
b, t = t, b
dh, dw = t-b, r-l

if 0 in img.shape:
img = np.zeros((1, 1), dtype=np.uint32)
Expand Down
10 changes: 5 additions & 5 deletions holoviews/tests/plotting/bokeh/testrasterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_raster_invert_axes(self):
self.assertEqual(source.data['x'][0], 0)
self.assertEqual(source.data['y'][0], 3)
self.assertEqual(source.data['dw'][0], 2)
self.assertEqual(source.data['dh'][0], -3)
self.assertEqual(source.data['dh'][0], 3)

def test_image_invert_axes(self):
arr = np.array([[0, 1, 2], [3, 4, 5]])
Expand All @@ -54,7 +54,7 @@ def test_image_invert_xaxis(self):
self.assertEqual(cdata['x'], [0.5])
self.assertEqual(cdata['y'], [-0.5])
self.assertEqual(cdata['dh'], [1.0])
self.assertEqual(cdata['dw'], [-1.0])
self.assertEqual(cdata['dw'], [1.0])
self.assertEqual(cdata['image'][0], arr[::-1, ::-1])

def test_image_invert_yaxis(self):
Expand All @@ -67,7 +67,7 @@ def test_image_invert_yaxis(self):
cdata = plot.handles['source'].data
self.assertEqual(cdata['x'], [-0.5])
self.assertEqual(cdata['y'], [0.5])
self.assertEqual(cdata['dh'], [-1.0])
self.assertEqual(cdata['dh'], [1.0])
self.assertEqual(cdata['dw'], [1.0])
self.assertEqual(cdata['image'][0], arr)

Expand All @@ -81,7 +81,7 @@ def test_rgb_invert_xaxis(self):
self.assertEqual(cdata['x'], [0.5])
self.assertEqual(cdata['y'], [-0.5])
self.assertEqual(cdata['dh'], [1.0])
self.assertEqual(cdata['dw'], [-1.0])
self.assertEqual(cdata['dw'], [1.0])

def test_rgb_invert_yaxis(self):
rgb = RGB(np.random.rand(10, 10, 3)).opts(plot=dict(invert_yaxis=True))
Expand All @@ -92,5 +92,5 @@ def test_rgb_invert_yaxis(self):
cdata = plot.handles['source'].data
self.assertEqual(cdata['x'], [-0.5])
self.assertEqual(cdata['y'], [0.5])
self.assertEqual(cdata['dh'], [-1.0])
self.assertEqual(cdata['dh'], [1.0])
self.assertEqual(cdata['dw'], [1.0])

0 comments on commit 3e7d955

Please sign in to comment.