Skip to content

Commit 281ca27

Browse files
committed
Added SankeyOptions.link_color_mode support.
1 parent 64a0300 commit 281ca27

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

highcharts_core/options/plot_options/sankey.py

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from typing import Optional
2+
3+
from validator_collection import validators
4+
5+
from highcharts_core import errors
16
from highcharts_core.options.plot_options.dependencywheel import DependencyWheelOptions
27

38

@@ -28,4 +33,108 @@ class SankeyOptions(DependencyWheelOptions):
2833
:align: center
2934
3035
"""
31-
pass
36+
def __init__(self, **kwargs):
37+
self._link_color_mode = None
38+
39+
self.link_color_mode = kwargs.get('link_color_mode', None)
40+
41+
super().__init__(**kwargs)
42+
43+
@property
44+
def link_color_mode(self) -> Optional[str]:
45+
"""Determines color mode for sankey links.
46+
47+
Available options:
48+
49+
* ``'from'`` - color of the sankey link will be the same as the ``.from`` node
50+
* ``'gradient'`` - color of the sankey link will be set to gradient between
51+
colors of the ``.from`` node and the ``.to`` node
52+
* ``'to'`` - color of the sankey link will be same as the ``.to``
53+
54+
Defaults to ``'from'``.
55+
56+
:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
57+
"""
58+
return self._link_color_mode
59+
60+
@link_color_mode.setter
61+
def link_color_mode(self, value):
62+
if not value:
63+
self._link_color_mode = None
64+
else:
65+
value = validators.string(value)
66+
value = value.lower()
67+
if value not in ['from', 'gradient', 'to']:
68+
raise errors.HighchartsValueError(
69+
f'link_color_mode expects a value of either "from", '
70+
f'"gradient", or "to". Received "{value}"')
71+
self._link_color_mode = value
72+
73+
@classmethod
74+
def _get_kwargs_from_dict(cls, as_dict):
75+
kwargs = {
76+
'accessibility': as_dict.get('accessibility', None),
77+
'allow_point_select': as_dict.get('allowPointSelect', None),
78+
'animation': as_dict.get('animation', None),
79+
'class_name': as_dict.get('className', None),
80+
'clip': as_dict.get('clip', None),
81+
'color': as_dict.get('color', None),
82+
'cursor': as_dict.get('cursor', None),
83+
'custom': as_dict.get('custom', None),
84+
'dash_style': as_dict.get('dashStyle', None),
85+
'data_labels': as_dict.get('dataLabels', None),
86+
'description': as_dict.get('description', None),
87+
'enable_mouse_tracking': as_dict.get('enableMouseTracking', None),
88+
'events': as_dict.get('events', None),
89+
'include_in_data_export': as_dict.get('includeInDataExport', None),
90+
'keys': as_dict.get('keys', None),
91+
'label': as_dict.get('label', None),
92+
'legend_symbol': as_dict.get('legendSymbol', None),
93+
'linked_to': as_dict.get('linkedTo', None),
94+
'marker': as_dict.get('marker', None),
95+
'on_point': as_dict.get('onPoint', None),
96+
'opacity': as_dict.get('opacity', None),
97+
'point': as_dict.get('point', None),
98+
'point_description_formatter': as_dict.get('pointDescriptionFormatter', None),
99+
'selected': as_dict.get('selected', None),
100+
'show_checkbox': as_dict.get('showCheckbox', None),
101+
'show_in_legend': as_dict.get('showInLegend', None),
102+
'skip_keyboard_navigation': as_dict.get('skipKeyboardNavigation', None),
103+
'sonification': as_dict.get('sonification', None),
104+
'states': as_dict.get('states', None),
105+
'sticky_tracking': as_dict.get('stickyTracking', None),
106+
'threshold': as_dict.get('threshold', None),
107+
'tooltip': as_dict.get('tooltip', None),
108+
'turbo_threshold': as_dict.get('turboThreshold', None),
109+
'visible': as_dict.get('visible', None),
110+
111+
'border_color': as_dict.get('borderColor', None),
112+
'border_width': as_dict.get('borderWidth', None),
113+
'center': as_dict.get('center', None),
114+
'center_in_category': as_dict.get('centerInCategory', None),
115+
'color_by_point': as_dict.get('colorByPoint', None),
116+
'color_index': as_dict.get('colorIndex', None),
117+
'colors': as_dict.get('colors', None),
118+
'curve_factor': as_dict.get('curveFactor', None),
119+
'levels': as_dict.get('levels', None),
120+
'link_opacity': as_dict.get('linkOpacity', None),
121+
'min_link_width': as_dict.get('minLinkWidth', None),
122+
'node_padding': as_dict.get('nodePadding', None),
123+
'node_width': as_dict.get('nodeWidth', None),
124+
'start_angle': as_dict.get('startAngle', None),
125+
126+
'link_color_mode': as_dict.get('linkColorMode', None),
127+
}
128+
129+
return kwargs
130+
131+
def _to_untrimmed_dict(self, in_cls = None) -> dict:
132+
untrimmed = {
133+
'linkColorMode': self.link_color_mode,
134+
}
135+
parent_as_dict = super()._to_untrimmed_dict(in_cls = in_cls)
136+
137+
for key in parent_as_dict:
138+
untrimmed[key] = parent_as_dict[key]
139+
140+
return untrimmed

highcharts_core/options/series/sankey.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def _get_kwargs_from_dict(cls, as_dict):
177177
'node_padding': as_dict.get('nodePadding', None),
178178
'node_width': as_dict.get('nodeWidth', None),
179179
'start_angle': as_dict.get('startAngle', None),
180+
181+
'link_color_mode': as_dict.get('linkColorMode', None),
180182

181183
'nodes': as_dict.get('nodes', None),
182184
}

0 commit comments

Comments
 (0)