Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle through text_color when overlaying Labels #5888

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(0, 3)}
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
).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(0, 3)}
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
).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(0, 3)}
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
).overlay()
assert isinstance(hm[0].opts["color"], Cycle)
Loading