Geolines data value (#566)

* Update: 更新 x,y 轴 formatter 参数注释

* #565 Geolines 图数据项可以新增数值维度

* Update: charts docs update

* Fix: fixed bronken test

* Update: 更新 github ISSUE 及 PR 提交模板

* Update: lines -> line

* Update: 删除无用语句
This commit is contained in:
陈键冬 2018-05-15 20:32:12 +08:00 committed by chenjiandongx
parent eac3f9f872
commit 8b5dba9c29
7 changed files with 238 additions and 161 deletions

View File

@ -1,5 +1,19 @@
<!--
### 提 issue 注意事项
0. 先仔细阅读文档中是否有关于您需要解决的问题的解决方法
1. 提 issue 前请先搜搜看以往的 issue 有没有解决了您的问题
2. 如若是不能正常使用的问题,请贴上详细的 pyecharts 版本,使用系统以及 Python 版本
3. 最好详细描述问题,必要时加上**代码+贴图**
3. 最好详细描述问题,必要时加上**代码+贴图**
-->
**问题**
**运行环境(系统环境及 pyecharts 版本)**
**代码及截图**

View File

@ -1,6 +1,14 @@
<!--
### 提 PR 注意事项
0. 同步到 dev 分支的最新版本
1. 代码尽量保持与项目统一风格,尽量按照 PEP8 规范写代码,必要时附上注释
2. 如需要时请添加单元测试,也请确保所有测试能够通过
3. 将 PR 推送至远程的 dev 分支master 分支只负责发布新版本。请在提交信息中描述关于该 PR 的详细信息,需要时加上截图。
4. 若是对文档进行修改,请确保数字,字母与中文之间两边均有一空格,如你所看到的整篇文档一样
4. 若是对文档进行修改,请确保数字,字母与中文之间两边均有一空格,如你所看到的所有文档一样
-->
本次 PR 内容,

View File

@ -1,7 +1,9 @@
# 版本日志
* ### version 0.5.5dev
* TODO
### Added
* [issue#565](https://github.com/pyecharts/pyecharts/issues/565) Geolines 图数据项可以新增数值维度
* ### version 0.5.4 - 2018.05.15current

View File

@ -1137,7 +1137,7 @@ add(name, data,
* name -> str
图例名称
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每一行包含两个数据, 如 ["广州", "北京"],则指定从广州到北京
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每一行包含两个或三个数据,如 ["广州", "北京"] 或 ["广州", "北京"100],则指定从广州到北京。第三个值用于表示该 line 的数值,该值可省略
* maptype -> str
地图类型。 从 v0.3.2+ 起,地图已经变为扩展包,支持全国省份,全国城市,全国区县,全球国家等地图,具体请参考 [地图自定义篇](zh-cn/customize_map)
* symbol -> str
@ -1218,6 +1218,26 @@ geolines.render()
```
![geolines-1](https://user-images.githubusercontent.com/19553554/35082102-fd8d884a-fc52-11e7-9e40-5f94098d4493.gif)
指定数值
```python
from pyecharts import GeoLines, Style
data_guangzhou = [
["广州", "上海", 10],
["广州", "北京", 20],
["广州", "南京", 30],
["广州", "重庆", 40],
["广州", "兰州", 50],
["广州", "杭州", 60],
]
lines = GeoLines("GeoLines 示例", **style.init_style)
lines.add(
"从广州出发", data_guangzhou, tooltip_formatter="{a} : {c}", **style_geo
)
lines.render()
```
![](https://user-images.githubusercontent.com/19553554/40048098-eaa7b3aa-5863-11e8-98cd-dcd8526fe820.gif)
多例模式
```python
from pyecharts import GeoLines, Style

View File

@ -40,8 +40,9 @@ class GeoLines(Geo):
:param name:
系列名称用于 tooltip 的显示legend 的图例筛选
:param data:
数据项数据中每一行是一个数据项每一列属于一个维度每一行包含两个数据
["广州", "北京"]则指定从广州到北京
数据项数据中每一行是一个数据项每一列属于一个维度每一行包含两个或
三个数据 ["广州", "北京"] ["广州", "北京"100]则指定从广州到北京
三个值用于表示该 line 的数值该值可省略
:param maptype:
地图类型 v0.3.2+ 地图已经变为扩展包支持全国省份全国城市全国区县
全球国家等地图具体请参考 [地图自定义篇](zh-cn/customize_map)
@ -88,8 +89,15 @@ class GeoLines(Geo):
geo_effect_symbol = SYMBOL["plane"]
_data_lines, _data_scatter = [], []
for d in data:
_from_name, _to_name = d
for element in data:
assert len(element) >= 2
_line_value = None
if len(element) == 2:
_from_name, _to_name = element
else:
_from_name, _to_name, _line_value = element
_from_coordinate = self.get_coordinate(
_from_name, raise_exception=True
)
@ -100,6 +108,7 @@ class GeoLines(Geo):
{
"fromName": _from_name,
"toName": _to_name,
"value": _line_value,
"coords": [_from_coordinate, _to_coordinate],
}
)
@ -161,6 +170,7 @@ class GeoLines(Geo):
"symbolSize": 10,
"data": _data_scatter,
"label": chart["label"],
"tooltip": {"formatter": "{b}"},
}
)

View File

@ -1,289 +1,295 @@
{
"backgroundColor": "#404a59",
"backgroundColor": "#404a59",
"color": [
"#a6c84c",
"#ffa022",
"#46bee9",
"#a6c84c",
"#ffa022",
"#46bee9",
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597",
"#a6c84c",
"#ffa022",
"#46bee9",
"#a6c84c",
"#ffa022",
"#46bee9",
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597",
"#f6f5ec"
],
],
"geo": {
"itemStyle": {
"emphasis": {
"areaColor": "#2a333d"
},
},
"normal": {
"areaColor": "#323c48",
"areaColor": "#323c48",
"borderColor": "#111"
}
},
},
"label": {
"emphasis": {
"show": true,
"show": true,
"textStyle": {
"color": "#eee"
}
}
},
"map": "china",
},
"map": "china",
"roam": true
},
},
"legend": [
{
"data": [
"\u4ece\u5e7f\u5dde\u51fa\u53d1",
"\u4ece\u5e7f\u5dde\u51fa\u53d1",
"\u4ece\u5317\u4eac\u51fa\u53d1"
],
"left": "right",
"orient": "horizontal",
"selectedMode": "single",
"show": true,
],
"left": "right",
"orient": "horizontal",
"selectedMode": "single",
"show": true,
"textStyle": {
"color": "#eee",
"color": "#eee",
"fontSize": 12
},
},
"top": "top"
}
],
],
"series": [
{
"data": [
{
"coords": [
[
113.23,
113.23,
23.16
],
],
[
121.48,
121.48,
31.22
]
],
"fromName": "\u5e7f\u5dde",
],
"fromName": "\u5e7f\u5dde",
"toName": "\u4e0a\u6d77"
}
],
],
"effect": {
"color": "#fff",
"period": 6,
"show": true,
"symbol": "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z",
"symbolSize": 15,
"color": "#fff",
"period": 6,
"show": true,
"symbol": "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z",
"symbolSize": 15,
"trailLength": 0
},
},
"lineStyle": {
"normal": {
"curveness": 0.2,
"opacity": 0.6,
"type": "solid",
"curveness": 0.2,
"opacity": 0.6,
"type": "solid",
"width": 1
}
},
"name": "\u4ece\u5e7f\u5dde\u51fa\u53d1",
},
"name": "\u4ece\u5e7f\u5dde\u51fa\u53d1",
"symbol": [
"none",
"none",
"arrow"
],
"symbolSize": 12,
"type": "lines",
],
"symbolSize": 12,
"type": "lines",
"zlevel": 2
},
},
{
"coordinateSystem": "geo",
"coordinateSystem": "geo",
"data": [
{
"name": "\u5e7f\u5dde",
"name": "\u5e7f\u5dde",
"value": [
113.23,
23.16,
113.23,
23.16,
0
]
},
},
{
"name": "\u4e0a\u6d77",
"name": "\u4e0a\u6d77",
"value": [
121.48,
31.22,
121.48,
31.22,
0
]
}
],
],
"label": {
"emphasis": {
"show": true,
"show": true,
"textStyle": {
"fontSize": 12
}
},
},
"normal": {
"formatter": "{b}",
"position": "right",
"show": true,
"formatter": "{b}",
"position": "right",
"show": true,
"textStyle": {
"color": "#eee",
"color": "#eee",
"fontSize": 12
}
}
},
"name": "\u4ece\u5e7f\u5dde\u51fa\u53d1",
"symbolSize": 10,
"type": "scatter",
},
"name": "\u4ece\u5e7f\u5dde\u51fa\u53d1",
"symbolSize": 10,
"tooltip": {
"formatter": "{b}"
},
"type": "scatter",
"zlevel": 2
},
},
{
"data": [
{
"coords": [
[
116.46,
116.46,
39.92
],
],
[
121.48,
121.48,
31.22
]
],
"fromName": "\u5317\u4eac",
],
"fromName": "\u5317\u4eac",
"toName": "\u4e0a\u6d77"
}
],
],
"effect": {
"color": "#fff",
"period": 6,
"show": true,
"symbol": "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z",
"symbolSize": 15,
"color": "#fff",
"period": 6,
"show": true,
"symbol": "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z",
"symbolSize": 15,
"trailLength": 0
},
},
"lineStyle": {
"normal": {
"curveness": 0.2,
"opacity": 0.6,
"type": "solid",
"curveness": 0.2,
"opacity": 0.6,
"type": "solid",
"width": 1
}
},
"name": "\u4ece\u5317\u4eac\u51fa\u53d1",
},
"name": "\u4ece\u5317\u4eac\u51fa\u53d1",
"symbol": [
"none",
"none",
"arrow"
],
"symbolSize": 12,
"type": "lines",
],
"symbolSize": 12,
"type": "lines",
"zlevel": 3
},
},
{
"coordinateSystem": "geo",
"coordinateSystem": "geo",
"data": [
{
"name": "\u5317\u4eac",
"name": "\u5317\u4eac",
"value": [
116.46,
39.92,
116.46,
39.92,
0
]
},
},
{
"name": "\u4e0a\u6d77",
"name": "\u4e0a\u6d77",
"value": [
121.48,
31.22,
121.48,
31.22,
0
]
}
],
],
"label": {
"emphasis": {
"show": true,
"show": true,
"textStyle": {
"fontSize": 12
}
},
},
"normal": {
"formatter": "{b}",
"position": "right",
"show": true,
"formatter": "{b}",
"position": "right",
"show": true,
"textStyle": {
"color": "#eee",
"color": "#eee",
"fontSize": 12
}
}
},
"name": "\u4ece\u5317\u4eac\u51fa\u53d1",
"symbolSize": 10,
"type": "scatter",
},
"name": "\u4ece\u5317\u4eac\u51fa\u53d1",
"symbolSize": 10,
"tooltip": {
"formatter": "{b}"
},
"type": "scatter",
"zlevel": 3
}
],
"series_id": "1",
],
"series_id": "1",
"title": [
{
"left": "center",
"left": "center",
"subtextStyle": {
"fontSize": 12
},
"text": "GeoLines \u793a\u4f8b",
},
"text": "GeoLines \u793a\u4f8b",
"textStyle": {
"fontSize": 18
},
},
"top": "#fff"
}
],
],
"toolbox": {
"feature": {
"dataView": {
"show": true
},
},
"restore": {
"show": true
},
},
"saveAsImage": {
"show": true,
"show": true,
"title": "\u4e0b\u8f7d\u56fe\u7247"
}
},
"left": "95%",
"orient": "vertical",
"show": true,
},
"left": "95%",
"orient": "vertical",
"show": true,
"top": "center"
},
},
"tooltip": {
"axisPointer": {
"type": "line"
},
"backgroundColor": "rgba(50,50,50,0.7)",
"borderColor": "#333",
"borderWidth": 0,
},
"backgroundColor": "rgba(50,50,50,0.7)",
"borderColor": "#333",
"borderWidth": 0,
"textStyle": {
"fontSize": 14
},
"trigger": "item",
},
"trigger": "item",
"triggerOn": "mousemove|click"
}
}

View File

@ -51,7 +51,6 @@ def test_geolines():
lines = GeoLines("GeoLines 示例", **style.init_style)
lines.add("从广州出发", data_guangzhou, **style_geo)
lines.add("从北京出发", data_beijing, **style_geo)
lines.print_echarts_options()
lines.render()
@ -92,3 +91,21 @@ def test_with_full_example():
lines.add_coordinate("A市", 119.3, 26.08)
lines.add("从广州出发", line_data, **style_geo)
lines.render()
def test_geolines_value_and_formatter():
data_guangzhou = [
["广州", "上海", 10],
["广州", "北京", 20],
["广州", "南京", 30],
["广州", "重庆", 40],
["广州", "兰州", 50],
["广州", "杭州", 60],
]
lines = GeoLines("GeoLines 示例", **style.init_style)
lines.add(
"从广州出发", data_guangzhou, tooltip_formatter="{a} : {c}", **style_geo
)
html_content = lines._repr_html_()
assert '"value": 10' in html_content
assert '"value": 60' in html_content