Skip to content

Commit

Permalink
Generalized concept of implicit categories
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 13, 2020
1 parent d5912c2 commit c2cdda2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 2 additions & 6 deletions holoviews/plotting/bokeh/annotation.py
Expand Up @@ -138,6 +138,7 @@ class LineAnnotationPlot(ElementPlot, AnnotationPlot):
apply_ranges = param.Boolean(default=False, doc="""
Whether to include the annotation in axis range calculations.""")

_allow_implicit_categories = False
_plot_methods = dict(single='Span')

def get_data(self, element, ranges, style):
Expand Down Expand Up @@ -171,9 +172,6 @@ def get_extents(self, element, ranges=None, range_type='combined'):
ranges[dim]['soft'] = loc, loc
return super(LineAnnotationPlot, self).get_extents(element, ranges, range_type)

def _get_factors(self, element, ranges):
return [], []


class BoxAnnotationPlot(ElementPlot, AnnotationPlot):

Expand All @@ -182,6 +180,7 @@ class BoxAnnotationPlot(ElementPlot, AnnotationPlot):

style_opts = line_properties + fill_properties + ['level', 'visible']

_allow_implicit_categories = False
_plot_methods = dict(single='BoxAnnotation')

def get_data(self, element, ranges, style):
Expand All @@ -207,9 +206,6 @@ def _init_glyph(self, plot, mapping, properties):
plot.renderers.append(box)
return None, box

def _get_factors(self, element, ranges):
return [], []


class SlopePlot(ElementPlot, AnnotationPlot):

Expand Down
4 changes: 4 additions & 0 deletions holoviews/plotting/bokeh/element.py
Expand Up @@ -177,6 +177,7 @@ class ElementPlot(BokehPlot, GenericElementPlot):
Formatter for ticks along the x-axis.""")

_categorical = False
_allow_implicit_categories = True

# Declare which styles cannot be mapped to a non-scalar dimension
_nonvectorized_styles = []
Expand Down Expand Up @@ -953,6 +954,9 @@ def _get_factors(self, element, ranges):
else:
yvals = element.dimension_values(1, False)
xvals, yvals = np.asarray(xvals), np.asarray(yvals)
if not self._allow_implicit_categories:
xvals = xvals if xvals.dtype.kind in 'SU' else []
yvals = yvals if yvals.dtype.kind in 'SU' else []
coords = tuple([v if vals.dtype.kind in 'SU' else dim.pprint_value(v) for v in vals]
for dim, vals in [(xdim, xvals), (ydim, yvals)])
if self.invert_axes: coords = coords[::-1]
Expand Down
8 changes: 2 additions & 6 deletions holoviews/plotting/bokeh/geometry.py
Expand Up @@ -23,6 +23,7 @@ class SegmentPlot(GeomMixin, ColorbarPlot):

style_opts = base_properties + line_properties + ['cmap']

_allow_implicit_categories = False
_nonvectorized_styles = base_properties + ['cmap']
_plot_methods = dict(single='segment')

Expand All @@ -33,9 +34,6 @@ def get_data(self, element, ranges, style):
mapping = dict(x0='x0', x1='x1', y0='y0', y1='y1')
return (data, mapping, style)

def _get_factors(self, element, ranges):
return [], []


class RectanglesPlot(GeomMixin, LegendPlot, ColorbarPlot):

Expand All @@ -48,6 +46,7 @@ class RectanglesPlot(GeomMixin, LegendPlot, ColorbarPlot):
style_opts = (base_properties + line_properties + fill_properties +
['cmap'])

_allow_implicit_categories = False
_nonvectorized_styles = base_properties + ['cmap']
_plot_methods = dict(single='rect')
_batched_style_opts = line_properties + fill_properties
Expand All @@ -61,6 +60,3 @@ def get_data(self, element, ranges, style):
data = {'x': (x1+x0)/2., 'y': (y1+y0)/2., 'width': x1-x0, 'height': y1-y0}
mapping = {'x': 'x', 'y': 'y', 'width': 'width', 'height': 'height'}
return data, mapping, style

def _get_factors(self, element, ranges):
return [], []

0 comments on commit c2cdda2

Please sign in to comment.