mirror of
https://github.com/pyecharts/pyecharts.git
synced 2025-12-08 20:59:23 +00:00
Update code style with maxline=79
This commit is contained in:
parent
6663b9e0a1
commit
6caa22be41
@ -94,28 +94,6 @@ class Base(object):
|
||||
html = tpl.render(**context)
|
||||
utils.write_utf8_html_file(path, html)
|
||||
|
||||
#
|
||||
# def _render(self, path="render.html"):
|
||||
# """ 渲染配置项并生成 html 文件
|
||||
#
|
||||
# :param path:
|
||||
# 文件保存路径
|
||||
# """
|
||||
# _tmp = "local.html"
|
||||
# my_option = utils.json_dumps(self._option, indent=4)
|
||||
# default_engine = template.create_buildin_template_engine()
|
||||
# tmp = default_engine.get_template(_tmp)
|
||||
# script_list = template.produce_html_script_list(self._js_dependencies)
|
||||
# html = tmp.render(
|
||||
# my_option=my_option,
|
||||
# chart_id=self._chart_id,
|
||||
# script_list=script_list,
|
||||
# page_title=self._page_title,
|
||||
# my_width=self.width,
|
||||
# my_height=self.height)
|
||||
# html = utils.freeze_js(html)
|
||||
# utils.write_utf8_html_file(path, html)
|
||||
|
||||
@staticmethod
|
||||
def cast(seq):
|
||||
""" 转换数据序列,将带字典和元组类型的序列转换为 k_lst,v_lst 两个列表
|
||||
|
||||
@ -2,11 +2,13 @@
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pyecharts.constants import SCRIPT_LOCAL_JSHOST, JUPYTER_LOCAL_JSHOST, DEFAULT_HOST
|
||||
from pyecharts.constants import SCRIPT_LOCAL_JSHOST, JUPYTER_LOCAL_JSHOST, \
|
||||
DEFAULT_HOST
|
||||
|
||||
|
||||
class PyEchartsConfig(object):
|
||||
def __init__(self, echarts_template_dir='.', jshost=None, force_js_embed=False):
|
||||
def __init__(self, echarts_template_dir='.', jshost=None,
|
||||
force_js_embed=False):
|
||||
self.echarts_template_dir = echarts_template_dir
|
||||
jshost = jshost or SCRIPT_LOCAL_JSHOST
|
||||
self._jshost = PyEchartsConfig.convert_jshost_string(jshost)
|
||||
|
||||
@ -17,10 +17,6 @@ JUPYTER_LOCAL_JSHOST = '/nbextensions/echarts'
|
||||
|
||||
DEFAULT_TEMPLATE_DIR = get_resource_dir('templates')
|
||||
|
||||
# CONFIGURATION = dict(
|
||||
# HOST=JUPYTER_LOCAL_JSHOST # TODO Delete this key from the dictionary
|
||||
# )
|
||||
|
||||
# Load js & map file index into a dictionary.
|
||||
|
||||
DEFAULT_ECHARTS_REGISTRY = os.path.join(
|
||||
|
||||
@ -32,30 +32,13 @@ class Page(list):
|
||||
template_name='simple_page.html',
|
||||
object_name='page',
|
||||
extra_context=None):
|
||||
tpl = template.create_buildin_template_engine().get_template(template_name)
|
||||
tpl = template.create_buildin_template_engine().get_template(
|
||||
template_name)
|
||||
context = {object_name: self}
|
||||
context.update(extra_context or {})
|
||||
html = tpl.render(**context)
|
||||
utils.write_utf8_html_file(path, html)
|
||||
|
||||
# def _render(self, path="render.html"):
|
||||
# """
|
||||
# Produce rendered charts in a html file
|
||||
#
|
||||
# :param path:
|
||||
# :return:
|
||||
# """
|
||||
# template_name = "multicharts.html"
|
||||
# chart_content = self.render_embed()
|
||||
# dependencies = self._merge_dependencies()
|
||||
# script_list = template.produce_html_script_list(dependencies)
|
||||
# tmp = template.create_buildin_template_engine().get_template(template_name)
|
||||
# html = tmp.render(multi_chart_content=chart_content,
|
||||
# page_title=self._page_title,
|
||||
# script_list=script_list)
|
||||
# html = utils.freeze_js(html)
|
||||
# utils.write_utf8_html_file(path, html)
|
||||
|
||||
def render_embed(self):
|
||||
"""
|
||||
Produce rendered charts in html for embedding purpose
|
||||
|
||||
@ -58,11 +58,13 @@ def echarts_js_dependencies(env, *args):
|
||||
|
||||
if current_config.js_embed:
|
||||
contents = Helpers.read_file_contents_from_local(js_names)
|
||||
return '\n'.join(['<script type="text/javascript">\n{}\n</script>'.format(c) for c in contents])
|
||||
embed_script_tpl_str = '<script type="text/javascript">\n{}\n</script>'
|
||||
return '\n'.join([embed_script_tpl_str.format(c) for c in contents])
|
||||
else:
|
||||
jshost = current_config.jshost
|
||||
js_links = Helpers.generate_js_link(jshost, js_names)
|
||||
return '\n'.join(['<script type="text/javascript" src="{}"></script>'.format(j) for j in js_links])
|
||||
link_script_tpl_str = '<script type="text/javascript" src="{}"></script>'
|
||||
return '\n'.join([link_script_tpl_str.format(j) for j in js_links])
|
||||
|
||||
|
||||
@environmentfunction
|
||||
@ -76,7 +78,8 @@ def echarts_js_dependencies_embed(env, *args):
|
||||
dependencies = Helpers.merge_js_dependencies(*args)
|
||||
js_names = [constants.DEFAULT_JS_LIBRARIES.get(x, x) for x in dependencies]
|
||||
contents = Helpers.read_file_contents_from_local(js_names)
|
||||
return '\n'.join(['<script type="text/javascript">\n{}\n</script>'.format(c) for c in contents])
|
||||
embed_script_tpl_str = '<script type="text/javascript">\n{}\n</script>'
|
||||
return '\n'.join([embed_script_tpl_str.format(c) for c in contents])
|
||||
|
||||
|
||||
@environmentfunction
|
||||
@ -90,7 +93,7 @@ def echarts_container(env, chart):
|
||||
|
||||
def ex_wh(x):
|
||||
"""
|
||||
Extend width/height to all values.See http://www.w3school.com.cn/cssref/pr_dim_width.asp
|
||||
Extend width/height to all values.
|
||||
:param x:
|
||||
:return:
|
||||
"""
|
||||
@ -136,7 +139,8 @@ def echarts_js_content(env, *charts):
|
||||
:param chart:
|
||||
:return:
|
||||
"""
|
||||
return '<script type="text/javascript">\n{}\n</script>'.format(generate_js_content(*charts))
|
||||
return '<script type="text/javascript">\n{}\n</script>'.format(
|
||||
generate_js_content(*charts))
|
||||
|
||||
|
||||
@environmentfunction
|
||||
@ -159,7 +163,8 @@ class EchartsEnvironment(Environment):
|
||||
self._pyecharts_config = pyecharts_config or PyEchartsConfig()
|
||||
loader = kwargs.pop('loader', None)
|
||||
if loader is None:
|
||||
loader = FileSystemLoader(self._pyecharts_config.echarts_template_dir)
|
||||
loader = FileSystemLoader(
|
||||
self._pyecharts_config.echarts_template_dir)
|
||||
super(EchartsEnvironment, self).__init__(
|
||||
keep_trailing_newline=True,
|
||||
trim_blocks=True,
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import warnings
|
||||
|
||||
from jinja2 import FileSystemLoader
|
||||
|
||||
import pyecharts.constants as constants
|
||||
@ -37,14 +35,14 @@ def configure(
|
||||
|
||||
|
||||
def online(host=constants.DEFAULT_HOST):
|
||||
warnings.warn('The online will be deprecated,use "pyecharts.configure" instead.', DeprecationWarning)
|
||||
CURRENT_CONFIG.jshost = host
|
||||
|
||||
|
||||
def create_buildin_template_engine():
|
||||
return EchartsEnvironment(
|
||||
pyecharts_config=CURRENT_CONFIG,
|
||||
loader=FileSystemLoader([CURRENT_CONFIG.echarts_template_dir, DEFAULT_TEMPLATE_DIR])
|
||||
loader=FileSystemLoader(
|
||||
[CURRENT_CONFIG.echarts_template_dir, DEFAULT_TEMPLATE_DIR])
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,8 @@ from __future__ import unicode_literals
|
||||
from nose.tools import eq_
|
||||
|
||||
from pyecharts.conf import PyEchartsConfig
|
||||
from pyecharts.constants import DEFAULT_HOST, SCRIPT_LOCAL_JSHOST, JUPYTER_LOCAL_JSHOST
|
||||
from pyecharts.constants import DEFAULT_HOST, SCRIPT_LOCAL_JSHOST, \
|
||||
JUPYTER_LOCAL_JSHOST
|
||||
|
||||
|
||||
def test_with_default_value():
|
||||
@ -28,9 +29,12 @@ def test_with_default_value():
|
||||
def test_pyecharts_remote_jshost():
|
||||
target_config = PyEchartsConfig(jshost=DEFAULT_HOST)
|
||||
eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.jshost)
|
||||
eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.get_current_jshost_for_script())
|
||||
eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.get_current_jshost_for_jupyter())
|
||||
eq_('/static/js/echarts', target_config.get_current_jshost_for_jupyter('/static/js/echarts'))
|
||||
eq_('https://chfw.github.io/jupyter-echarts/echarts',
|
||||
target_config.get_current_jshost_for_script())
|
||||
eq_('https://chfw.github.io/jupyter-echarts/echarts',
|
||||
target_config.get_current_jshost_for_jupyter())
|
||||
eq_('/static/js/echarts',
|
||||
target_config.get_current_jshost_for_jupyter('/static/js/echarts'))
|
||||
|
||||
assert target_config.js_embed
|
||||
|
||||
@ -44,7 +48,8 @@ def test_custom_local_jshost():
|
||||
eq_('/static/js', target_config.jshost)
|
||||
eq_('/static/js', target_config.get_current_jshost_for_script())
|
||||
eq_('/static/js', target_config.get_current_jshost_for_jupyter())
|
||||
eq_('/static/js/echarts', target_config.get_current_jshost_for_jupyter('/static/js/echarts'))
|
||||
eq_('/static/js/echarts',
|
||||
target_config.get_current_jshost_for_jupyter('/static/js/echarts'))
|
||||
|
||||
assert not target_config.js_embed
|
||||
|
||||
@ -54,11 +59,15 @@ def test_custom_local_jshost():
|
||||
|
||||
|
||||
def test_custom_remote_jshost():
|
||||
target_config = PyEchartsConfig(jshost='https://cdn.bootcss.com/echarts/3.7.2/')
|
||||
target_config = PyEchartsConfig(
|
||||
jshost='https://cdn.bootcss.com/echarts/3.7.2/')
|
||||
eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.jshost)
|
||||
eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.get_current_jshost_for_script())
|
||||
eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.get_current_jshost_for_jupyter())
|
||||
eq_('/static/js/echarts', target_config.get_current_jshost_for_jupyter('/static/js/echarts'))
|
||||
eq_('https://cdn.bootcss.com/echarts/3.7.2',
|
||||
target_config.get_current_jshost_for_script())
|
||||
eq_('https://cdn.bootcss.com/echarts/3.7.2',
|
||||
target_config.get_current_jshost_for_jupyter())
|
||||
eq_('/static/js/echarts',
|
||||
target_config.get_current_jshost_for_jupyter('/static/js/echarts'))
|
||||
|
||||
assert not target_config.js_embed
|
||||
|
||||
|
||||
@ -31,7 +31,10 @@ def create_three():
|
||||
|
||||
|
||||
def test_custom_templates():
|
||||
configure(jshost='https://chfw.github.io/jupyter-echarts/echarts', force_js_embed=False)
|
||||
configure(
|
||||
jshost='https://chfw.github.io/jupyter-echarts/echarts',
|
||||
force_js_embed=False
|
||||
)
|
||||
page = create_three()
|
||||
# page.js_dependencies = ['echarts.min']
|
||||
page.render(path='new_version_page.html')
|
||||
|
||||
@ -28,14 +28,17 @@ def test_echarts_js_dependencies():
|
||||
|
||||
|
||||
def test_echarts_js_dependencies_embed():
|
||||
ECHARTS_ENV.configure_pyecharts(jshost=get_resource_dir('templates', 'js', 'echarts'))
|
||||
tpl = ECHARTS_ENV.from_string('{{ echarts_js_dependencies_embed("echarts.min") }}')
|
||||
ECHARTS_ENV.configure_pyecharts(
|
||||
jshost=get_resource_dir('templates', 'js', 'echarts'))
|
||||
tpl = ECHARTS_ENV.from_string(
|
||||
'{{ echarts_js_dependencies_embed("echarts.min") }}')
|
||||
bar = create_demo_bar()
|
||||
html = tpl.render(bar=bar)
|
||||
assert len(html) > 0
|
||||
|
||||
# echarts_js_dependencies equals echarts_js_dependencies_embed when use local host.
|
||||
tpl2 = ECHARTS_ENV.from_string('{{ echarts_js_dependencies("echarts.min") }}')
|
||||
tpl2 = ECHARTS_ENV.from_string(
|
||||
'{{ echarts_js_dependencies("echarts.min") }}')
|
||||
html2 = tpl2.render(bar=bar)
|
||||
assert len(html2) > 0
|
||||
assert html == html2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user