Skip to content

Commit ac1fc1f

Browse files
committed
Implemented SankeyOptions.node_distance
1 parent 354af37 commit ac1fc1f

File tree

1 file changed

+43
-0
lines changed
  • highcharts_core/options/plot_options

1 file changed

+43
-0
lines changed

highcharts_core/options/plot_options/sankey.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Optional
2+
from decimal import Decimal
23

34
from validator_collection import validators
45

@@ -36,9 +37,11 @@ class SankeyOptions(DependencyWheelOptions):
3637
def __init__(self, **kwargs):
3738
self._link_color_mode = None
3839
self._node_alignment = None
40+
self._node_distance = None
3941

4042
self.link_color_mode = kwargs.get('link_color_mode', None)
4143
self.node_alignment = kwargs.get('node_alignment', None)
44+
self.node_distance = kwargs.get('node_distance', None)
4245

4346
super().__init__(**kwargs)
4447

@@ -104,6 +107,44 @@ def node_alignment(self, value):
104107
f'"bottom". Received "{value}"')
105108
self._node_alignment = value
106109

110+
@property
111+
def node_distance(self) -> Optional[str | int | float | Decimal]:
112+
"""The distance between nodes in a sankey diagram in the longitudinal direction.
113+
Defaults to ``30``.
114+
115+
.. note::
116+
117+
The longitudinal direction means the direction that the chart flows - in a
118+
horizontal chart the distance is horizontal, in an inverted chart (vertical),
119+
the distance is vertical.
120+
121+
If a number is given, it denotes pixels. If a percentage string is given, the
122+
distance is a percentage of the rendered node width. A value of 100% will render
123+
equal widths for the nodes and the gaps between them.
124+
125+
.. note::
126+
127+
This option applies only when the ``.node_width`` option is ``'auto'``, making
128+
the node width respond to the number of columns.
129+
130+
:rtype: :class:`str <python:str>` or numeric or :obj:`None <python:None>`
131+
"""
132+
return self._node_distance
133+
134+
@node_distance.setter
135+
def node_distance(self, value):
136+
if value is None:
137+
self._node_distance = None
138+
else:
139+
try:
140+
value = validators.string(value)
141+
if "%" not in value:
142+
raise ValueError
143+
except (TypeError, ValueError):
144+
value = validators.numeric(value)
145+
146+
self._node_distance = value
147+
107148
@classmethod
108149
def _get_kwargs_from_dict(cls, as_dict):
109150
kwargs = {
@@ -159,6 +200,7 @@ def _get_kwargs_from_dict(cls, as_dict):
159200

160201
'link_color_mode': as_dict.get('linkColorMode', None),
161202
'node_alignment': as_dict.get('nodeAlignment', None),
203+
'node_distance': as_dict.get('nodeDistance', None),
162204
}
163205

164206
return kwargs
@@ -167,6 +209,7 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
167209
untrimmed = {
168210
'linkColorMode': self.link_color_mode,
169211
'nodeAlignment': self.node_alignment,
212+
'nodeDistance': self.node_distance,
170213
}
171214
parent_as_dict = super()._to_untrimmed_dict(in_cls = in_cls)
172215

0 commit comments

Comments
 (0)