Skip to content

Commit

Permalink
Fix overlay of two-level categorical plots and HLine (#5203)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Feb 7, 2022
1 parent 4c46d73 commit bad936e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
16 changes: 9 additions & 7 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import sys
import warnings

from itertools import chain
from types import FunctionType

import param
Expand Down Expand Up @@ -2317,13 +2319,13 @@ def _get_factors(self, overlay, ranges):
if el is not None:
elranges = util.match_spec(el, ranges)
xfs, yfs = sp._get_factors(el, elranges)
xfactors.append(xfs)
yfactors.append(yfs)
if xfactors:
xfactors = np.concatenate(xfactors)
if yfactors:
yfactors = np.concatenate(yfactors)
return util.unique_array(xfactors), util.unique_array(yfactors)
if len(xfs):
xfactors.append(xfs)
if len(yfs):
yfactors.append(yfs)
xfactors = list(util.unique_iterator(chain(*xfactors)))
yfactors = list(util.unique_iterator(chain(*yfactors)))
return xfactors, yfactors


def _get_axis_dims(self, element):
Expand Down
14 changes: 12 additions & 2 deletions holoviews/tests/plotting/bokeh/testoverlayplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from holoviews.core import NdOverlay, HoloMap, DynamicMap, Overlay
from holoviews.core.options import Cycle
from holoviews.element import Curve, Points, ErrorBars, Scatter, Text, VLine
from holoviews.element import Bars, Curve, ErrorBars, HLine, Points, Scatter, Text, VLine
from holoviews.streams import Stream, Tap
from holoviews.util import Dynamic

from ...utils import LoggingComparisonTestCase
from .testplot import TestBokehPlot, bokeh_renderer

try:
from bokeh.models import FixedTicker, HoverTool, FactorRange, Range1d
from bokeh.models import FixedTicker, HoverTool, FactorRange, Span, Range1d
except:
pass

Expand Down Expand Up @@ -192,6 +192,16 @@ def test_points_errorbars_text_ndoverlay_categorical_xaxis(self):
for xs, factor in zip(error_plot.handles['source'].data['base'], factors):
self.assertEqual(factor, xs)

def test_overlay_categorical_two_level(self):
bars = Bars([('A', 'a', 1), ('B', 'b', 2), ('A', 'b', 3), ('B', 'a', 4)],
kdims=['Upper', 'Lower'])

plot = bokeh_renderer.get_plot(bars * HLine(2))
x_range = plot.handles['x_range']
assert isinstance(x_range, FactorRange)
assert x_range.factors == [('A', 'a'), ('A', 'b'), ('B', 'a'), ('B', 'b')]
assert isinstance(plot.state.renderers[-1], Span)

def test_points_errorbars_text_ndoverlay_categorical_xaxis_invert_axes(self):
overlay = NdOverlay({i: Points(([chr(65+i)]*10,np.random.randn(10)))
for i in range(5)})
Expand Down

0 comments on commit bad936e

Please sign in to comment.