diff --git a/pyecharts/__init__.py b/pyecharts/__init__.py
index cd2d1d0a..a634ef0f 100644
--- a/pyecharts/__init__.py
+++ b/pyecharts/__init__.py
@@ -38,4 +38,5 @@ from pyecharts.custom.timeline import Timeline
# misc
from pyecharts.template import online
+from pyecharts.engine import configure
from pyecharts.style import Style
diff --git a/pyecharts/conf.py b/pyecharts/conf.py
index 4affc9d7..b06fb040 100644
--- a/pyecharts/conf.py
+++ b/pyecharts/conf.py
@@ -2,11 +2,13 @@
# coding=utf-8
from __future__ import unicode_literals
+from pyecharts.utils import get_resource_dir
+
class PyEchartsConfig(object):
def __init__(self, echarts_template_dir='.', jshost=None, force_js_embed=False):
self.echarts_template_dir = echarts_template_dir
- jshost = jshost or ''
+ jshost = jshost or get_resource_dir('templates', 'js', 'echarts')
if jshost[-1:] in ('/', '\\'):
jshost = jshost[:-1]
self._jshost = jshost.rstrip('/')
diff --git a/pyecharts/engine.py b/pyecharts/engine.py
index 1d56f051..f1f02aa5 100644
--- a/pyecharts/engine.py
+++ b/pyecharts/engine.py
@@ -3,7 +3,7 @@
from __future__ import unicode_literals
from jinja2 import Environment, environmentfunction
-from pyecharts.utils import get_resource_dir, json_dumps
+from pyecharts.utils import json_dumps
from pyecharts import constants
from pyecharts.conf import DEFAULT_CONFIG
@@ -16,11 +16,17 @@ class Helpers(object):
:return:
"""
dependencies = []
+
+ def _add(_x):
+ if _x not in dependencies:
+ dependencies.append(_x)
+
for a in args:
if hasattr(a, 'js_dependencies'):
- dependencies.extend(a.js_dependencies)
+ for d in a.js_dependencies:
+ _add(d)
else:
- dependencies.append(a)
+ _add(a)
return dependencies
@staticmethod
@@ -92,43 +98,52 @@ def echarts_container(env, chart):
@environmentfunction
-def echarts_js_content(env, chart):
+def echarts_js_content(env, *charts):
"""
Render script html node for echarts initial code.
:param env:
:param chart:
:return:
"""
- content_fmt = '''
- var myChart_{chart_id} = echarts.init(document.getElementById('{chart_id}'));
- var option_{chart_id} = {options};
- myChart_{chart_id}.setOption(option_{chart_id});
- '''
- js_content = content_fmt.format(
- chart_id=chart.chart_id,
- options=json_dumps(chart.options, indent=4)
- )
- return ''.format(js_content)
+
+ print(charts)
+ contents = []
+ for chart in charts:
+ content_fmt = '''
+ var myChart_{chart_id} = echarts.init(document.getElementById('{chart_id}'));
+ var option_{chart_id} = {options};
+ myChart_{chart_id}.setOption(option_{chart_id});
+ '''
+ js_content = content_fmt.format(
+ chart_id=chart.chart_id,
+ options=json_dumps(chart.options, indent=4)
+ )
+ contents.append(js_content)
+ contents = '\n'.join(contents)
+ return ''.format(contents)
@environmentfunction
-def echarts_js_content_wrap(env, chart):
+def echarts_js_content_wrap(env, *charts):
"""
Render echarts initial code for a chart.
:param env:
- :param chart:
+ :param charts:
:return:
"""
- content_fmt = '''
- var myChart_{chart_id} = echarts.init(document.getElementById('{chart_id}'));
- var option_{chart_id} = {options};
- myChart_{chart_id}.setOption(option_{chart_id});
- '''
- js_content = content_fmt.format(
- chart_id=chart.chart_id,
- options=json_dumps(chart.options, indent=4)
- )
- return js_content
+ contents = []
+ for chart in charts:
+ content_fmt = '''
+ var myChart_{chart_id} = echarts.init(document.getElementById('{chart_id}'));
+ var option_{chart_id} = {options};
+ myChart_{chart_id}.setOption(option_{chart_id});
+ '''
+ js_content = content_fmt.format(
+ chart_id=chart.chart_id,
+ options=json_dumps(chart.options, indent=4)
+ )
+ contents.append(js_content)
+ return '\n'.join(contents)
class EchartsEnvironment(Environment):
diff --git a/pyecharts/templates/simple_page.html b/pyecharts/templates/simple_page.html
index 82268701..e13f5143 100644
--- a/pyecharts/templates/simple_page.html
+++ b/pyecharts/templates/simple_page.html
@@ -9,6 +9,6 @@
{% for chart in page %}
{{ echarts_container(chart) }}
{% endfor %}
-{{ echarts_js_content(page) }}
+{{ echarts_js_content(*page) }}