Skip to content

Commit

Permalink
Correctly check if hover data should be added (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed May 14, 2018
1 parent e131d7a commit 969fced
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 23 deletions.
10 changes: 4 additions & 6 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import numpy as np
import param
from bokeh.models import (CategoricalColorMapper, CustomJS, HoverTool,
Whisker, Range1d)
from bokeh.models import CategoricalColorMapper, CustomJS, Whisker, Range1d
from bokeh.models.tools import BoxSelectTool
from bokeh.transform import jitter

Expand Down Expand Up @@ -125,7 +124,7 @@ def get_batched_data(self, element, ranges):
for k, v in sdata.items():
data[k].append(v)

if any(isinstance(t, HoverTool) for t in self.state.tools):
if 'hover' in self.handles:
for dim, k in zip(element.dimensions(), key):
sanitized = dimension_sanitizer(dim.name)
data[sanitized].append([k]*nvals)
Expand Down Expand Up @@ -605,7 +604,7 @@ def get_data(self, element, ranges, style):
mapping['color'] = {'field': cdim.name,
'transform': cmapper}

if any(isinstance(t, HoverTool) for t in self.state.tools) and not self.static_source:
if 'hover' in self.handles and not self.static_source:
for d in dims:
data[dimension_sanitizer(d)] = element.dimension_values(d)

Expand Down Expand Up @@ -824,8 +823,7 @@ def get_data(self, element, ranges, style):
# Define style information
width = style.get('bar_width', style.get('width', 1))
cmap = style.get('cmap')
hover = any(t == 'hover' or isinstance(t, HoverTool)
for t in self.tools+self.default_tools)
hover = 'hover' in self.handles

# Group by stack or group dim if necessary
if group_dim is None:
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _get_hover_data(self, data, element, dimensions=None):
Initializes hover data based on Element dimension values.
If empty initializes with no data.
"""
if not any(isinstance(t, HoverTool) for t in self.state.tools) or self.static_source:
if 'hover' not in self.handles or self.static_source:
return

for d in (dimensions or element.dimensions()):
Expand Down
5 changes: 2 additions & 3 deletions holoviews/plotting/bokeh/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import param
import numpy as np
from bokeh.models import HoverTool, ColumnDataSource
from bokeh.models import (StaticLayoutProvider, NodesAndLinkedEdges,
EdgesAndLinkedNodes, Patches, Bezier)
EdgesAndLinkedNodes, Patches, Bezier, ColumnDataSource)

from ...core.data import Dataset
from ...core.util import (basestring, dimension_sanitizer, unique_array,
Expand Down Expand Up @@ -200,7 +199,7 @@ def get_data(self, element, ranges, style):
edge_mapping.update(pmapping)

# Get hover data
if any(isinstance(t, HoverTool) for t in self.state.tools):
if 'hover' in self.handles:
if self.inspection_policy == 'nodes':
index_dim = element.nodes.get_dimension(2)
point_data['index_hover'] = [index_dim.pprint_value(v) for v in element.nodes.dimension_values(2)]
Expand Down
6 changes: 3 additions & 3 deletions holoviews/plotting/bokeh/heatmap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import param
import numpy as np

from bokeh.models import HoverTool, Span
from bokeh.models import Span
from bokeh.models.glyphs import AnnularWedge

from ...core.util import is_nan, dimension_sanitizer
Expand Down Expand Up @@ -90,7 +90,7 @@ def get_data(self, element, ranges, style):
yvals = [ydim.pprint_value(yv) for yv in yvals]
data = {x: xvals, y: yvals, 'zvalues': zvals}

if any(isinstance(t, HoverTool) for t in self.state.tools) and not self.static_source:
if 'hover' in self.handles and not self.static_source:
for vdim in element.vdims:
sanitized = dimension_sanitizer(vdim.name)
data[sanitized] = ['-' if is_nan(v) else vdim.pprint_value(v)
Expand Down Expand Up @@ -533,7 +533,7 @@ def get_data(self, element, ranges, style):
"outer_radius": outer_radius,
z: zvals, x: xvals, y: yvals}

if any(isinstance(t, HoverTool) for t in self.state.tools):
if 'hover' in self.handles:
for vdim in element.vdims:
sanitized = dimension_sanitizer(vdim.name)
values = ['-' if is_nan(v) else vdim.pprint_value(v)
Expand Down
6 changes: 2 additions & 4 deletions holoviews/plotting/bokeh/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import param
import numpy as np

from bokeh.models import HoverTool

from ...core import util
from .element import ColorbarPlot, LegendPlot, line_properties, fill_properties
from .util import expand_batched_style
Expand Down Expand Up @@ -39,7 +37,7 @@ def _get_hover_data(self, data, element):
"""
Initializes hover data based on Element dimension values.
"""
if not any(isinstance(t, HoverTool) for t in self.state.tools) or self.static_source:
if 'hover' not in self.handles or self.static_source:
return

for k, v in self.overlay_dims.items():
Expand Down Expand Up @@ -129,7 +127,7 @@ def _get_hover_data(self, data, element):
Initializes hover data based on Element dimension values.
If empty initializes with no data.
"""
if not any(isinstance(t, HoverTool) for t in self.state.tools) or self.static_source:
if 'hover' not in self.handles or self.static_source:
return

for d in element.vdims:
Expand Down
3 changes: 1 addition & 2 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import param

from bokeh.models import HoverTool
from ...core.util import cartesian_product, dimension_sanitizer
from ...element import Raster, RGB, HSV
from .element import ElementPlot, ColorbarPlot, line_properties, fill_properties
Expand Down Expand Up @@ -170,7 +169,7 @@ def get_data(self, element, ranges, style):
zvals = zdata.flatten() if self.invert_axes else zdata.T.flatten()
data = {'left': x0, 'right': x1, dimension_sanitizer(z.name): zvals,
'bottom': y0, 'top': y1}
if any(isinstance(t, HoverTool) for t in self.state.tools) and not self.static_source:
if 'hover' in self.handles and not self.static_source:
data[dimension_sanitizer(x.name)] = element.dimension_values(x)
data[dimension_sanitizer(y.name)] = element.dimension_values(y)
return data, mapping, style
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/sankey.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import param
import numpy as np

from bokeh.models import Patches, HoverTool
from bokeh.models import Patches

from ...core.data import Dataset
from ...core.util import basestring, max_range, dimension_sanitizer
Expand Down Expand Up @@ -124,7 +124,7 @@ def _patch_hover(self, element, data):
"""
Replace edge start and end hover data with label_index data.
"""
if not (self.inspection_policy == 'edges' and any(isinstance(t, HoverTool) for t in self.state.tools)):
if not (self.inspection_policy == 'edges' and 'hover' in self.handles):
return
lidx = element.nodes.get_dimension(self.label_index)
src, tgt = [dimension_sanitizer(kd.name) for kd in element.kdims[:2]]
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import param
import numpy as np

from bokeh.models import FactorRange, HoverTool, Circle, VBar, HBar
from bokeh.models import FactorRange, Circle, VBar, HBar

from ...core.dimension import Dimension
from ...core.util import (basestring, dimension_sanitizer, wrap_tuple,
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_data(self, element, ranges, style):
label = label[0]
else:
label = key
hover = any(isinstance(t, HoverTool) for t in self.state.tools)
hover = 'hover' in self.handles

# Add color factor
if cidx is not None and cidx<element.ndims:
Expand Down

0 comments on commit 969fced

Please sign in to comment.