Skip to content

Commit 9f26e89

Browse files
committed
Add test cases
1 parent eae38d8 commit 9f26e89

4 files changed

Lines changed: 47 additions & 9 deletions

File tree

changelog.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
* ### version 0.3.0 (dev)
1111
* 图表`render` 方法增加 `template_name``object_name``extra_context` 等参数,全面支持自定义模板
12-
* 重写底层逻辑,支持在模板文件中使用 `echarts_*` 系列模板函数`render_embed` 方法不再推荐使用
12+
* 重写底层逻辑,支持在模板文件中使用 `echarts_*` 系列模板函数
1313
* js 依赖文件支持外部链接方式引入。
1414
* 新增统一配置函数 `pyecharts.configure` ,支持设置模板目录,JS文件仓库路径。
15-
* `pyecharts.online` 全局函数不再推荐使用
1615
* `pyecharts.custom.Page` 类实现 `list` 协议,支持迭代、索引、添加、扩展等操作。
1716
* 图表 width 和 height 支持 '50%' 、'78px' 等其他 css 有效长度形式。
1817
* [issue#252](https://github.com/chenjiandongx/pyecharts/issues/252) 新增 `xaxis_label_textsize`, `xaxis_label_textcolor`, `yaxis_label_textsize`, `yaxis_label_textcolor` 四个参数修改坐标轴标签的字体和颜色
@@ -48,7 +47,7 @@
4847

4948
#### Changed
5049
* 将 label 通用配置项的 `is_emphasis` 参数更改为 `is_label_emphasis`
51-
* show_config() 修改用 JSON 显示
50+
* show_config() 修改用 JSON 显示
5251

5352
#### Fixed
5453
* [issue#195](https://github.com/chenjiandongx/pyecharts/issues/195) 修复 HeatMap 图配置 x、y 轴属性无效的问题
@@ -152,8 +151,8 @@
152151

153152
#### Added
154153
* 为 xyAxis 模块新增下列参数
155-
`xaxis_interval`, `xaxis_name_size`, `xaxis_name_gap`, `xaxis_margin`, `is_xaxislabel_align`
156-
`yaxis_interval`, `yaxis_name_size`, `yaxis_name_gap`, `yaxis_margin`, `is_yaxislabel_align`
154+
`xaxis_interval`, `xaxis_name_size`, `xaxis_name_gap`, `xaxis_margin`, `is_xaxislabel_align`
155+
`yaxis_interval`, `yaxis_name_size`, `yaxis_name_gap`, `yaxis_margin`, `is_yaxislabel_align`
157156
* [issue#86](https://github.com/chenjiandongx/pyecharts/issues/86) 为 3D 图新增参数用于配置坐标轴选项(参见通用配置项中的 axis3D)
158157
* 修改自定义模块的接口,现自定义模块有以下 4 个类,具体用法参见文档
159158
* Grid 类:并行显示多张图

docs/zh-cn/doc_flask.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ $ flask run
124124

125125
自 V0.3.0 起, pyecharts 支持在 Flask 使用 `echarts_*` 系列模板函数。
126126

127-
### 第一步:实现 Flask 应用的自定义模板引擎
127+
### Step 0:实现 Flask 应用的自定义模板引擎
128128

129129
主要有三个要点:
130130

131131
- 创建一个继承自 `flask.templating.Environment` 的模板引擎类`FlaskEchartsEnvironment`
132132
- 通过使用 `pyecharts.engine.PyEchartsConfigMixin` 提供一个配置对象 。
133133
- 在构造函数 `__init__` 中添加模板函数到全局字典中。
134+
- 在自己的 Flask 应用类中指定 `FlaskEchartsEnvironment` 为默认模板引擎。
134135

135136
```python
136137
from flask import Flask, render_template
@@ -154,9 +155,34 @@ class MyFlask(Flask):
154155

155156

156157
app = MyFlask(__name__)
158+
159+
@app.route("/")
160+
def hello():
161+
hm = create_heatmap()
162+
return render_template('flask_tpl.html', hm=hm)
163+
164+
165+
def create_heatmap():
166+
begin = datetime.date(2017, 1, 1)
167+
end = datetime.date(2017, 12, 31)
168+
data = [[str(begin + datetime.timedelta(days=i)),
169+
random.randint(1000, 25000)] for i in
170+
range((end - begin).days + 1)]
171+
heatmap = HeatMap("日历热力图示例", "某人 2017 年微信步数情况", width=1100)
172+
heatmap.add("", data, is_calendar_heatmap=True,
173+
visual_text_color='#000', visual_range_text=['', ''],
174+
visual_range=[1000, 25000], calendar_cell_size=['auto', 30],
175+
is_visualmap=True, calendar_date_range="2017",
176+
visual_orient="horizontal", visual_pos="center",
177+
visual_top="80%", is_piecewise=True)
178+
return heatmap
179+
180+
app.run(port=10200)
157181
```
158182

159-
### 第二步:创建模板文件
183+
**注意的是:视图函数中 `render_template` 传给模板的是图表实例 hm ,而不再是其若干个属性,这是和第一种方式最大的区别之一。**
184+
185+
### Step 1:创建模板文件
160186

161187
在同目录下 templates 文件夹创建 flask_demo.html 文件写入如下的代码。
162188

@@ -185,4 +211,8 @@ app = MyFlask(__name__)
185211
使用外链形式优点在于:
186212

187213
- 减少最后生成文件大小
188-
- 更容易与 web 框架整合,便于大型项目开发
214+
- 更容易与 web 框架整合,便于大型项目开发
215+
216+
### Step 2: 运行
217+
218+
之后脚本运行步骤同第一种方式。

test/test_conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_with_default_value():
1818
eq_(SCRIPT_LOCAL_JSHOST, target_config.jshost)
1919
eq_(SCRIPT_LOCAL_JSHOST, target_config.get_current_jshost_for_script())
2020
eq_(JUPYTER_LOCAL_JSHOST, target_config.get_current_jshost_for_jupyter())
21+
eq_('http://demo', target_config.get_current_jshost_for_script('http://demo'))
2122

2223
assert target_config.js_embed
2324

test/test_template_function.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# coding=utf8
2+
import unittest
3+
4+
from nose.tools import raises
25

36
from pyecharts.utils import get_resource_dir
47
from pyecharts import Bar
5-
from pyecharts.engine import EchartsEnvironment
8+
from pyecharts.engine import BaseEnvironment, EchartsEnvironment
69

710
ECHARTS_ENV = EchartsEnvironment()
811

@@ -73,3 +76,8 @@ def test_echarts_js_content_wrap():
7376
bar = create_demo_bar()
7477
html = tpl.render(bar=bar)
7578
assert len(html) > 0
79+
80+
81+
@raises(TypeError)
82+
def test_create_environment_without_config():
83+
be = BaseEnvironment()

0 commit comments

Comments
 (0)