def test_echarts_js_dependencies_embed():
    env = EchartsEnvironment(pyecharts_config=PyEchartsConfig(
        jshost=get_resource_dir('templates', 'js', 'echarts')))
    tpl = env.from_string('{{ echarts_js_dependencies_embed("echarts") }}')
    bar = create_demo_bar()
    html = tpl.render(bar=bar)
    assert len(html) > 0
Beispiel #2
0
def _load_coordinates():
    """
    Load the coordinate dataset into the dictionary.
    :return:
    """
    with open(get_resource_dir('datasets', 'city_coordinates.json'),
              encoding='utf8') as f:
        return json.load(f)
Beispiel #3
0
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") }}')
    bar = create_demo_bar()
    html = tpl.render(bar=bar)
    assert len(html) > 0
Beispiel #4
0
def _load_coordinates():
    """
    Load the coordinate dataset into the dictionary.
    :return:
    """
    with open(get_resource_dir("datasets", "city_coordinates.json"),
              encoding="utf8") as f:
        return json.load(f)
Beispiel #5
0
def _load_coordinates():
    """
    Load the coordinate dataset into the dictionary.
    :return:
    """
    with open(
        get_resource_dir("datasets", "city_coordinates.json"), encoding="utf8"
    ) as f:
        return json.load(f)
Beispiel #6
0
    def get_cities_in_region(self, region):

        if region != "CN":
            return {}

        _local_data_file = get_resource_dir("datasets",
                                            "city_coordinates.json")
        with codecs.open(_local_data_file, encoding="utf8") as f:
            return json.load(f)
def test_echarts_js_dependencies_embed():
    env = EchartsEnvironment(
        pyecharts_config=PyEchartsConfig(
            jshost=get_resource_dir("templates", "js", "echarts")
        )
    )
    tpl = env.from_string('{{ echarts_js_dependencies_embed("echarts") }}')
    bar = create_demo_bar()
    html = tpl.render(bar=bar)
    assert len(html) > 0
Beispiel #8
0
def create_default_environment(file_type):
    """
    Create environment object with pyecharts default single PyEchartsConfig.

    :return: A new EchartsEnvironment object.
    """
    default_template_dir = utils.get_resource_dir("templates")
    config = conf.CURRENT_CONFIG
    echarts_env = ENV_MANAGER.get_a_environment(
        file_type,
        pyecharts_config=config,
        loader=FileSystemLoader(
            [config.echarts_template_dir, default_template_dir]),
    )
    return echarts_env
Beispiel #9
0
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") }}')
    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") }}')
    html2 = tpl2.render(bar=bar)
    assert len(html2) > 0
    assert html == html2
Beispiel #10
0
def create_default_environment(file_type):
    """
    Create environment object with pyecharts default single PyEchartsConfig.

    :return: A new EchartsEnvironment object.
    """
    default_template_dir = utils.get_resource_dir("templates")
    config = conf.CURRENT_CONFIG
    echarts_env = ENV_MANAGER.get_a_environment(
        file_type,
        pyecharts_config=config,
        loader=FileSystemLoader(
            [config.echarts_template_dir, default_template_dir]
        ),
    )
    return echarts_env
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") }}')
    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") }}')
    html2 = tpl2.render(bar=bar)
    assert len(html2) > 0
    assert html == html2
Beispiel #12
0
def test_get_resource_dir():
    path = get_resource_dir("templates")
    expected = os.path.join(os.getcwd(), "..", "pyecharts", "templates")
    eq_(path, os.path.abspath(expected))
Beispiel #13
0
def test_get_resource_dir():
    path = get_resource_dir('templates')
    expected = os.path.join(os.getcwd(), '..', 'pyecharts', 'templates')
    eq_(path, os.path.abspath(expected))
Beispiel #14
0
def test_get_resource_dir():
    path = get_resource_dir("templates")
    expected = os.path.join(os.getcwd(), "..", "pyecharts", "templates")
    eq_(path, os.path.abspath(expected))
Beispiel #15
0
#!/usr/bin/env python
# coding=utf-8
from __future__ import unicode_literals

from jinja2 import Environment, FileSystemLoader
import pyecharts.constants as constants
from pyecharts.utils import get_resource_dir

# Single Singleton Instance for jinja2
JINJA2_ENV = Environment(loader=FileSystemLoader(
    get_resource_dir('templates')),
                         keep_trailing_newline=True,
                         trim_blocks=True,
                         lstrip_blocks=True)


def produce_require_configuration(dependencies, jshost):
    """

    :param dependencies:
    :param jshost:
    :return:
    """
    _d = ensure_echarts_is_in_the_front(dependencies)
    # if no nick name register, we treat the location as location.js
    require_conf_items = [
        "'%s': '%s/%s'" %
        (key, jshost, constants.DEFAULT_JS_LIBRARIES.get(key, key))
        for key in _d
    ]
    require_libraries = ["'%s'" % key for key in _d]
Beispiel #16
0
 def _load_countries_into_memory(self):
     _region_dict = get_resource_dir("datasets", REGION_DB)
     with codecs.open(_region_dict, encoding="utf-8") as file_handle:
         self.region_dict = json.load(file_handle)
Beispiel #17
0
# coding=utf-8
from __future__ import unicode_literals

import os
import json
import codecs

from pyecharts.utils import get_resource_dir
import pyecharts.constants as constants

SCRIPT_FILE_PATH = get_resource_dir('templates', 'js', 'echarts')
# Path constants for template dir

DEFAULT_TEMPLATE_DIR = get_resource_dir('templates')
DEFAULT_ECHARTS_REGISTRY = os.path.join(
    get_resource_dir('templates'), 'js', 'registry.json')
# Load js & map file index into a dictionary.


with codecs.open(DEFAULT_ECHARTS_REGISTRY, 'r', 'utf-8') as f:
    content = f.read()
    CONFIG = json.loads(content)

DEFAULT_JS_LIBRARIES = CONFIG['FILE_MAP']  # {<Pinyin>:<Js File Name>}
CITY_NAME_PINYIN_MAP = CONFIG['PINYIN_MAP']  # {<Chinese Name>:<Pinyin>}


class PyEchartsConfig(object):
    def __init__(self, echarts_template_dir='.', jshost=SCRIPT_FILE_PATH,
                 force_js_embed=False):
        self.echarts_template_dir = echarts_template_dir
Beispiel #18
0
# coding=utf-8
from __future__ import unicode_literals

import os
import json
import codecs
import warnings

from pyecharts.utils import get_resource_dir
import pyecharts.constants as constants

SCRIPT_LOCAL_JSHOST = get_resource_dir('templates', 'js', 'echarts')
# Path constants for template dir

DEFAULT_TEMPLATE_DIR = get_resource_dir('templates')
DEFAULT_ECHARTS_REGISTRY = os.path.join(get_resource_dir('templates'), 'js',
                                        'echarts', 'registry.json')
# Load js & map file index into a dictionary.

with codecs.open(DEFAULT_ECHARTS_REGISTRY, 'r', 'utf-8') as f:
    content = f.read()
    CONFIG = json.loads(content)

DEFAULT_JS_LIBRARIES = CONFIG['FILE_MAP']  # {<Pinyin>:<Js File Name>}
CITY_NAME_PINYIN_MAP = CONFIG['PINYIN_MAP']  # {<Chinese Name>:<Pinyin>}


class PyEchartsConfig(object):
    def __init__(self,
                 echarts_template_dir='.',
                 jshost=None,
Beispiel #19
0
def test_get_resource_dir():
    path = get_resource_dir('templates')
    expected = os.path.join(os.getcwd(), '..', 'pyecharts', 'templates')
    eq_(path, os.path.abspath(expected))
# coding=utf-8
from __future__ import unicode_literals

from pyecharts.js_extensions import EXTENSION_MANAGER
from pyecharts.utils import get_resource_dir

# Path constants for template dir
DEFAULT_TEMPLATE_DIR = get_resource_dir('templates')


class PyEchartsConfig(object):
    def __init__(self,
                 echarts_template_dir='.',
                 jshost=None,
                 force_js_embed=False):
        self.echarts_template_dir = echarts_template_dir
        self._jshost = remove_trailing_slashes(jshost)
        self.force_js_embed = force_js_embed
        self.hosted_on_github = False

    @property
    def js_embed(self):
        """ Determine whether to use embed code in <script> tag.
        """
        if self.force_js_embed:
            return True
        else:
            return self.jshost is None

    @property
    def jshost(self):