sankey.py
2.3 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
from ... import options as opts
from ... import types
from ...charts.chart import Chart
from ...globals import ChartType
class Sankey(Chart):
"""
<<< Sankey >>>
Sankey diagram is a special flow diagram, which is mainly used to
express how raw materials, energy and so on from the initial form through
the intermediate process of processing, transformation to the final form.
"""
def add(
self,
series_name: str,
nodes: types.Sequence,
links: types.Sequence,
*,
is_selected: bool = True,
pos_left: types.Union[str, types.Numeric] = "5%",
pos_top: types.Union[str, types.Numeric] = "5%",
pos_right: types.Union[str, types.Numeric] = "20%",
pos_bottom: types.Union[str, types.Numeric] = "5%",
node_width: types.Numeric = 20,
node_gap: types.Numeric = 8,
node_align: str = "justify",
layout_iterations: types.Numeric = 32,
orient: str = "horizontal",
is_draggable: bool = True,
focus_node_adjacency: types.Union[bool, str] = False,
levels: types.SankeyLevel = None,
label_opts: types.Label = opts.LabelOpts(),
linestyle_opt: types.LineStyle = opts.LineStyleOpts(),
tooltip_opts: types.Tooltip = None,
itemstyle_opts: types.ItemStyle = None,
):
if layout_iterations < 32:
layout_iterations = 32
self._append_legend(series_name, is_selected)
self.options.get("series").append(
{
"type": ChartType.SANKEY,
"name": series_name,
"data": nodes,
"links": links,
"left": pos_left,
"top": pos_top,
"right": pos_right,
"bottom": pos_bottom,
"nodeWidth": node_width,
"nodeGap": node_gap,
"nodeAlign": node_align,
"layoutIteration": layout_iterations,
"orient": orient,
"draggable": is_draggable,
"focusNodeAdjacency": focus_node_adjacency,
"levels": levels,
"label": label_opts,
"lineStyle": linestyle_opt,
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
}
)
return self