Skip to content

Commit

Permalink
Cycle through text_color when overlaying Labels (#5888)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Sep 18, 2023
1 parent 0b76098 commit 0dad517
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def colormap_generator(palette):
options.VSpan = Options('style', color=Cycle(), alpha=0.5)
options.HSpan = Options('style', color=Cycle(), alpha=0.5)
options.Arrow = Options('style', arrow_size=10)
options.Labels = Options('style', text_align='center', text_baseline='middle')
options.Labels = Options('style', text_color=Cycle(), text_align='center', text_baseline='middle')

# Graphs
options.Graph = Options(
Expand Down
1 change: 1 addition & 0 deletions holoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def grid_selector(grid):
options.VSpan = Options('style', alpha=0.5, facecolor=Cycle())
options.HSpan = Options('style', alpha=0.5, facecolor=Cycle())
options.Spline = Options('style', edgecolor=Cycle())
options.Labels = Options('style', color=Cycle())

options.Arrow = Options('style', color='k', linewidth=2, textsize=13)
# Paths
Expand Down
1 change: 1 addition & 0 deletions holoviews/plotting/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
# Annotations
options.VSpan = Options('style', fillcolor=Cycle(), opacity=0.5)
options.HSpan = Options('style', fillcolor=Cycle(), opacity=0.5)
options.Labels = Options('style', color=Cycle())

# Shapes
options.Rectangles = Options('style', line_color=dflt_shape_line_color)
Expand Down
11 changes: 11 additions & 0 deletions holoviews/tests/plotting/bokeh/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from holoviews.core.dimension import Dimension
from holoviews.element import Labels
from holoviews.core.spaces import HoloMap
from holoviews.plotting.bokeh.util import property_to_dict
from holoviews.core.options import Cycle

from bokeh.models import LinearColorMapper, CategoricalColorMapper

Expand Down Expand Up @@ -186,3 +188,12 @@ def test_labels_color_index_color_clash(self):
"color_index.\n"
)
self.assertEqual(log_msg, warning)

def test_labels_text_color_cycle(self):
hm = HoloMap(
{i: Labels([
(0, 0 + i, "Label 1"),
(1, 1 + i, "Label 2")
]) for i in range(3)}
).overlay()
assert isinstance(hm[0].opts["text_color"], Cycle)
10 changes: 10 additions & 0 deletions holoviews/tests/plotting/matplotlib/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from holoviews.core.dimension import Dimension
from holoviews.core.spaces import HoloMap
from holoviews.element import Labels
from holoviews.core.options import Cycle
from holoviews.plotting.util import rgb2hex

from .test_plot import TestMPLPlot, mpl_renderer
Expand Down Expand Up @@ -171,3 +172,12 @@ def test_label_rotation_op_update(self):
artist = plot.handles['artist']
self.assertEqual([a.get_rotation() for a in artist],
[30, 120, 60])

def test_labels_text_color_cycle(self):
hm = HoloMap(
{i: Labels([
(0, 0 + i, "Label 1"),
(1, 1 + i, "Label 2")
]) for i in range(3)}
).overlay()
assert isinstance(hm[0].opts["color"], Cycle)
11 changes: 11 additions & 0 deletions holoviews/tests/plotting/plotly/test_labelplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np

from holoviews.element import Labels, Tiles
from holoviews.core.options import Cycle
from holoviews.core.spaces import HoloMap

from .test_plot import TestPlotlyPlot

Expand Down Expand Up @@ -132,3 +134,12 @@ def test_visible(self):
element = Tiles("") * Labels([(0, 3, 0), (1, 2, 1), (2, 1, 1)]).opts(visible=False)
state = self._get_plot_state(element)
self.assertEqual(state['data'][1]['visible'], False)

def test_labels_text_color_cycle(self):
hm = HoloMap(
{i: Labels([
(0, 0 + i, "Label 1"),
(1, 1 + i, "Label 2")
]) for i in range(3)}
).overlay()
assert isinstance(hm[0].opts["color"], Cycle)

0 comments on commit 0dad517

Please sign in to comment.