Skip to content

Commit 50f9ebb

Browse files
authored
Merge pull request #23 from kinegratii/dev
release v0.3.6
2 parents 8b5acac + 1253a95 commit 50f9ebb

File tree

12 files changed

+156
-122
lines changed

12 files changed

+156
-122
lines changed

MANIFEST.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
include django_echarts/templates/*.html
2-
include django_echarts/templates/tags/*.html

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,33 @@ django-echarts 主要提供了以下的内容:
1717

1818
## 安装
1919

20-
### Python3 Only
20+
### pyecharts
2121

22-
django-echarts 只支持 Python3.5 以上 的开发环境。
22+
请根据你的 pyecharts 版本安装 django-echarts 。
23+
24+
> django-echarts 暂未适配 pyecharts v0.5.x ,敬请期待。
25+
26+
27+
| django-echarts | pyecharts | 备注 |
28+
| ------ | ------ | ------ |
29+
| 0.3.x | 0.3.x - 0.4.x | |
30+
31+
### Python & Django
32+
33+
django-echarts **只支持**
34+
35+
- Python3.5+
36+
- Django 1.11 LTS 或 Django 2.0+
37+
38+
### 安装方式
39+
40+
可以使用 pip 在线安装。
2341

2442
```shell
2543
pip install django-echarts
2644
```
2745

46+
2847
或者使用源码构建
2948

3049
```shell
@@ -33,15 +52,6 @@ cd django-echarts
3352
python setup.py install
3453
```
3554

36-
### 其他
37-
38-
其他安装要求为:
39-
40-
- pyecharts 0.3+
41-
- Django 1.11 LTS 或 Django 2.0+
42-
43-
44-
4555
## 快速使用
4656

4757
1 添加 django_echarts包到项目配置模块的 `INSTALL_APPS`列表。

django_echarts/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
A django app for Echarts integration with pyecharts as chart builder.
33
"""
44

5-
__version__ = '0.3.5'
5+
__version__ = '0.3.6'
66
__author__ = 'kinegratii'

django_echarts/datasets/charts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class NamedCharts:
88
A data structure class containing multiple named charts.
99
"""
1010

11-
def __init__(self, page_title='EChart', **kwargs):
11+
def __init__(self, page_title='EChart', **name_chart_pair):
1212
self.page_title = page_title
1313
self._charts = OrderedDict()
14-
for k, v in kwargs.items():
14+
for k, v in name_chart_pair.items():
1515
self.add_chart(chart=v, name=k)
1616

1717
def add_chart(self, chart, name=None):
@@ -20,7 +20,7 @@ def add_chart(self, chart, name=None):
2020
return self
2121

2222
def _next_name(self):
23-
return 'c{}'.format(len(self._charts))
23+
return 'c{}'.format(len(self))
2424

2525
# List-like feature
2626

@@ -60,8 +60,8 @@ def js_dependencies(self):
6060
return merge_js_dependencies(*self)
6161

6262
@classmethod
63-
def from_charts(cls, *args):
63+
def from_charts(cls, *charts):
6464
mc = cls()
65-
for c in args:
66-
mc.add_chart(c)
65+
for chart in charts:
66+
mc.add_chart(chart)
6767
return mc

django_echarts/templates/tags/echarts.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
更新日志
22
=========
33

4+
v0.3.6 (20180530)
5+
-----------------
6+
7+
- 优化 `Page` 类实现
8+
- 发布独立的 `Page` 文档
9+
410
v0.3.5 (20180504)
511
-----------------
612

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
# built documents.
5656
#
5757
# The short X.Y version.
58-
version = '0.3.5'
58+
version = '0.3.6'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '0.3.5'
60+
release = '0.3.6'
6161

6262
# The language for content autogenerated by Sphinx. Refer to documentation
6363
# for a list of supported languages.

docs/datastructure.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
数据结构
2+
=========
3+
4+
**注意**:从 pyecharts v0.5.4 开始, `pyecharts.Page` 类也支持 *图表命名引用*, 因此可以直接使用 `pyecharts.Page` 类。
5+
6+
多图表渲染
7+
----------
8+
9+
.. versionadded:: 0.3.4
10+
11+
自 v0.3.4 新增 `django_echarts.datasets.charts.NamedCharts` 用于多图表渲染,该类是对于原有的 `pyecharts.custom.page.Page` 进行改善,包括:
12+
13+
- 增加图表对象命名引用
14+
- 移除了 `list` 的相关方法
15+
16+
基本使用
17+
++++++++
18+
19+
20+
在创建一个 `NamedCharts` 实例 `charts` ,后,使用 `add_chart` 添加一个图表对象,可以使用 `name` 为之起一个引用名称,如果没有指定引用名称,则使用 c0,c1 命名。
21+
22+
::
23+
24+
25+
class MultipleChartsView(EChartsBackendView):
26+
echarts_instance_name = 'charts'
27+
template_name = 'multiple_charts.html'
28+
29+
def get_echarts_instance(self, *args, **kwargs):
30+
device_data = models.Device.objects.values('device_type').annotate(count=Count('device_type'))
31+
device_types, counters = fetch(device_data, 'device_type', 'count')
32+
pie = Pie("设备分类", page_title='设备分类', width='100%')
33+
pie.add("设备分类", device_types, counters, is_label_show=True)
34+
35+
battery_lifes = models.Device.objects.values('name', 'battery_life')
36+
names, lifes = fetch(battery_lifes, 'name', 'battery_life')
37+
bar = Bar('设备电量', page_title='设备电量', width='100%')
38+
bar.add("设备电量", names, lifes)
39+
charts = NamedCharts().add_chart(pie, name='pie').add_chart(bar)
40+
return charts
41+
42+
元素访问
43+
++++++++
44+
45+
.. versionchanged:: 0.3.5
46+
图表访问方式从 *属性访问* 改为 *字典访问* 。
47+
48+
对于 包含若干图表的 `NamedCharts` 实例,可以像字典一样访问该图表对象。
49+
50+
Python 代码的访问方式
51+
52+
::
53+
54+
# 访问 pie 对象 page_title
55+
print(charts['pie'].page_title)
56+
57+
# 访问 bar 对象 page_title
58+
print(charts['c1'].page_title) # 推荐
59+
print(charts[1].page_title) # 不再推荐
60+
61+
模板代码的访问方式:
62+
63+
::
64+
65+
{{ charts.pie.page_title }}
66+
{{ charts.c1.page_title }}
67+
68+
注意
69+
70+
::
71+
72+
无论是 Jinja2 模板还是 Django 模板,均不提倡使用 `charts.1` 形式访问列表中的某一个元素。
73+
74+
NamedCharts VS Page
75+
+++++++++++++++++++
76+
77+
`NamedCharts` 内部使用 `collections.OrderedDict` 保存图表名称和实例,支持字典访问方式,同时扩展原有的 `Page` 的列表特性。
78+
79+
具体差别如下表:
80+
81+
.. image:: /_static/namedcharts-vs-page.png

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ django-echarts 仅支持 Python3.5+ 的开发环境, Django 版本要求为 2.0+
2727
tutorial
2828
topics
2929
data_builder
30+
datastructure
3031
fetch
3132
api
3233
development

docs/topics.rst

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -142,83 +142,6 @@ django_echarts 提供两种方式的渲染视图,即:
142142
});
143143
</script>
144144
145-
多图表渲染
146-
----------
147-
148-
.. versionadded:: 0.3.4
149-
150-
自 v0.3.4 新增 `django_echarts.datasets.charts.NamedCharts` 用于多图表渲染,该类是对于原有的 `pyecharts.custom.page.Page` 进行改善,包括:
151-
152-
- 增加图表对象命名引用
153-
- 移除了 `list` 的相关方法
154-
155-
基本使用
156-
++++++++
157-
158-
159-
在创建一个 `NamedCharts` 实例 `charts` ,后,使用 `add_chart` 添加一个图表对象,可以使用 `name` 为之起一个引用名称,如果没有指定引用名称,则使用 c0,c1 命名。
160-
161-
::
162-
163-
164-
class MultipleChartsView(EChartsBackendView):
165-
echarts_instance_name = 'charts'
166-
template_name = 'multiple_charts.html'
167-
168-
def get_echarts_instance(self, *args, **kwargs):
169-
device_data = models.Device.objects.values('device_type').annotate(count=Count('device_type'))
170-
device_types, counters = fetch(device_data, 'device_type', 'count')
171-
pie = Pie("设备分类", page_title='设备分类', width='100%')
172-
pie.add("设备分类", device_types, counters, is_label_show=True)
173-
174-
battery_lifes = models.Device.objects.values('name', 'battery_life')
175-
names, lifes = fetch(battery_lifes, 'name', 'battery_life')
176-
bar = Bar('设备电量', page_title='设备电量', width='100%')
177-
bar.add("设备电量", names, lifes)
178-
charts = NamedCharts().add_chart(pie, name='pie').add_chart(bar)
179-
return charts
180-
181-
元素访问
182-
++++++++
183-
184-
.. versionchanged:: 0.3.5
185-
图表访问方式从 *属性访问* 改为 *字典访问* 。
186-
187-
对于 包含若干图表的 `NamedCharts` 实例,可以像字典一样访问该图表对象。
188-
189-
Python 代码的访问方式
190-
191-
::
192-
193-
# 访问 pie 对象 page_title
194-
print(charts['pie'].page_title)
195-
196-
# 访问 bar 对象 page_title
197-
print(charts['c1'].page_title) # 推荐
198-
print(charts[1].page_title) # 不再推荐
199-
200-
模板代码的访问方式:
201-
202-
::
203-
204-
{{ charts.pie.page_title }}
205-
{{ charts.c1.page_title }}
206-
207-
注意
208-
209-
::
210-
211-
无论是 Jinja2 模板还是 Django 模板,均不提倡使用 `charts.1` 形式访问列表中的某一个元素。
212-
213-
NamedCharts VS Page
214-
+++++++++++++++++++
215-
216-
`NamedCharts` 内部使用 `collections.OrderedDict` 保存图表名称和实例,支持字典访问方式,同时扩展原有的 `Page` 的列表特性。
217-
218-
具体差别如下表:
219-
220-
.. image:: /_static/namedcharts-vs-page.png
221-
222145
223146
模板标签
224147
---------

0 commit comments

Comments
 (0)