Skip to content

Commit

Permalink
pyecharts#208 PR 进行部分修改和完善
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx committed Oct 12, 2017
1 parent 66d7ddb commit 3a5454f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 39 deletions.
54 changes: 33 additions & 21 deletions docs/zh-cn/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ add(name, x_axis, y_axis, data, grid3d_opacity=1, grid3d_shading='color', **kwar
x 坐标轴数据。需为类目轴,也就是不能是数值。
* y_axis -> str
y 坐标轴数据。需为类目轴,也就是不能是数值。
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』
* grid3d_opacity -> int
3D 笛卡尔坐标系组的透明度(柱状的透明度),默认为 1,完全不透明。
Expand Down Expand Up @@ -791,7 +791,7 @@ add(name, x_axis, y_axis, **kwargs)
图例名称
* x_axis -> list
x 坐标轴数据
* y_axis -> [list],包含列表的列表
* y_axis -> [list], 包含列表的列表
y 坐标轴数据,二维数组的每一数组项(上例中的每行)是渲染一个 box,它含有五个量值,依次是:
[min, Q1, median (or Q2), Q3, max]

Expand Down Expand Up @@ -1193,21 +1193,29 @@ graph.render()
HeatMap.add() 方法签名
```python
add(name, x_axis, y_axis, data, **kwargs)
add(*args, **kwargs)
```
如果指定了 `is_calendar_heatmap`(使用日历热力图)为 True,则参数为
* name -> str
图例名称
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』
* calendar_date_range -> str/list
日历热力图的日期, "2016" 表示 2016 年, ["2016-5-5", "2017-5-5"] 表示 2016 年 5 月 5 日至 2017 年 5 月 5 日
* calendar_cell_size -> list
日历每格框的大小,可设置单值 或数组 第一个元素是宽 第二个元素是高,支持设置自适应 "auto"。默认为 ["auto", 20]

默认为不指定,参数为
* name -> str
图例名称
* x_axis -> str
x 坐标轴数据。需为类目轴,也就是不能是数值。
* y_axis -> str
y 坐标轴数据。需为类目轴,也就是不能是数值。
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』
* is_date_heatmap -> bool
是否是日历热力图,默认为 False
* date_range -> str/list
日历热力图的日期, "2016"表示2016年, ["2016-5-5", "2017-5-5"]表示2016年5月5日至2017年5月5日

默认情况,不指定 `is_calendar_heatmap`
```python
import random
from pyecharts import HeatMap
Expand All @@ -1223,6 +1231,7 @@ heatmap.render()
```
![heatmap-0](https://github.com/chenjiandongx/pyecharts/blob/master/images/heatmap-0.gif)

使用日历热力图,指定 `is_calendar_heatmap` 为 True
```python
import datetime
import random
Expand All @@ -1231,14 +1240,17 @@ from pyecharts import HeatMap
begin = datetime.date(2017, 1, 1)
end = datetime.date(2017, 12, 31)
data = [[str(begin + datetime.timedelta(days=i)),
random.randint(0, 100)] for i in range((end - begin).days+1)]
heatmap = HeatMap("日历热力图示例")
heatmap.add("日历热力图", data, date_range=["2017"], is_visualmap=True,
is_legend_show=False, is_date_heatmap=True, visual_orient="horizontal",
visual_pos="center", visual_top="top")
random.randint(1000, 25000)] for i in range((end - begin).days + 1)]
heatmap = HeatMap("日历热力图示例", "某人 2017 年微信步数情况", width=1100)
heatmap.add("", data, is_calendar_heatmap=True,
visual_text_color='#000', visual_range_text=['', ''],
visual_range=[1000, 25000], calendar_cell_size=['auto', 30],
is_visualmap=True, calendar_date_range="2017",
visual_orient="horizontal", visual_pos="center",
visual_top="80%", is_piecewise=True)
heatmap.render()
```
![heatmap-0](https://github.com/chenjiandongx/pyecharts/blob/master/images/heatmap-1.gif)
![heatmap-1](https://github.com/chenjiandongx/pyecharts/blob/master/images/heatmap-1.gif)

**Note:** 热力图必须配合 [通用配置项](https://github.com/chenjiandongx/pyecharts/blob/master/docs/zh-cn/documentation.md#通用配置项) 中的 VisualMap 使用才有效果。

Expand All @@ -1254,7 +1266,7 @@ add(name, x_axis, y_axis, **kwargs)
图例名称
* x_axis -> list
x 坐标轴数据
* y_axis -> [list],包含列表的列表
* y_axis -> [list], 包含列表的列表
y 坐标轴数据。数据中,每一行是一个『数据项』,每一列属于一个『维度』。
数据项具体为 [open, close, lowest, highest] (即:[开盘值, 收盘值, 最低值, 最高值]
```python
Expand Down Expand Up @@ -1423,7 +1435,7 @@ add(name, data, grid3d_opacity=1, **kwargs)
```
* name -> str
图例名称
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』
* grid3d_opacity -> int
3D 笛卡尔坐标系组的透明度(线的透明度),默认为 1,完全不透明。
Expand Down Expand Up @@ -1607,7 +1619,7 @@ add(name, data, **kwargs)
```
* name -> str
图例名称
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项。数据中,每一行是一个『数据项』,每一列属于一个『维度』

Parallel.config() 方法签名
Expand Down Expand Up @@ -1771,7 +1783,7 @@ add(name, data, angle_data=None, radius_data=None, type='line', symbol_size=4, s
```
* name -> str
图例名称
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项 [极径,极角 [数据值]]
* angle_data -> list
角度类目数据
Expand Down Expand Up @@ -1881,7 +1893,7 @@ add(name, value, item_color=None, **kwargs)
```
* name -> list
图例名称
* value -> [list],包含列表的列表
* value -> [list], 包含列表的列表
数据项。数据中,每一行是一个『数据项』,每一列属于一个『维度』
* item_color -> str
指定单图例颜色
Expand Down Expand Up @@ -2195,7 +2207,7 @@ add(name, data, grid3d_opacity=1, **kwargs)
```
* name -> str
图例名称
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』
* grid3d_opacity -> int
3D 笛卡尔坐标系组的透明度(点的透明度),默认为 1,完全不透明。
Expand Down Expand Up @@ -2227,7 +2239,7 @@ add(name, data)
```
* name -> list
图例名称,必须为 list 类型,list 中每个值为数据项中的种类。
* data -> [list],包含列表的列表
* data -> [list], 包含列表的列表
数据项,数据中,每一行是一个『数据项』,每一列属于一个『维度』。每个数据项至少需要三个维度,如 ['2015/11/08', 10, 'DQ'],分别为 [时间,数值,种类(图例名)]

```python
Expand Down
Binary file modified images/bar-8.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/heatmap-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pyecharts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def add(self, angle_data=None,
border_color=None,
boundary_gap=None,
center=None,
calendar_date_range=None,
calendar_cell_size=None,
datazoom_type=None,
datazoom_range=None,
datazoom_orient=None,
Expand Down Expand Up @@ -162,6 +164,7 @@ def add(self, angle_data=None,
is_area_show=None,
is_axisline_show=None,
is_calculable=None,
is_calendar_heatmap=None,
is_clockwise=None,
is_convert=None,
is_datazoom_show=None,
Expand Down
34 changes: 21 additions & 13 deletions pyecharts/charts/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ def add(self, *args, **kwargs):
def __add(self, *args, **kwargs):
"""
:param name:
Series name used for displaying in tooltip and filtering with legend,
or updating data and configuration with setOption.
:param x_axis:
data of xAxis, it must be catagory axis.
:param y_axis:
data of yAxis, it must be catagory axis.
:param data:
data array of series, it is represented by a two-dimension array -> [[],[]]
:param args:
if kwargs has is_calendar_heatmap property:
:param name:
Series name used for displaying in tooltip and filtering with legend,
or updating data and configuration with setOption.
:param data:
data array of series, it is represented by a two-dimension array -> [[],[]]
else:
:param name:
Series name used for displaying in tooltip and filtering with legend,
or updating data and configuration with setOption.
:param x_axis:
data of xAxis, it must be catagory axis.
:param y_axis:
data of yAxis, it must be catagory axis.
:param data:
data array of series, it is represented by a two-dimension array -> [[],[]]
:param kwargs:
:return:
"""
if kwargs.get('is_date_heatmap', None) is True:
_is_calendar = kwargs.get('is_calendar_heatmap', None) is True
if _is_calendar:
name, data = args
else:
name, x_axis, y_axis, data = args
Expand All @@ -52,10 +61,9 @@ def __add(self, *args, **kwargs):
"seriesId": self._option.get('series_id'),
})

if kwargs.get('is_date_heatmap', None) is True:
if _is_calendar:
self._option.get('toolbox')['show'] = False
self._option.get('series')[0].update(coordinateSystem='calendar',
calendarIndex=0)
self._option.get('series')[0].update(coordinateSystem='calendar')
self._option.update(calendar=chart['calendar'])
else:
xaxis, yaxis = chart['xy_axis']
Expand Down
36 changes: 31 additions & 5 deletions pyecharts/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ def visual_map(visual_type='color',
"dimension": visual_dimension,
"orient": visual_orient,
"left": visual_pos,
"top": visual_top
"top": visual_top,
"showLabel": True,
}
return _visual_map

Expand Down Expand Up @@ -1134,11 +1135,36 @@ def tooltip(type=None,


@collectfuncs
def calendar(date_range=None,
cellSize=['auto', 20], **kwargs):
def calendar(calendar_date_range=None,
calendar_cell_size=None,
**kwargs):
"""
:param calendar_date_range:
Required, range of Calendar coordinates, support multiple formats.
Examples:
# one year
range: 2017
# one month
range: '2017-02'
# a range
range: ['2017-01-02', '2017-02-23']
# note: they will be identified as ['2017-01-01', '2017-02-01']
range: ['2017-01', '2017-02']
:param calendar_cell_size:
The size of each rect of calendar coordinates, can be set to a single
value or array, the first element is width and the second element
is height.Support setting self-adaptation: "auto"
:param kwargs:
:return:
"""

if calendar_cell_size is None:
calendar_cell_size = ['auto', 20]

_calendar = {
"range": date_range,
"cellSize": cellSize
"range": calendar_date_range,
"cellSize": calendar_cell_size
}
return _calendar

Expand Down

0 comments on commit 3a5454f

Please sign in to comment.