Skip to content

Commit afd2318

Browse files
committed
Implemented diagram series .node_width properties.
1 parent 4c12726 commit afd2318

File tree

4 files changed

+100
-9
lines changed

4 files changed

+100
-9
lines changed

highcharts_core/options/plot_options/arcdiagram.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,32 @@ def min_link_width(self, value):
221221
minimum = 0)
222222

223223
@property
224-
def node_width(self) -> Optional[int | float | Decimal]:
224+
def node_width(self) -> Optional[str | int | float | Decimal]:
225225
"""The pixel width of each node in a sankey diagram or dependency wheel, or the
226-
height in case the chart is inverted. Defaults to ``20``.
226+
height in case the chart is inverted.
227227
228-
:rtype: numeric or :obj:`None <python:None>`
228+
Can be a number or a percentage string.
229+
230+
Defaults to ``20``.
231+
232+
:rtype: :class:`str <python:str>` or numeric or :obj:`None <python:None>`
229233
"""
230234
return self._node_width
231235

232236
@node_width.setter
233237
def node_width(self, value):
238+
if value is None:
239+
self._node_width = None
240+
else:
241+
try:
242+
value = validators.string(value)
243+
if "%" not in value:
244+
raise ValueError
245+
except (TypeError, ValueError):
246+
value = validators.numeric(value)
247+
248+
self._node_width = value
249+
234250
self._node_width = validators.numeric(value,
235251
allow_empty = True,
236252
minimum = 0)

highcharts_core/options/plot_options/dependencywheel.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,31 @@ def node_padding(self, value):
277277
allow_empty = True)
278278

279279
@property
280-
def node_width(self) -> Optional[int | float | Decimal]:
280+
def node_width(self) -> Optional[str | int | float | Decimal]:
281281
"""The pixel width of each node in a sankey diagram or dependency wheel, or the
282-
height in case the chart is inverted. Defaults to ``20``.
282+
height in case the chart is inverted.
283283
284-
:rtype: numeric or :obj:`None <python:None>`
284+
Can be a number or a percentage string.
285+
286+
Defaults to ``20``.
287+
288+
:rtype: :class:`str <python:str>` or numeric or :obj:`None <python:None>`
285289
"""
286290
return self._node_width
287291

288292
@node_width.setter
289293
def node_width(self, value):
290-
self._node_width = validators.numeric(value,
291-
allow_empty = True,
292-
minimum = 0)
294+
if value is None:
295+
self._node_width = None
296+
else:
297+
try:
298+
value = validators.string(value)
299+
if "%" not in value:
300+
raise ValueError
301+
except (TypeError, ValueError):
302+
value = validators.numeric(value)
303+
304+
self._node_width = value
293305

294306
@property
295307
def start_angle(self) -> Optional[int | float | Decimal]:

highcharts_core/options/plot_options/sankey.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,34 @@ def node_distance(self, value):
145145

146146
self._node_distance = value
147147

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+
148176
@classmethod
149177
def _get_kwargs_from_dict(cls, as_dict):
150178
kwargs = {

highcharts_core/options/plot_options/treegraph.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __init__(self, **kwargs):
123123

124124
self._levels = None
125125
self._node_distance = None
126+
self._node_width = None
126127

127128
self.animation_limit = kwargs.get('animation_limit', None)
128129
self.boost_blending = kwargs.get('boost_blending', None)
@@ -150,6 +151,7 @@ def __init__(self, **kwargs):
150151

151152
self.levels = kwargs.get('levels', None)
152153
self.node_distance = kwargs.get('node_distance', None)
154+
self.node_width = kwargs.get('node_width', None)
153155

154156
super().__init__(**kwargs)
155157

@@ -690,6 +692,37 @@ def node_distance(self, value):
690692

691693
self._node_distance = value
692694

695+
@property
696+
def node_width(self) -> Optional[str | int | float | Decimal]:
697+
"""The pixel width of each node in a treegraph, or the height in case the chart is
698+
inverted. Defaults to :obj:`None <python:None>`.
699+
700+
For tree graphs, the node width is only applied if the marker symbol is ``'rect'``,
701+
otherwise the marker sizing options apply.
702+
703+
Can be a number or a percentage string, or ``'auto'``. If ``'auto'``, the nodes are
704+
sized to fill up the plot area in the longitudinal direction, regardless of the
705+
number of levels.
706+
707+
:rtype: :class:`str <python:str>` or numeric or :obj:`None <python:None>`
708+
"""
709+
return self._node_width
710+
711+
@node_width.setter
712+
def node_width(self, value):
713+
if value is None:
714+
self._node_width = None
715+
else:
716+
try:
717+
value = validators.string(value)
718+
value = value.lower()
719+
if value != "auto" and "%" not in value:
720+
raise ValueError
721+
except (TypeError, ValueError):
722+
value = validators.numeric(value)
723+
724+
self._node_width = value
725+
693726
@classmethod
694727
def _get_kwargs_from_dict(cls, as_dict):
695728
"""Convenience method which returns the keyword arguments used to initialize the
@@ -764,6 +797,7 @@ class from a Highcharts Javascript-compatible :class:`dict <python:dict>` object
764797
'reversed': as_dict.get('reversed', None),
765798
'levels': as_dict.get('levels', None),
766799
'node_distance': as_dict.get('nodeDistance', None),
800+
'node_width': as_dict.get('nodeWidth', None),
767801
}
768802

769803
return kwargs
@@ -829,6 +863,7 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
829863
'reversed': self.reversed,
830864
'levels': self.levels,
831865
'nodeDistance': self.node_distance,
866+
'nodeWidth': self.node_width,
832867
}
833868

834869
return untrimmed

0 commit comments

Comments
 (0)