Exemplo n.º 1
0
def test_merge_js_dependencies():
    # PyEchartsConfig.merge_js_dependencies(str1, str2,...)
    eq_(['echarts', 'fujian'],
        PyEchartsConfig.merge_js_dependencies('echarts', 'fujian'))

    # PyEchartsConfig.merge_js_dependencies(chart)
    class MockChart(object):
        def __init__(self, js_dependencies):
            self.js_dependencies = js_dependencies

    ch1 = MockChart(['echarts', 'fujian', 'zhengjiang', 'anhui'])
    eq_(['echarts', 'fujian', 'zhengjiang', 'anhui'],
        PyEchartsConfig.merge_js_dependencies(ch1))

    # PyEchartsConfig.merge_js_dependencies(chart1, chart2 )
    ch1 = MockChart(['echarts'])
    ch2 = MockChart(['echarts', 'beijing'])
    eq_(['echarts', 'beijing'],
        PyEchartsConfig.merge_js_dependencies(ch1, ch2))

    # PyEchartsConfig.merge_js_dependencies(*chart_list)

    mock_page = [ch1, ch2]
    ch1 = MockChart(['echarts'])
    ch2 = MockChart(['echarts', 'beijing'])
    eq_(['echarts', 'beijing'],
        PyEchartsConfig.merge_js_dependencies(*mock_page))
Exemplo n.º 2
0
def test_merge_js_dependencies():
    # PyEchartsConfig.merge_js_dependencies(str1, str2,...)
    eq_(['echarts', 'fujian'],
        PyEchartsConfig.merge_js_dependencies('echarts', 'fujian'))

    # PyEchartsConfig.merge_js_dependencies(chart)
    class MockChart(object):
        def __init__(self, js_dependencies):
            self.js_dependencies = js_dependencies

    ch1 = MockChart(['echarts', 'fujian', 'zhengjiang', 'anhui'])
    eq_(
        ['echarts', 'fujian', 'zhengjiang', 'anhui'],
        PyEchartsConfig.merge_js_dependencies(ch1)
    )

    # PyEchartsConfig.merge_js_dependencies(chart1, chart2 )
    ch1 = MockChart(['echarts'])
    ch2 = MockChart(['echarts', 'beijing'])
    eq_(
        ['echarts', 'beijing'],
        PyEchartsConfig.merge_js_dependencies(ch1, ch2)
    )

    # PyEchartsConfig.merge_js_dependencies(*chart_list)

    mock_page = [ch1, ch2]
    ch1 = MockChart(['echarts'])
    ch2 = MockChart(['echarts', 'beijing'])
    eq_(
        ['echarts', 'beijing'],
        PyEchartsConfig.merge_js_dependencies(*mock_page)
    )
Exemplo n.º 3
0
def test_with_default_value():
    target_config = PyEchartsConfig()
    eq_(SCRIPT_FILE_PATH, target_config.jshost)

    assert target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 4
0
def test_custom_local_jshost():
    target_config = PyEchartsConfig(jshost='/static/js/')
    eq_('/static/js', target_config.jshost)

    assert not target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 5
0
def test_custom_local_jshost():
    target_config = PyEchartsConfig(jshost="/static/js/")
    eq_("/static/js", target_config.jshost)

    assert not target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 6
0
def test_pyecharts_remote_jshost():
    target_config = PyEchartsConfig(jshost=DEFAULT_JUPYTER_GITHUB_URL)
    eq_('https://chfw.github.io/jupyter-echarts/echarts', target_config.jshost)

    assert target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 7
0
def test_custom_remote_jshost():
    target_config = PyEchartsConfig(
        jshost='https://cdn.bootcss.com/echarts/3.7.2/')
    eq_('https://cdn.bootcss.com/echarts/3.7.2', target_config.jshost)

    assert not target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 8
0
def test_custom_remote_jshost():
    target_config = PyEchartsConfig(
        jshost="https://cdn.bootcss.com/echarts/3.7.2/")
    eq_("https://cdn.bootcss.com/echarts/3.7.2", target_config.jshost)

    assert not target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
def test_echarts_js_dependencies():
    env = EchartsEnvironment(pyecharts_config=PyEchartsConfig(
        jshost='http://localhost/echarts'))
    tpl = env.from_string('{{ echarts_js_dependencies(bar) }}')
    bar = create_demo_bar()
    html = tpl.render(bar=bar)
    assert '<script type="text/javascript" src="http://localhost/echarts/echarts.min.js"></script>' == html  # flake8: noqa
Exemplo n.º 10
0
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
Exemplo n.º 11
0
def test_echarts_js_dependencies():
    env = EchartsEnvironment(pyecharts_config=PyEchartsConfig()
                             # pyecharts_config=PyEchartsConfig()
                             )
    tpl = env.get_template('tpl_demo.html')
    bar = create_demo_bar()
    html = tpl.render(bar=bar)
    # flake8: noqa
    write_utf8_html_file('my_tpl_demo4.html', html)
Exemplo n.º 12
0
def dataframe_line_plot(df, title='', path=None):
    option = {
        'title': {
            'text': title,
            'left': 'center'
        },
        'legend': {
            'show': True,
            'orient': 'vertical',
            'right': '9%',
            'top': '3%'
        },
        'xAxis': {
            'type': 'time',
            'axisLine': {
                'onZero': False
            }
        },
        'yAxis': {
            'axisLine': {
                'onZero': False
            }
        },
        'dataZoom': [{
            'type': 'slider',
            'xAxisIndex': 0,
            'start': 0,
            'end': 50
        }]
    }

    time = [ts.timestamp() / 0.001 for ts in df.index]
    series = []
    for channel in df.columns:
        values = df[channel].values.tolist()
        data = [(t, x) for t, x in zip(time, values)]
        series.append({
            'type': 'line',
            'showSymbol': False,
            'name': channel,
            'data': data
        })
    option.update({'series': series})

    line_plot = Line()
    line_plot._option.update(option)

    conf = PyEchartsConfig(echarts_template_dir='html',
                           jshost='js',
                           force_js_embed=False)
    env = EchartsEnvironment(pyecharts_config=conf)
    tpl = env.get_template('template.html')
    html = tpl.render(chart=line_plot)
    write_utf8_html_file(path, html)
Exemplo n.º 13
0
def environment(**options):
    """
    Create a environment object for settings.TEMPLATE.Jinja2.ENGINE
    :param options:
    :return:
    """
    env = BaseEnvironment(
        pyecharts_config=PyEchartsConfig(jshost=settings.STATIC_URL),
        **options)
    env.globals.update({
        'static': staticfiles_storage.url,
        'url': reverse,
    })
    return env
Exemplo n.º 14
0
    def genReport(self, filetype="html", timeout=60):
        attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
        v1 = [5, 20, 36, 10, 75, 90]
        v2 = [10, 25, 8, 60, 20, 80]
        bar = Bar("柱状图数据堆叠示例")
        bar.add("商家A", attr, v1, is_stack=True, is_toolbox_show=False)
        bar.add("商家B", attr, v2, is_stack=True)

        config = PyEchartsConfig(echarts_template_dir=Report.TEMPLATE_DIR)
        env = EchartsEnvironment(pyecharts_config=config)
        tpl = env.get_template(Report.REPORT_HTML)
        html = tpl.render(bar=bar)
        name = 'report_%s'%self.getUID()
        write_utf8_html_file("%s/%s.html"%(Report.OUT_DIR, name), html)
        
        if "pdf"==filetype:
            cmd = "phantomjs make_pdf.js %s"%name
            self.PopenWithTimeout(cmd, cwd=Report.OUT_DIR, timeout=timeout)
Exemplo n.º 15
0
def test_custom_local_jshost():
    target_config = PyEchartsConfig(jshost='/static/js/')
    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'))

    assert not target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 16
0
def test_with_default_value():
    target_config = PyEchartsConfig()
    eq_(SCRIPT_LOCAL_JSHOST, target_config.jshost)
    eq_(SCRIPT_LOCAL_JSHOST, target_config.get_current_jshost_for_script())
    eq_(JUPYTER_LOCAL_JSHOST, target_config.get_current_jshost_for_jupyter())
    eq_('http://demo',
        target_config.get_current_jshost_for_script('http://demo'))

    assert target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 17
0
def test_echarts_js_in_first():
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("",
            attr,
            value,
            maptype='广东',
            is_visualmap=True,
            visual_text_color='#000')
    env = EchartsEnvironment(pyecharts_config=PyEchartsConfig(
        jshost='http://localhost/echarts'))
    tpl = env.from_string('{{ echarts_js_dependencies(m) }}')
    html = tpl.render(m=map)
    echarts_js_pos = html.find('echarts.min.js')
    guangdong_js_pos = html.find('guangdong.js')
    assert echarts_js_pos > -1
    assert guangdong_js_pos > -1
    assert echarts_js_pos < guangdong_js_pos
Exemplo n.º 18
0
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'))

    assert target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
def test_echarts_js_in_first():
    value = [20, 190, 253, 77, 65]
    attr = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市"]
    map = Map("广东地图示例", width=1200, height=600)
    map.add(
        "",
        attr,
        value,
        maptype="广东",
        is_visualmap=True,
        visual_text_color="#000",
    )
    env = EchartsEnvironment(pyecharts_config=PyEchartsConfig(
        jshost="http://localhost/echarts"))
    tpl = env.from_string("{{ echarts_js_dependencies(m) }}")
    html = tpl.render(m=map)
    echarts_js_pos = html.find("echarts.min.js")
    guangdong_js_pos = html.find("guangdong.js")
    assert echarts_js_pos > -1
    assert guangdong_js_pos > -1
    assert echarts_js_pos < guangdong_js_pos
Exemplo n.º 20
0
def test_custom_remote_jshost():
    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'))

    assert not target_config.js_embed

    target_config.force_js_embed = True

    assert target_config.js_embed
Exemplo n.º 21
0
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile('../config.py')
    app.register_blueprint(main_blueprint)
    app.register_blueprint(auth_blueprint, url_prefix='/auth')
    app.register_blueprint(api_blueprint, url_prefix='/api')
    app.register_blueprint(user_blueprint, url_prefix='/user')
    app.jinja_env.globals.update(ECHAERTS_TEMPLATE_FUNCTIONS)
    app.jinja_env.pyecharts_config = PyEchartsConfig(
        jshost='https://cdn.bootcss.com/echarts/3.7.2')

    db.init_app(app)
    login_manager.init_app(app)

    for key in ext_dict:
        ext_dict[key].init_app(app)

    def add_template_globals():
        return app.config['GLOBAL_TEMPLATE_ARGS']

    app.context_processor(add_template_globals)

    return app
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description: 
"""

from __future__ import unicode_literals

from pyecharts import Bar
from pyecharts.conf import PyEchartsConfig
from pyecharts.engine import EchartsEnvironment
from pyecharts.utils import write_utf8_html_file

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", attr, v1, is_stack=True)
bar.add("商家B", attr, v2, is_stack=True)

config = PyEchartsConfig(echarts_template_dir='./',
                         jshost='https://cdn.bootcss.com/echarts/3.6.2')
env = EchartsEnvironment(pyecharts_config=config)
tpl = env.get_template('tpl.html')

html = tpl.render(bar=bar)
write_utf8_html_file('my_tpl_demo2.html', html)
Exemplo n.º 23
0
def test_get_js_library():
    test_config = PyEchartsConfig()
    actual = test_config.get_js_library("abc")
    assert actual is None
Exemplo n.º 24
0
def test_get_js_library():
    test_config = PyEchartsConfig()
    actual = test_config.get_js_library("abc")
    assert actual is None
Exemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     super(FlaskEchartsEnvironment, self).__init__(*args, **kwargs)
     self.pyecharts_config = PyEchartsConfig(jshost='https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0')
     self.globals.update(ECHAERTS_TEMPLATE_FUNCTIONS)
 def __init__(self, *args, **kwargs):
     super(FlaskEchartsEnvironment, self).__init__(*args, **kwargs)
     self.pyecharts_config = PyEchartsConfig(jshost='/static/js')
     self.globals.update(ECHAERTS_TEMPLATE_FUNCTIONS)
Exemplo n.º 27
0
from pyecharts import Line
from pyecharts.conf import PyEchartsConfig
from pyecharts.engine import EchartsEnvironment
from pyecharts.utils import write_utf8_html_file
from pyecharts import ThemeRiver

attr = ['a', 'b', 'c', 'd']
v1 = [40000, 50000, 60000, 70000]
pie = Pie("饼图-星级玫瑰图示例", title_pos='center', width=900)
pie.add("7-17",
        attr,
        v1,
        center=[75, 50],
        is_random=True,
        radius=[30, 75],
        rosetype='area',
        is_legend_show=False,
        is_label_show=True)
#pie.render()
config = PyEchartsConfig(echarts_template_dir='./')
env = EchartsEnvironment(pyecharts_config=config)
#tpl = env.get_template('chart_template.html')
#html = tpl.render(pie=pie)
write_utf8_html_file('chart_out.tif')

##
from pyecharts import Gauge
gauge = Gauge("仪表盘示例")
gauge.add("业务指标", "完成率", 66.66)
gauge.show_config()
gauge.render()