enable the integration with the existing echarts-maps assets, that are hosted on github

This commit is contained in:
chfw 2019-03-27 22:04:52 +00:00
parent 0abc29239e
commit a1f7d6ea88
3 changed files with 36 additions and 8 deletions

View File

@ -1,5 +1,5 @@
# coding=utf-8
from pyecharts.datasets import FILENAMES
from pyecharts.datasets import FILENAMES, EXTRA
class OrderedSet:
@ -22,9 +22,17 @@ def filter_js_func(fn: str) -> str:
def produce_require_dict(js_dependencies, js_host) -> dict:
confs, libraries = [], []
for name in js_dependencies.items:
f, _ = FILENAMES[name]
confs.append("'{}':'{}{}'".format(name, js_host, f))
libraries.append("'{}'".format(name))
if name in FILENAMES:
f, _ = FILENAMES[name]
confs.append("'{}':'{}{}'".format(name, js_host, f))
libraries.append("'{}'".format(name))
else:
for url, files in EXTRA.items():
if name in files:
f, _ = files[name]
confs.append("'{}':'{}{}'".format(name, url, f))
libraries.append("'{}'".format(name))
break
return dict(config_items=confs, libraries=libraries)

View File

@ -1,11 +1,24 @@
# coding=utf-8
import json
import os
import urllib.request
__HERE = os.path.abspath(os.path.dirname(__file__))
EXTRA = {}
with open(os.path.join(__HERE, "map_filename.json"), "r", encoding="utf8") as f:
FILENAMES = json.load(f)
with open(os.path.join(__HERE, "city_coordinates.json"), "r", encoding="utf8") as f:
COORDINATES = json.load(f)
def register(additional_asset_url):
contents = urllib.request.urlopen(additional_asset_url + '/registry.json').read()
contents = json.loads(contents)
files = {}
for name, pinyin in contents['PINYIN_MAP'].items():
file_name = contents['FILE_MAP'][pinyin]
files[name] = [file_name, 'js']
EXTRA[contents['GITHUB_URL'] + '/'] = files

View File

@ -6,7 +6,7 @@ from jinja2 import Environment
from pyecharts.commons.types import Any, Optional
from ..commons.utils import write_utf8_html_file
from ..datasets import FILENAMES
from ..datasets import FILENAMES, EXTRA
from ..globals import CurrentConfig
@ -21,8 +21,15 @@ class RenderEngine:
links = []
for dep in chart.js_dependencies.items:
# TODO: if?
f, ext = FILENAMES[dep]
links.append("{}{}.{}".format(chart.js_host, f, ext))
if dep in FILENAMES:
f, ext = FILENAMES[dep]
links.append("{}{}.{}".format(chart.js_host, f, ext))
else:
for url, files in EXTRA.items():
if dep in files:
f, ext = files[dep]
links.append("{}{}.{}".format(url, f, ext))
break
chart.dependencies = links
return chart