Skip to content

Commit

Permalink
Geolines data value (pyecharts#566)
Browse files Browse the repository at this point in the history
* Update: 更新 x,y 轴 formatter 参数注释

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

* Update: charts docs update

* Fix: fixed bronken test

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

* Update: lines -> line

* Update: 删除无用语句
  • Loading branch information
chenjiandongx committed May 16, 2018
1 parent eac3f9f commit 8b5dba9
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 161 deletions.
16 changes: 15 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<!--
### 提 issue 注意事项
0. 先仔细阅读文档中是否有关于您需要解决的问题的解决方法
1. 提 issue 前请先搜搜看以往的 issue 有没有解决了您的问题
2. 如若是不能正常使用的问题,请贴上详细的 pyecharts 版本,使用系统以及 Python 版本
3. 最好详细描述问题,必要时加上**代码+贴图**
3. 最好详细描述问题,必要时加上**代码+贴图**
-->

**问题**



**运行环境(系统环境及 pyecharts 版本)**



**代码及截图**


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

本次 PR 内容,


4 changes: 3 additions & 1 deletion docs/zh-cn/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 版本日志

* ### version 0.5.5(dev)
* TODO

### Added
* [issue#565](https://github.com/pyecharts/pyecharts/issues/565) Geolines 图数据项可以新增数值维度

* ### version 0.5.4 - 2018.05.15(current)

Expand Down
22 changes: 21 additions & 1 deletion docs/zh-cn/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ add(name, data,
* name -> str
图例名称
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每一行包含两个数据, 如 ["广州", "北京"],则指定从广州到北京。
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每一行包含两个或三个数据,如 ["广州", "北京"]["广州", "北京",100],则指定从广州到北京。第三个值用于表示该 line 的数值,该值可省略
* maptype -> str
地图类型。 从 v0.3.2+ 起,地图已经变为扩展包,支持全国省份,全国城市,全国区县,全球国家等地图,具体请参考 [地图自定义篇](zh-cn/customize_map)
* symbol -> str
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions pyecharts/charts/geolines.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def add(
:param name:
系列名称,用于 tooltip 的显示,legend 的图例筛选。
:param data:
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每一行包含两个数据,
如 ["广州", "北京"],则指定从广州到北京。
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每一行包含两个或
三个数据,如 ["广州", "北京"] 或 ["广州", "北京",100],则指定从广州到北京。第
三个值用于表示该 line 的数值,该值可省略。
:param maptype:
地图类型。 从 v0.3.2+ 起,地图已经变为扩展包,支持全国省份,全国城市,全国区县,
全球国家等地图,具体请参考 [地图自定义篇](zh-cn/customize_map)
Expand Down Expand Up @@ -88,8 +89,15 @@ def add(
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
)
Expand All @@ -100,6 +108,7 @@ def add(
{
"fromName": _from_name,
"toName": _to_name,
"value": _line_value,
"coords": [_from_coordinate, _to_coordinate],
}
)
Expand Down Expand Up @@ -161,6 +170,7 @@ def add(
"symbolSize": 10,
"data": _data_scatter,
"label": chart["label"],
"tooltip": {"formatter": "{b}"},
}
)

Expand Down
Loading

0 comments on commit 8b5dba9

Please sign in to comment.