graph.py
2.9 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
81
82
83
84
85
86
87
88
89
90
91
92
from ... import options as opts
from ... import types
from ...charts.chart import Chart
from ...globals import ChartType
class Graph(Chart):
"""
<<< Graph >>>
The graph is used to represent the relational data.
"""
def add(
self,
series_name: str,
nodes: types.Sequence[types.GraphNode],
links: types.Sequence[types.GraphLink],
categories: types.Union[types.Sequence[types.GraphCategory], None] = None,
*,
is_selected: bool = True,
is_focusnode: bool = True,
is_roam: bool = True,
is_draggable: bool = False,
is_rotate_label: bool = False,
layout: str = "force",
symbol: types.Optional[str] = None,
symbol_size: types.Numeric = 10,
edge_length: types.Numeric = 50,
gravity: types.Numeric = 0.2,
repulsion: types.Numeric = 50,
edge_label: types.Label = None,
edge_symbol: types.Union[types.Sequence[str], str] = None,
edge_symbol_size: types.Numeric = 10,
label_opts: types.Label = opts.LabelOpts(),
linestyle_opts: types.LineStyle = opts.LineStyleOpts(),
tooltip_opts: types.Tooltip = None,
itemstyle_opts: types.ItemStyle = None,
):
_nodes = []
for n in nodes:
if isinstance(n, opts.GraphNode):
n = n.opts
_nodes.append(n)
_links = []
for link in links:
if isinstance(link, opts.GraphLink):
link = link.opts
_links.append(link)
if categories:
for c in categories:
if isinstance(c, opts.GraphCategory):
c = c.opts
self._append_legend(c.get("name", ""), is_selected)
if edge_label is None:
edge_label = opts.LabelOpts(is_show=False)
if edge_symbol is None:
edge_symbol = [None, None]
self.options.get("series").append(
{
"type": ChartType.GRAPH,
"name": series_name,
"layout": layout,
"symbol": symbol,
"symbolSize": symbol_size,
"circular": {"rotateLabel": is_rotate_label},
"force": {
"repulsion": repulsion,
"edgeLength": edge_length,
"gravity": gravity,
},
"label": label_opts,
"lineStyle": linestyle_opts,
"roam": is_roam,
"draggable": is_draggable,
"focusNodeAdjacency": is_focusnode,
"data": _nodes,
"categories": categories,
"edgeLabel": edge_label,
"edgeSymbol": edge_symbol,
"edgeSymbolSize": edge_symbol_size,
"links": _links,
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
}
)
return self