Exemplo n.º 1
0
def test_json_encoder():
    """
    Test json encoder.
    :return:
    """
    data = date(2017, 1, 1)
    eq_(json.dumps({'date': '2017-01-01', 'a': '1'}, indent=0),
        json_dumps({'date': data, 'a': '1'}))

    data2 = {'np_list': np.array(['a', 'b', 'c'])}
    data2_e = {'np_list': ['a', 'b', 'c']}
    eq_(json.dumps(data2_e, indent=0), json_dumps(data2))
Exemplo n.º 2
0
 def _render_notebook_component_(self):
     """ 为 notebook 渲染组件模板
     """
     my_option = utils.json_dumps(self._option, indent=4)
     return engine.render("notebook_chart_component.html",
                          my_option=my_option,
                          chart_id=self._chart_id)
Exemplo n.º 3
0
 def _render_notebook_component_(self):
     """ 为 notebook 渲染组件模板
     """
     my_option = utils.json_dumps(self._option, indent=4)
     return engine.render_notebook(
         "notebook_chart_component.html",
         my_option=my_option,
         chart_id=self._chart_id)
Exemplo n.º 4
0
def test_json_encoder():
    """
    Test json encoder.
    :return:
    """
    data = date(2017, 1, 1)
    eq_(json.dumps({
        'date': '2017-01-01',
        'a': '1'
    }, indent=0), json_dumps({
        'date': data,
        'a': '1'
    }))

    data2 = {'np_list': np.array(['a', 'b', 'c'])}
    data2_e = {'np_list': ['a', 'b', 'c']}
    eq_(json.dumps(data2_e, indent=0), json_dumps(data2))
Exemplo n.º 5
0
def index():
    _bar = bar_chart()
    return render_template('pyecharts2.html',
                           chart_id=_bar.chart_id,
                           host=REMOTE_HOST,
                           my_width="100%",
                           my_height=600,
                           my_option=json_dumps(_bar.options),
                           script_list=_bar.get_js_dependencies())
Exemplo n.º 6
0
 def render_embed(self):
     """ 渲染图表的所有配置项,为 web pages 服务,不过需先提供
     所需要的js 依赖文件
     """
     my_option = utils.json_dumps(self._option, indent=4)
     html = engine.render('chart_component.html',
                          my_option=my_option,
                          chart_id=self._chart_id,
                          my_width=self.width,
                          my_height=self.height)
     return html
Exemplo n.º 7
0
 def render_embed(self):
     """ 渲染图表的所有配置项,为 web pages 服务,不过需先提供
     所需要的js 依赖文件
     """
     my_option = utils.json_dumps(self._option, indent=4)
     html = engine.render('chart_component.html',
                          my_option=my_option,
                          chart_id=self._chart_id,
                          my_width=self.width,
                          my_height=self.height)
     return html
Exemplo n.º 8
0
def build_echarts_initial_fragment(*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)
        return '\n'.join(contents)
Exemplo n.º 9
0
def generate_js_content(*charts):
    """ Generate the initial code fragment for one or some chart instances.

    :param charts:
    :return:
    """
    contents = []
    for chart in charts:
        js_content = CHART_CONFIG_FORMATTER.format(
            chart_id=chart.chart_id,
            options=utils.json_dumps(chart.options, indent=4))
        contents.append(js_content)
    contents = '\n'.join(contents)
    return contents
Exemplo n.º 10
0
def generate_js_content(*charts):
    """ Generate the initial code fragment for one or some chart instances.

    :param charts:
    :return:
    """
    contents = []
    for chart in charts:
        js_content = CHART_CONFIG_FORMATTER.format(
            chart_id=chart.chart_id,
            options=utils.json_dumps(chart.options, indent=4)
        )
        contents.append(js_content)
    contents = '\n'.join(contents)
    return contents
Exemplo n.º 11
0
 def show_config(self):
     """ 打印输出图形所有配置项
     """
     print(utils.json_dumps(self._option, indent=4))
Exemplo n.º 12
0
 def print_echarts_options(self):
     """ 打印输出图形所有配置项
     """
     print(utils.json_dumps(self._option, indent=4))
Exemplo n.º 13
0
 def show_config(self):
     """ 打印输出图形所有配置项
     """
     print(utils.json_dumps(self._option, indent=4))
Exemplo n.º 14
0
 def get_echarts_options(self):
     """ 返回图形所有配置项
     """
     return utils.json_dumps(self._option, indent=4)