4
4
import sys
5
5
import json
6
6
import codecs
7
+ import random
8
+
7
9
from test .constants import RANGE_COLOR , CLOTHES , WEEK
8
10
from pyecharts import (
9
11
Bar ,
@@ -53,7 +55,7 @@ def test_page_add_chart():
53
55
)
54
56
55
57
56
- def create_three ():
58
+ def create_three_charts ():
57
59
page = Page (page_title = TEST_PAGE_TITLE )
58
60
59
61
# bar
@@ -65,8 +67,6 @@ def create_three():
65
67
page .add (bar )
66
68
67
69
# scatter3D
68
- import random
69
-
70
70
data = [
71
71
[
72
72
random .randint (0 , 100 ),
@@ -98,12 +98,12 @@ def create_three():
98
98
99
99
@raises (NotImplementedError )
100
100
def test_no_image_rendering_for_page ():
101
- page = create_three ()
101
+ page = create_three_charts ()
102
102
page .render (path = "page.png" )
103
103
104
104
105
105
def test_two_bars ():
106
- page = create_three ()
106
+ page = create_three_charts ()
107
107
page .render ()
108
108
with codecs .open ("render.html" , "r" , "utf-8" ) as f :
109
109
actual_content = f .read ()
@@ -119,7 +119,7 @@ def test_two_bars():
119
119
120
120
121
121
def test_page_get_js_dependencies ():
122
- page = create_three ()
122
+ page = create_three_charts ()
123
123
dependencies = page .get_js_dependencies ()
124
124
eq_ (dependencies [0 ], "echarts.min" )
125
125
assert "guangdong" in dependencies
@@ -128,14 +128,14 @@ def test_page_get_js_dependencies():
128
128
129
129
130
130
def test_page_embed ():
131
- page = create_three ()
131
+ page = create_three_charts ()
132
132
html = page .render_embed ()
133
133
assert "<html>" not in html
134
134
assert json .dumps ("柱状图数据堆叠示例" ) in html
135
135
136
136
137
137
def test_page_in_notebook ():
138
- page = create_three ()
138
+ page = create_three_charts ()
139
139
html = page ._repr_html_ ()
140
140
141
141
assert "echartsgl" in html
@@ -148,7 +148,7 @@ def test_page_in_notebook():
148
148
assert echarts_position < guangdong_position
149
149
150
150
151
- def test_more ():
151
+ def test_more_charts ():
152
152
page = Page ()
153
153
154
154
# line
@@ -251,8 +251,6 @@ def test_more():
251
251
page .add (radar )
252
252
253
253
# scatter3d
254
- import random
255
-
256
254
data = [
257
255
[
258
256
random .randint (0 , 100 ),
@@ -325,3 +323,46 @@ def test_more():
325
323
or ("echarts.min" in page .js_dependencies )
326
324
)
327
325
page .render ()
326
+
327
+
328
+ def test_page_extra_html_text_label ():
329
+ page = Page ()
330
+ line = Line (
331
+ "折线图示例" , extra_html_text_label = ["LINE TEXT LABEL" , "color:red" ]
332
+ )
333
+ line .add (
334
+ "最高气温" ,
335
+ WEEK ,
336
+ [11 , 11 , 15 , 13 , 12 , 13 , 10 ],
337
+ mark_point = ["max" , "min" ],
338
+ mark_line = ["average" ],
339
+ )
340
+ page .add (line )
341
+
342
+ v1 = [11 , 12 , 13 , 10 , 10 , 10 ]
343
+ pie = Pie (
344
+ "饼图-圆环图示例" ,
345
+ title_pos = "center" ,
346
+ extra_html_text_label = ["PIE TEXT LABEL" ],
347
+ )
348
+ pie .add (
349
+ "" ,
350
+ CLOTHES ,
351
+ v1 ,
352
+ radius = [40 , 75 ],
353
+ label_text_color = None ,
354
+ is_label_show = True ,
355
+ legend_orient = "vertical" ,
356
+ legend_pos = "left" ,
357
+ )
358
+ page .add (pie )
359
+
360
+ v2 = [10 , 25 , 8 , 60 , 20 , 80 ]
361
+ bar = Bar ("柱状图" , extra_html_text_label = ["BAR TEXT LABEL" ])
362
+ bar .add ("商家B" , CLOTHES , v2 )
363
+ page .add (bar )
364
+
365
+ html_content = page ._repr_html_ ()
366
+ assert '<p style="">BAR TEXT LABEL</p>' in html_content
367
+ assert '<p style="color:red">LINE TEXT LABEL</p>' in html_content
368
+ assert '<p style="">PIE TEXT LABEL</p>' in html_content
0 commit comments