Skip to content

Commit

Permalink
Code Improvement (pyecharts#462)
Browse files Browse the repository at this point in the history
* 🔨 remove magic constants

* 📚 advertise that render_notebook is removed. fix pyecharts#456 forever
  • Loading branch information
chfw authored and chenjiandongx committed Mar 23, 2018
1 parent 1851393 commit ba7ee71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pyecharts exposes chart API and template API so that it can work on some common

### Work on Jupyter Notebook

In the Notebook cell ,you can simply call the instance itself to diplay the chart.
In the Notebook cell, you can simply pass on chart instance itself to Jupyter, which will diplay the chart. Please note **render_notebook** function has been removed.

All chart classes in pyecharts implement the `_repr_html_` interface about [IPython Rich Display](http://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display) .

Expand Down
5 changes: 5 additions & 0 deletions pyecharts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def cast(seq):
v_lst.append(seq[key])
return k_lst, v_lst

def render_notebook(self):
warnings.warn('Implementation has been removed. ' +
'Please pass the chart instance directly to Jupyter.' +
'If you need more help, please read documentation')

def _repr_html_(self):
""" 渲染配置项并将图形显示在 notebook 中
chart/page => charts
Expand Down
2 changes: 2 additions & 0 deletions pyecharts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
JPEG = 'jpeg'
DEFAULT_HTML = 'html'
JUPYTER_PRESENTATIONS = [SVG, PNG, JPEG, DEFAULT_HTML]
ENVIRONMENT_PLUGIN_TYPE = 'pyecharts_environment'
JS_EXTENSION_PLUGIN_TYPE = 'pyecharts_js_extension'

SYMBOL = {
"plane": 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.'
Expand Down
12 changes: 8 additions & 4 deletions pyecharts/engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# coding=utf-8
from __future__ import unicode_literals

import codecs

from jinja2 import Environment, FileSystemLoader, environmentfunction, Markup
from lml.plugin import PluginManager, PluginInfo

import codecs
import pyecharts.conf as conf
import pyecharts.utils as utils
import pyecharts.constants as constants

from lml.plugin import PluginManager, PluginInfo

LINK_SCRIPT_FORMATTER = '<script type="text/javascript" src="{}"></script>'
EMBED_SCRIPT_FORMATTER = '<script type="text/javascript">\n{}\n</script>'
Expand Down Expand Up @@ -136,7 +138,8 @@ def __init__(self, *args, **kwargs):
self.globals.update(ECHAERTS_TEMPLATE_FUNCTIONS)


@PluginInfo('pyecharts_environment', tags=['html'])
@PluginInfo(constants.ENVIRONMENT_PLUGIN_TYPE,
tags=[constants.DEFAULT_HTML])
class EchartsEnvironment(BaseEnvironment):
"""
Built-in jinja2 template engine for pyecharts
Expand Down Expand Up @@ -214,7 +217,8 @@ def __init__(self):
Register with lml that this class manages 'pyecharts_environment'
extension
"""
super(EnvironmentManager, self).__init__('pyecharts_environment')
super(EnvironmentManager, self).__init__(
constants.ENVIRONMENT_PLUGIN_TYPE)

def get_a_environment(self, file_type, **kwargs):
"""
Expand Down
6 changes: 4 additions & 2 deletions pyecharts/js_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lml.plugin import PluginManager

import pyecharts.exceptions as exceptions
import pyecharts.constants as constants

# here are all plugins from pyecharts team
OFFICIAL_PLUGINS = [
Expand Down Expand Up @@ -84,7 +85,8 @@ def _resolve_jshost(self, jshost, use_github=False):

class JsExtensionManager(PluginManager):
def __init__(self):
super(JsExtensionManager, self).__init__('pyecharts_js_extension')
super(JsExtensionManager, self).__init__(
constants.JS_EXTENSION_PLUGIN_TYPE)
self.js_extensions = []

def get_all_extensions(self):
Expand All @@ -101,7 +103,7 @@ def get_a_extension(self, name):
if len(self.js_extensions) == 0:
self.get_all_extensions()
for __extension__ in self.js_extensions:
if __extension__.registry['JS_FOLDER'] == name:
if __extension__.registry[REGISTRY_JS_FOLDER] == name:
return __extension__
return None

Expand Down

0 comments on commit ba7ee71

Please sign in to comment.