forked from pyecharts/pyecharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bar.py
187 lines (158 loc) · 5.46 KB
/
test_bar.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python
# coding=utf-8
from __future__ import unicode_literals
import random
from test.constants import CLOTHES
from pyecharts import Bar
clothes_v1 = [5, 20, 36, 10, 75, 90]
clothes_v2 = [10, 25, 8, 60, 20, 80]
def test_bar_stack():
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", CLOTHES, clothes_v1, is_stack=True)
bar.add("商家B", CLOTHES, clothes_v2, is_stack=True)
bar.chart_id = "id_chart_id"
html_content = bar._repr_html_()
assert "id_chart_id" == bar.chart_id
assert "dataZoom" not in html_content
assert "stack_" in html_content
def test_bar_marks():
bar = Bar("标记线和标记点示例")
bar.add("商家A", CLOTHES, clothes_v1, mark_point=["average"])
bar.add("商家B", CLOTHES, clothes_v2, mark_line=["min", "max"])
assert '"average"' in bar._repr_html_()
def test_bar_convert_xy_axis():
bar = Bar("x 轴和 y 轴交换")
bar.add("商家A", CLOTHES, clothes_v1)
bar.add("商家B", CLOTHES, clothes_v2, is_convert=True)
assert "average" not in bar._repr_html_()
def test_bar_histogram():
bar = Bar("直方图示例")
bar.add("", CLOTHES * 2, clothes_v1 + clothes_v2, bar_category_gap=0)
bar.render()
def test_bar_rotate_label():
days = ["{}天".format(i) for i in range(20)]
days_v1 = [random.randint(1, 20) for _ in range(20)]
bar = Bar("坐标轴标签旋转示例")
bar.add(
"", days, days_v1, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30
)
assert "stack_" not in bar._repr_html_()
def test_bar_waterfall():
months = ["{}月".format(i) for i in range(1, 8)]
months_v1 = [0, 100, 200, 300, 400, 220, 250]
months_v2 = [1000, 800, 600, 500, 450, 400, 300]
bar = Bar("瀑布图示例")
bar.add(
"", months, months_v1, label_color=["rgba(0,0,0,0)"], is_stack=True
)
bar.add(
"月份",
months,
months_v2,
is_label_show=True,
is_stack=True,
label_pos="inside",
)
bar.render()
def test_bar_datazoom_undefined():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom 默认 示例")
bar.add("", days, days_v1, is_label_show=True, is_datazoom_show=True)
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "slider"' in html_content
assert ': "inside"' not in html_content
def test_bar_datazoom_slider():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom 示例")
bar.add(
"",
days,
days_v1,
is_datazoom_show=True,
datazoom_type="slider",
datazoom_range=[10, 25],
)
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "slider"' in html_content
assert ': "inside"' not in html_content
def test_bar_datazoom_inside():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom - inside 示例")
bar.add(
"",
days,
days_v1,
is_datazoom_show=True,
datazoom_type="inside",
datazoom_range=[10, 25],
)
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "inside"' in html_content
assert ': "slider"' not in html_content
def test_bar_datazoom_both():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom - both 示例")
bar.add(
"",
days,
days_v1,
is_datazoom_show=True,
datazoom_type="both",
datazoom_range=[10, 25],
is_toolbox_show=False,
)
assert len(bar.options.get("dataZoom")) == 2
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "inside"' in html_content
assert ': "slider"' in html_content
def test_bar_datazoom_xaxis_and_yaxis():
days = ["{}天".format(i) for i in range(30)]
days_v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("Bar - datazoom - xaxis/yaxis 示例")
bar.add(
"",
days,
days_v1,
# 默认为 X 轴,横向
is_datazoom_show=True,
datazoom_type="slider",
datazoom_range=[10, 25],
# 新增额外的 dataZoom 控制条,纵向
is_datazoom_extra_show=True,
datazoom_extra_type="slider",
datazoom_extra_range=[10, 25],
is_toolbox_show=False,
)
assert len(bar.options.get("dataZoom")) == 2
html_content = bar._repr_html_()
assert "dataZoom" in html_content
assert ': "slider"' in html_content
assert ': "vertical"' in html_content
assert ': "horizontal"' in html_content
def test_bar_extra_html_text_label():
bar = Bar("柱状图", extra_html_text_label=["bar_extra_html_text_label"])
bar.add("商家A", CLOTHES, clothes_v1, is_stack=True)
bar.add("商家B", CLOTHES, clothes_v2, is_stack=True)
html_content = bar._repr_html_()
assert '<p style="">bar_extra_html_text_label</p>' in html_content
def test_bar_line_color_and_with():
bar = Bar("柱状图")
bar.add(
"商家A",
CLOTHES,
clothes_v1,
xaxis_line_color="green",
xaxis_line_width=5,
xaxis_label_textcolor="black",
)
html_content = bar._repr_html_()
assert '"color": "green"' in html_content
assert '"width": 5' in html_content