Repository: holoviz/holoviews

Issue:
Hover tool disappears when flipping axis
It is nice having the default hover tool as support. However it disappears when flipping the axis of an image.

Below is code that will generate am html page showing proper behavior in one tab and the bug in another tab.

```
import numpy as np
import holoviews as hv
import panel as pn
from holoviews import opts
from bokeh.resources import INLINE
from holoviews.operation.datashader import rasterize
from matplotlib.cm import  PuBu

hv.extension('bokeh')
np.random.seed(1)
Matrix = np.random.random((1000,1000))

PlotData  = hv.Image(Matrix)  
ShadedBase = rasterize (PlotData, aggregator = 'max', interpolation = 'linear', dynamic  = False)
Shaded = ShadedBase.redim.label(x='X axis ',y='Time', z= 'Value' ).opts(cmap=PuBu, title = 'Working Well ' , xaxis='top', yaxis='left', height=1000, width=1000, tools=['hover'], toolbar = None, axiswise=True) 
ShadedFlipped = ShadedBase.redim.label(x='X axis ',y='Time', z= 'Value' ).opts(cmap=PuBu, title = 'Bug - No hover tool when Y axis is flipped' , invert_yaxis=True, xaxis='top', yaxis='left', height=1000, width=1000, tools=['hover'], toolbar = None, axiswise=True) 

out = pn.layout.Tabs( ( 'Hover tool Working Well',Shaded ),
                       ( 'Hover tool Not working with flipped axis', ShadedFlipped)
                      )

out.save('TestAxisFlip', resources=INLINE) 

```

I am using Python 3.7.4, holoviews 1.12.3 , Bokeh 1.3.4 

Hopefully there is a simple fix.






Discussion:
This is a bokeh issue afaik, but I'll leave it open here for now.
Thanks Philipp,

Can you elaborate,  I am not sure how exactly it is redirected to Bokeh, so
more details will be helpful.

This is a minor issue since it only means that the plots will be flipped,
yet if its a problem in Bokeh, is it worthwhile reporting it there?

I'll be happy to do so using the same example.

         Jacob

On Sun, Sep 29, 2019 at 12:45 PM Philipp Rudiger <notifications@github.com>
wrote:

> This is a bokeh issue afaik, but I'll leave it open here for now.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pyviz/holoviews/issues/4006?email_source=notifications&email_token=AAPE42ZSBDFXSVBYC6HLKR3QMDSUFA5CNFSM4I3OMIW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD732Q5A#issuecomment-536324212>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAPE423MRXR23M3VDXTSWK3QMDSUFANCNFSM4I3OMIWQ>
> .
>


Resolving patch:
diff --git a/holoviews/plotting/bokeh/raster.py b/holoviews/plotting/bokeh/raster.py
--- a/holoviews/plotting/bokeh/raster.py
+++ b/holoviews/plotting/bokeh/raster.py
@@ -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):
@@ -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)


Test patch:
diff --git a/holoviews/tests/plotting/bokeh/testrasterplot.py b/holoviews/tests/plotting/bokeh/testrasterplot.py
--- a/holoviews/tests/plotting/bokeh/testrasterplot.py
+++ b/holoviews/tests/plotting/bokeh/testrasterplot.py
@@ -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]])
@@ -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):
@@ -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)
 
@@ -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))
@@ -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])