Skip to content

Commit 4c12726

Browse files
committed
Implemented TreegraphOptions.node_distance.
1 parent ac1fc1f commit 4c12726

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

highcharts_core/options/plot_options/treegraph.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(self, **kwargs):
122122
self._traverse_up_button = None
123123

124124
self._levels = None
125+
self._node_distance = None
125126

126127
self.animation_limit = kwargs.get('animation_limit', None)
127128
self.boost_blending = kwargs.get('boost_blending', None)
@@ -148,6 +149,7 @@ def __init__(self, **kwargs):
148149
self.reversed = kwargs.get('reversed', None)
149150

150151
self.levels = kwargs.get('levels', None)
152+
self.node_distance = kwargs.get('node_distance', None)
151153

152154
super().__init__(**kwargs)
153155

@@ -649,7 +651,45 @@ def levels(self) -> Optional[List[TreegraphLevelOptions]]:
649651
@class_sensitive(TreegraphLevelOptions)
650652
def levels(self, value):
651653
self._levels = value
652-
654+
655+
@property
656+
def node_distance(self) -> Optional[str | int | float | Decimal]:
657+
"""The distance between nodes in a treegraph diagram in the longitudinal
658+
direction. Defaults to ``30``.
659+
660+
.. note::
661+
662+
The longitudinal direction means the direction that the chart flows - in a
663+
horizontal chart the distance is horizontal, in an inverted chart (vertical),
664+
the distance is vertical.
665+
666+
If a number is given, it denotes pixels. If a percentage string is given, the
667+
distance is a percentage of the rendered node width. A value of 100% will render
668+
equal widths for the nodes and the gaps between them.
669+
670+
.. note::
671+
672+
This option applies only when the ``.node_width`` option is ``'auto'``, making
673+
the node width respond to the number of columns.
674+
675+
:rtype: :class:`str <python:str>` or numeric or :obj:`None <python:None>`
676+
"""
677+
return self._node_distance
678+
679+
@node_distance.setter
680+
def node_distance(self, value):
681+
if value is None:
682+
self._node_distance = None
683+
else:
684+
try:
685+
value = validators.string(value)
686+
if "%" not in value:
687+
raise ValueError
688+
except (TypeError, ValueError):
689+
value = validators.numeric(value)
690+
691+
self._node_distance = value
692+
653693
@classmethod
654694
def _get_kwargs_from_dict(cls, as_dict):
655695
"""Convenience method which returns the keyword arguments used to initialize the
@@ -723,6 +763,7 @@ class from a Highcharts Javascript-compatible :class:`dict <python:dict>` object
723763
'link': as_dict.get('link', None),
724764
'reversed': as_dict.get('reversed', None),
725765
'levels': as_dict.get('levels', None),
766+
'node_distance': as_dict.get('nodeDistance', None),
726767
}
727768

728769
return kwargs
@@ -787,6 +828,7 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
787828
'link': self.link,
788829
'reversed': self.reversed,
789830
'levels': self.levels,
831+
'nodeDistance': self.node_distance,
790832
}
791833

792834
return untrimmed

0 commit comments

Comments
 (0)