forked from pyecharts/pyecharts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_grid.py
More file actions
73 lines (61 loc) · 2.27 KB
/
test_grid.py
File metadata and controls
73 lines (61 loc) · 2.27 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
from unittest.mock import patch
from nose.tools import assert_equal, assert_in
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Line
def _chart_for_grid() -> Bar:
x_data = ["{}月".format(i) for i in range(1, 13)]
bar = (
Bar()
.add_xaxis(x_data)
.add_yaxis(
"蒸发量",
[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
yaxis_index=0,
)
.add_yaxis(
"降水量",
[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
yaxis_index=1,
)
.extend_axis(yaxis=opts.AxisOpts(name="蒸发量", type_="value", position="right"))
.extend_axis(yaxis=opts.AxisOpts(type_="value", name="温度", position="left"))
.set_global_opts(
yaxis_opts=opts.AxisOpts(name="降水量", position="right", offset=80)
)
)
line = (
Line()
.add_xaxis(x_data)
.add_yaxis(
"平均温度",
[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
yaxis_index=2,
color="#675bba",
label_opts=opts.LabelOpts(is_show=False),
)
)
bar.overlap(line)
return bar
def test_grid_control_axis_index():
bar = _chart_for_grid()
gc = Grid().add(
bar, opts.GridOpts(pos_left="5%", pos_right="20%"), is_control_axis_index=True
)
expected_idx = (0, 1, 2)
for idx, series in enumerate(gc.options.get("series")):
assert_equal(series.get("yAxisIndex"), expected_idx[idx])
def test_grid_do_not_control_axis_index():
bar = _chart_for_grid()
gc = Grid().add(bar, opts.GridOpts(pos_left="5%", pos_right="20%"))
expected_idx = (0, 0, 0)
for idx, series in enumerate(gc.options.get("series")):
assert_equal(series.get("yAxisIndex"), expected_idx[idx])
@patch("pyecharts.render.engine.write_utf8_html_file")
def test_grid_options(fake_writer):
bar = _chart_for_grid()
gc = Grid().add(
bar, opts.GridOpts(pos_left="5%", pos_right="20%", is_contain_label=True)
)
gc.render()
_, content = fake_writer.call_args[0]
assert_in("containLabel", content)