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))
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)
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)
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))
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())
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
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)
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
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
def show_config(self): """ 打印输出图形所有配置项 """ print(utils.json_dumps(self._option, indent=4))
def print_echarts_options(self): """ 打印输出图形所有配置项 """ print(utils.json_dumps(self._option, indent=4))
def get_echarts_options(self): """ 返回图形所有配置项 """ return utils.json_dumps(self._option, indent=4)