1
1
from typing import Optional
2
+ from decimal import Decimal
2
3
3
4
from validator_collection import validators
4
5
@@ -36,9 +37,11 @@ class SankeyOptions(DependencyWheelOptions):
36
37
def __init__ (self , ** kwargs ):
37
38
self ._link_color_mode = None
38
39
self ._node_alignment = None
40
+ self ._node_distance = None
39
41
40
42
self .link_color_mode = kwargs .get ('link_color_mode' , None )
41
43
self .node_alignment = kwargs .get ('node_alignment' , None )
44
+ self .node_distance = kwargs .get ('node_distance' , None )
42
45
43
46
super ().__init__ (** kwargs )
44
47
@@ -104,6 +107,72 @@ def node_alignment(self, value):
104
107
f'"bottom". Received "{ value } "' )
105
108
self ._node_alignment = value
106
109
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
+
148
+ @property
149
+ def node_width (self ) -> Optional [str | int | float | Decimal ]:
150
+ """The pixel width of each node in a sankey diagram, or the height in case
151
+ the chart is inverted. Defaults to ``20``.
152
+
153
+ Can be a number, a percentage string, or ``'auto'``. If ``'auto'``, the nodes
154
+ are sized to fill up the plot area in the longitudinal direction, regardless
155
+ of the number of levels.
156
+
157
+ :rtype: :class:`str <python:str>` or numeric or :obj:`None <python:None>`
158
+ """
159
+ return self ._node_width
160
+
161
+ @node_width .setter
162
+ def node_width (self , value ):
163
+ if value is None :
164
+ self ._node_width = None
165
+ else :
166
+ try :
167
+ value = validators .string (value )
168
+ value = value .lower ()
169
+ if value != 'auto' and "%" not in value :
170
+ raise ValueError
171
+ except (TypeError , ValueError ):
172
+ value = validators .numeric (value )
173
+
174
+ self ._node_width = value
175
+
107
176
@classmethod
108
177
def _get_kwargs_from_dict (cls , as_dict ):
109
178
kwargs = {
@@ -159,6 +228,7 @@ def _get_kwargs_from_dict(cls, as_dict):
159
228
160
229
'link_color_mode' : as_dict .get ('linkColorMode' , None ),
161
230
'node_alignment' : as_dict .get ('nodeAlignment' , None ),
231
+ 'node_distance' : as_dict .get ('nodeDistance' , None ),
162
232
}
163
233
164
234
return kwargs
@@ -167,6 +237,7 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
167
237
untrimmed = {
168
238
'linkColorMode' : self .link_color_mode ,
169
239
'nodeAlignment' : self .node_alignment ,
240
+ 'nodeDistance' : self .node_distance ,
170
241
}
171
242
parent_as_dict = super ()._to_untrimmed_dict (in_cls = in_cls )
172
243
0 commit comments