forked from pyecharts/pyecharts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_map.py
More file actions
88 lines (73 loc) · 3 KB
/
test_map.py
File metadata and controls
88 lines (73 loc) · 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# coding=utf-8
from __future__ import unicode_literals
import json
import codecs
from pyecharts import Map
def test_map_show_label():
# show label
value = [155, 10, 66, 78]
attr = ["福建", "山东", "北京", "上海"]
map = Map("全国地图示例", width=1200, height=600)
map.add("", attr, value, maptype='china', is_label_show=True)
map.render()
def test_map_combine_with_visualmap():
value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]
attr = ["福建", "山东", "北京", "上海", "甘肃",
"新疆", "河南", "广西", "西藏"]
map = Map("Map 结合 VisualMap 示例", width=1200, height=600)
map.add("", attr, value, maptype='china', is_visualmap=True,
visual_text_color='#000')
map.render()
def test_echarts_position_in_render_html():
value = [20, 190, 253, 77, 65]
attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
map = Map("广东地图示例", width=1200, height=600)
map.add("", attr, value, maptype='广东', is_map_symbol_show=False,
is_visualmap=True, visual_text_color='#000')
map.render()
with codecs.open('render.html', 'r', 'utf-8') as f:
actual_content = f.read()
echarts_position = actual_content.find('exports.echarts')
guangdong_position = actual_content.find(json.dumps('广东'))
assert echarts_position < guangdong_position
assert '"showLegendSymbol": false' in actual_content
def test_city_map():
value = [1]
attr = ["渝水区"]
map = Map("新余地图示例", width=1200, height=600)
map.add("", attr, value, maptype='新余', is_visualmap=True,
visual_text_color='#000')
# To avoid potential pinyin crash, all cities have a province prefix
assert "jiang1_xi1_xin1_yu2" in map._repr_html_()
def test_world_map():
value = [95.1, 23.2, 43.3, 66.4, 88.5, 0.1]
attr = [
"China", "Canada", "Brazil", "Russia",
"United States", "Unknown Country"
]
map = Map("世界地图示例", width=1200, height=600)
map.add("", attr, value, maptype="world", is_visualmap=True,
visual_text_color='#000')
map.render()
with codecs.open('render.html', 'r', 'utf-8') as f:
actual_content = f.read()
# test register map
assert "registerMap(\"world\"," in actual_content
# test non-existent country
assert "Russia" in actual_content
assert "Unknown Country', " not in actual_content
def test_china_map():
value = [155, 10, 66, 78]
attr = ["福建", "山东", "北京", "上海"]
map = Map("全国地图示例", width=1200, height=600)
map.add("", attr, value, maptype='china')
map.render()
with codecs.open('render.html', 'r', 'utf-8') as f:
actual_content = f.read()
# test register map
assert "registerMap(\"china\"," in actual_content
# 福建省
assert "\u798f\u5efa" in actual_content
# 汕头市
assert "\u4e0a\u6d77" in actual_content