Skip to content

Commit 97079aa

Browse files
committed
📚 update pyecharts extensions guide
1 parent 01d33f0 commit 97079aa

1 file changed

Lines changed: 116 additions & 57 deletions

File tree

docs/zh-cn/customize_map.md

Lines changed: 116 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,124 @@
99

1010
```
1111
pip install echarts-china-cities-pypkg
12-
pip install echarts-countries-js
12+
pip install echarts-countries-pypkg
1313
```
1414

15+
## 如何制作自己的地图扩展
16+
17+
你需要做两个 github 项目:一个是 npm 项目,提供所有的 javascript 脚本;另一个是 python 项目,把前一个项目变成可以用 pip 装的 python 包。
18+
19+
### npm 项目
20+
21+
这个项目首先必须是一个 npm 的项目,并已经启动 gh-pages 来提供地图库。如果未启动 gh-pages , 那么
22+
你的 jupyter 用户不能把 ipynb 下载成 html ,因为下载之后地图将无法显示。
23+
24+
需要是这样一个结构:
25+
26+
```
27+
+ your-map-extension-js
28+
+ registry.json
29+
+ your-map-extension-js
30+
+ london.js
31+
+ manchester.js
32+
+ index.js
33+
+ other files
34+
```
35+
36+
在 registry.json 里,需要填写这些项目:
37+
```
38+
{
39+
"JUPYTER_URL": "/nbextensions/your-map-extension-js",
40+
"GITHUB_URL": "https://your.github.io/your-map-extension-js/your-map-extensions-js",
41+
"JUPYTER_ENTRY": "your-map-extension-js/index",
42+
"JS_FOLDER": "your-map-extensions-js",
43+
"PINYIN_MAP": {
44+
"伦敦": "lundun",
45+
"曼彻斯特": "manqiesite"
46+
},
47+
"FILE_MAP": {
48+
"lundun": "london",
49+
"manqiesite": "manchester"
50+
}
51+
}
52+
```
53+
54+
index.js 可以是这样:
55+
```
56+
define(["require", "exports"], function (require, exports) {
57+
"use strict";
58+
Object.defineProperty(exports, "__esModule", { value: true });
59+
var version = '1.0.0';
60+
function load_ipython_extension() {
61+
console.log("your-map-extension-js " + version + " has been loaded");
62+
}
63+
exports.load_ipython_extension = load_ipython_extension;
64+
});
65+
66+
```
67+
68+
### python 项目
69+
70+
首先,你需要得到以下的项目:
71+
72+
```
73+
pip install yehua
74+
git clone https://github.com/pyecharts/pypkg-mobans.git
75+
export YEHUA_FILE=/ABSOLUTE/PATH/TO/pypkg-mobans/yehua.yml
76+
```
77+
78+
然后你需要移步到你的工作文件夹,以 echarts-united-kingdom-pykg 为例子运行这个命令
79+
80+
```
81+
$ yh
82+
Yehua will walk you through creating a pyecharts pypkg package.
83+
Press ^C to quit at any time.
84+
85+
project name: echarts-united-kingdom-pypkg
86+
npm project name: echarts-united-kingdom-js
87+
description: pyecharts map extension - united kingdom maps - python package
88+
license: MIT
89+
author: C.W.
90+
contact email: wangc_2011@hotmail.com
91+
github profile/organisation: chfw
92+
copyright owner: C.W.
93+
Cloning into 'mobans'...
94+
remote: Counting objects: 214, done.
95+
remote: Compressing objects: 100% (11/11), done.
96+
remote: Total 214 (delta 8), reused 12 (delta 5), pack-reused 198
97+
Receiving objects: 100% (214/214), 30.31 KiB | 17.00 KiB/s, done.
98+
Resolving deltas: 100% (126/126), done.
99+
Templating CUSTOM_README.rst.jj2 to README.rst
100+
Templating custom_setup.py.jj2 to setup.py
101+
Templating requirements.txt.jj2 to requirements.txt
102+
Templating tests/custom_requirements.txt.jj2 to tests/requirements.txt
103+
Templating docs/source/conf.py.jj2 to docs/source/conf.py
104+
Templating test.script.jj2 to test.sh
105+
Templating _version.py.jj2 to echarts_united_kingdom_pypkg/_version.py
106+
Templating gitignore.jj2 to .gitignore
107+
Templating travis.yml.jj2 to .travis.yml
108+
Templated 9 files.
109+
Initialized empty Git repository in /private/tmp/echarts-united-kingdom-pypkg/.git/
110+
Please review changes before commit!
111+
```
112+
113+
这个时候,这个扩展包的骨架就已经做好了。我们现在做最后一步:
114+
115+
116+
```
117+
pyecharts-host:tmp chfw$ cd echarts-united-kingdom-pypkg/
118+
git submodule add https://github.com/your/npm/project your_project_name_pypkg/resources
119+
```
120+
121+
然后做:
122+
123+
```
124+
git commit
125+
```
126+
127+
这样呢,这个包就可以放在 github 上了。
128+
129+
15130
## 如何手动添加(0.1.9.7+)
16131
下面就以广东省汕头市南澳县地图为例,说明如何自行添加地图。
17132

@@ -69,60 +184,4 @@ jupyter nbextension enable echarts/main
69184

70185
![customize-map-2](https://user-images.githubusercontent.com/19553554/35104708-9d88455a-fca4-11e7-8fb1-1aff8e0066ef.png)
71186

72-
## 如何把手动加的地图变成自动的
73-
74-
如果用户期望 pyecharts 支持自己的地图,请发请求然后再发来改动。
75-
76-
或者自己开发pyecharts的地图扩展
77-
78-
79-
## pyecharts 的地图扩展
80-
81-
首先,地图扩展必须是一个 github 的项目,并已经启动 gh-pages 来提供地图库。如果未启动 gh-pages , 那么
82-
你的 jupyter 用户不能把 ipynb 下载成 html ,因为下载之后地图将无法显示。
83-
84-
需要是这样一个结构:
85-
86-
```
87-
+ your-map-extension-js
88-
+ registry.json
89-
+ your-map-extension-js
90-
+ london.js
91-
+ manchester.js
92-
+ index.js
93-
+ other files
94-
```
95-
96-
在 registry.json 里,需要填写这些项目:
97-
```
98-
{
99-
"JUPYTER_URL": "/nbextensions/your-map-extension-js",
100-
"GITHUB_URL": "https://your.github.io/your-map-extension-js/your-map-extensions-js",
101-
"JUPYTER_ENTRY": "your-map-extension-js/index",
102-
"JS_FOLDER": "your-map-extensions-js",
103-
"PINYIN_MAP": {
104-
"伦敦": "lundun",
105-
"曼彻斯特": "manqiesite"
106-
},
107-
"FILE_MAP": {
108-
"lundun": "london",
109-
"manqiesite": "manchester"
110-
}
111-
}
112-
```
113-
114-
index.js 可以是这样:
115-
```
116-
define(["require", "exports"], function (require, exports) {
117-
"use strict";
118-
Object.defineProperty(exports, "__esModule", { value: true });
119-
var version = '1.0.0';
120-
function load_ipython_extension() {
121-
console.log("your-map-extension-js " + version + " has been loaded");
122-
}
123-
exports.load_ipython_extension = load_ipython_extension;
124-
});
125-
126-
```
127187

128-
最后,就是通知我们把你的扩展加入 pyecharts-cli 的目录,方便你和其他人装你的地图扩展。

0 commit comments

Comments
 (0)