Skip to content

Commit

Permalink
🐎 major speed improvement for browser loading. all javascript files a…
Browse files Browse the repository at this point in the history
…re local in render.html. NO more fetching from the cloud. It works when you do NOT have INTERNET access.
  • Loading branch information
chfw committed Aug 1, 2017
1 parent 09d3a41 commit 39a85f5
Show file tree
Hide file tree
Showing 44 changed files with 1,825 additions and 38 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include README.md
include changelog.md
include pyecharts/templates/*.html
include pyecharts/templates/js/*.js
1 change: 1 addition & 0 deletions pyecharts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def render(self, path="render.html"):
my_option = json.dumps(self._option, indent=4, ensure_ascii=False)
tmp = self._jinja2_env.get_template(temple)
html = tmp.render(myOption=my_option, myWidth=self._width, myHeight=self._height)
html = template.freeze_js(html)
if PY2:
html = html.encode('utf-8')
with open(path, "w+") as fout:
Expand Down
32 changes: 32 additions & 0 deletions pyecharts/template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#!/usr/bin/env python
#coding=utf-8
import os
import re


JS_PATTERN = re.compile(r'<!-- build -->(.*)<!-- endbuild -->',
re.IGNORECASE | re.MULTILINE | re.DOTALL)
JS_SRC_PATTERN = re.compile(r'src=\"(.*?)\"')


def freeze_js(html_content):
matches = JS_PATTERN.finditer(html_content)

if not matches:
return html_content

for match in reversed(tuple(matches)):
# JS file block
src_matches = JS_SRC_PATTERN.findall(match.group(1))

js_content = ""
for src in src_matches:
file_path = os.path.join(get_resource_dir('templates'), src.strip())

with open(file_path, "r") as f:
js_content += f.read() + '\n'
# Replace matched string with inline JS
fmt = '<script type="text/javascript">{}</script>'
js_content = fmt.format(js_content)
html_content = (html_content[:match.start()] + js_content +
html_content[match.end():])

return html_content


_mapindex = {
"安徽": "anhui: '//oog4yfyu0.bkt.clouddn.com/anhui'",
Expand Down
27 changes: 27 additions & 0 deletions pyecharts/templates/js/anhui.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/aomen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'echarts'], factory);
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports, require('echarts'));
} else {
// Browser globals
factory({}, root.echarts);
}
}(this, function (exports, echarts) {
var log = function (msg) {
if (typeof console !== 'undefined') {
console && console.error && console.error(msg);
}
}
if (!echarts) {
log('ECharts is not Loaded');
return;
}
if (!echarts.registerMap) {
log('ECharts Map is not loaded')
return;
}
echarts.registerMap('澳门', {"type":"FeatureCollection","features":[{"id":"820001","geometry":{"type":"Polygon","coordinates":["@@LADC^umZ@DONWEBDCLHBH@DFBBNA"],"encodeOffsets":[[116285,22746]]},"properties":{"cp":[113.5528956,22.20787],"name":"花地瑪堂區","childNum":1}},{"id":"820002","geometry":{"type":"Polygon","coordinates":["@@MK@CA@AAGDEB@NVFHE"],"encodeOffsets":[[116281,22734]]},"properties":{"cp":[113.5489608,22.1992075],"name":"花王堂區","childNum":1}},{"id":"820003","geometry":{"type":"Polygon","coordinates":["@@EGOB@DNLHE@C"],"encodeOffsets":[[116285,22729]]},"properties":{"cp":[113.5501828,22.19372083],"name":"望德堂區","childNum":1}},{"id":"820004","geometry":{"type":"Polygon","coordinates":["@@ŸYIPEL@JFCBBFADHDBBFDHIJJEFDPCHHlY"],"encodeOffsets":[[116313,22707]]},"properties":{"cp":[113.5536475,22.18853944],"name":"大堂區","childNum":1}},{"id":"820005","geometry":{"type":"Polygon","coordinates":["@@JICGAECACGEBAAEDP^"],"encodeOffsets":[[116266,22728]]},"properties":{"cp":[113.5419278,22.18736806],"name":"風順堂區","childNum":1}},{"id":"820006","geometry":{"type":"Polygon","coordinates":["@@ ZNWRquZCBCC@AEA@@ADCDCAACEAGBQ@IN"],"encodeOffsets":[[116265,22694]]},"properties":{"cp":[113.5587044,22.15375944],"name":"嘉模堂區","childNum":1}},{"id":"820007","geometry":{"type":"Polygon","coordinates":["@@MOIAIEI@@GE@AAUCBdCFIFR@HAFBBDDBDCBCDB@BFDDC"],"encodeOffsets":[[116316,22676]]},"properties":{"cp":[113.5695992,22.13663],"name":"路氹填海區","childNum":1}},{"id":"820008","geometry":{"type":"Polygon","coordinates":["@@DKMMa_GC_COD@dVDBBF@@HJ@JFJBNP"],"encodeOffsets":[[116329,22670]]},"properties":{"cp":[113.5599542,22.12348639],"name":"聖方濟各堂區","childNum":1}}],"UTF8Encoding":true});
}));
27 changes: 27 additions & 0 deletions pyecharts/templates/js/beijing.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/china.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/chongqing.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyecharts/templates/js/echarts-gl.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions pyecharts/templates/js/echarts.min.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/fujian.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/gansu.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyecharts/templates/js/get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl http://oog4yfyu0.bkt.clouddn.com/$1.js -o $1.js
27 changes: 27 additions & 0 deletions pyecharts/templates/js/guangdong.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/guangxi.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/guizhou.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/hainan.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/hebei.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/heilongjiang.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/henan.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/hubei.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/hunan.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/jiangsu.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/jiangxi.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/jilin.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/liaoning.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/neimenggu.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/ningxia.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/qinghai.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyecharts/templates/js/shandong.js

Large diffs are not rendered by default.

Loading

0 comments on commit 39a85f5

Please sign in to comment.