forked from pyecharts/pyecharts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sankey.py
More file actions
70 lines (63 loc) · 2.13 KB
/
test_sankey.py
File metadata and controls
70 lines (63 loc) · 2.13 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
from unittest.mock import patch
from nose.tools import assert_equal, assert_in
from pyecharts import options as opts
from pyecharts.charts import Sankey
@patch("pyecharts.render.engine.write_utf8_html_file")
def test_sankey_base(fake_writer):
nodes = [{"name": "category1"}, {"name": "category2"}, {"name": "category3"}]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
]
c = Sankey().add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
c.render()
_, content = fake_writer.call_args[0]
assert_equal(c.theme, "white")
assert_equal(c.renderer, "canvas")
@patch("pyecharts.render.engine.write_utf8_html_file")
def test_sankey_new_opts(fake_writer):
nodes = [
{"name": "a"},
{"name": "b"},
{"name": "a1"},
{"name": "b1"},
{"name": "c"},
{"name": "e"},
]
links = [
{"source": "a", "target": "a1", "value": 5},
{"source": "e", "target": "b", "value": 3},
{"source": "a", "target": "b1", "value": 3},
{"source": "b1", "target": "a1", "value": 1},
{"source": "b1", "target": "c", "value": 2},
{"source": "b", "target": "c", "value": 1},
]
c = Sankey().add(
"sankey",
nodes,
links,
pos_bottom="10%",
focus_node_adjacency="allEdges",
orient="vertical",
levels=[
opts.SankeyLevelsOpts(
depth=0,
itemstyle_opts=opts.ItemStyleOpts(color="#eee"),
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
)
],
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
c.render()
_, content = fake_writer.call_args[0]
assert_in("bottom", content)
assert_in("orient", content)
assert_in("levels", content)
assert_in("focusNodeAdjacency", content)