11from typing import Optional
2+ from decimal import Decimal
23
34from 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,72 @@ 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+
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+
107176 @classmethod
108177 def _get_kwargs_from_dict (cls , as_dict ):
109178 kwargs = {
@@ -159,6 +228,7 @@ def _get_kwargs_from_dict(cls, as_dict):
159228
160229 'link_color_mode' : as_dict .get ('linkColorMode' , None ),
161230 'node_alignment' : as_dict .get ('nodeAlignment' , None ),
231+ 'node_distance' : as_dict .get ('nodeDistance' , None ),
162232 }
163233
164234 return kwargs
@@ -167,6 +237,7 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
167237 untrimmed = {
168238 'linkColorMode' : self .link_color_mode ,
169239 'nodeAlignment' : self .node_alignment ,
240+ 'nodeDistance' : self .node_distance ,
170241 }
171242 parent_as_dict = super ()._to_untrimmed_dict (in_cls = in_cls )
172243
0 commit comments