tree.py
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from ... import options as opts
from ... import types
from ...charts.chart import Chart
from ...globals import ChartType
class Tree(Chart):
"""
<<< Tree diagrams >>>
Tree diagrams are used primarily to visualize tree data structures,
which are special hierarchical types with unique root nodes, left subtrees,
and right subtrees.
"""
@staticmethod
def _set_collapse_interval(data, interval):
"""
间隔折叠节点,当节点过多时可以解决节点显示过杂间隔。
:param data: 节点数据
:param interval: 指定间隔
"""
if interval <= 0:
return data
if data and isinstance(data, list):
for d in data:
children = d.get("children", None)
if children and interval > 0:
for index, value in enumerate(children):
if index % interval == 0:
value.update(collapsed="false")
return data
def add(
self,
series_name: str,
data: types.Sequence[types.Union[opts.TreeItem, dict]],
*,
layout: str = "orthogonal",
symbol: str = "emptyCircle",
symbol_size: types.Numeric = 7,
orient: str = "LR",
pos_top: types.Optional[str] = None,
pos_left: types.Optional[str] = None,
pos_bottom: types.Optional[str] = None,
pos_right: types.Optional[str] = None,
collapse_interval: types.Numeric = 0,
is_roam: bool = False,
is_expand_and_collapse: bool = True,
initial_tree_depth: types.Optional[types.Numeric] = None,
label_opts: types.Label = opts.LabelOpts(),
leaves_label_opts: types.Label = opts.LabelOpts(),
tooltip_opts: types.Tooltip = None,
itemstyle_opts: types.ItemStyle = None,
):
_data = self._set_collapse_interval(data, collapse_interval)
self.options.get("series").append(
{
"type": ChartType.TREE,
"name": series_name,
"data": _data,
"left": pos_left,
"right": pos_right,
"top": pos_top,
"bottom": pos_bottom,
"symbol": symbol,
"symbolSize": symbol_size,
"roam": is_roam,
"expandAndCollapse": is_expand_and_collapse,
"initialTreeDepth": initial_tree_depth,
"layout": layout,
"orient": orient,
"label": label_opts,
"leaves": {"label": leaves_label_opts},
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
}
)
return self