Ejemplo n.º 1
0
def test_themeriver_basefake_writer(fake_writer):
    data = [
        ["2015/11/08", 10, "DQ"],
        ["2015/11/20", 30, "TY"],
        ["2015/11/08", 21, "SS"],
        ["2015/11/14", 7, "QG"],
        ["2015/11/22", 4, "SY"],
        ["2015/11/20", 26, "DD"],
    ]
    c = ThemeRiver().add(
        ["DQ", "TY", "SS", "QG", "SY", "DD"],
        data,
        singleaxis_opts=opts.SingleAxisOpts(type_="time", pos_bottom="10%"),
    )
    c.render()
    _, content = fake_writer.call_args[0]
    eq_(c.theme, "white")
    eq_(c.renderer, "canvas")
def draw_river_picture(series_name, data, to_file, svg_name):
    """
    主题河流图
    :param series_name: [str]
    :param data: [[date, value, series_name]]
    :param svg_name: svg文件
    :param to_file: 结果文件
    :return:
    """
    bar = ThemeRiver(init_opts=opts.InitOpts(width="800px", height="600px", bg_color='white')) \
        .add(
        series_name=series_name,
        data=data,
        singleaxis_opts=opts.SingleAxisOpts(
            pos_top="2%",
            pos_bottom="10%",
            pos_right="20%",
            type_="time",
            name_textstyle_opts=opts.TextStyleOpts(font_size=25),
            axislabel_opts=opts.LabelOpts(font_size=25)
        ),
        label_opts=opts.LabelOpts(is_show=False, position='bottom', distance='200px'),
    ) \
        .set_global_opts(
        tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="line"),
        toolbox_opts=opts.ToolboxOpts(
            feature=opts.ToolBoxFeatureOpts(
                # data_zoom=opts.ToolBoxFeatureDataZoomOpts(is_show=False),
                # brush=opts.ToolBoxFeatureBrushOpts(is_show=False),
            )
        ),
        legend_opts=opts.LegendOpts(type_="scroll",
                                    pos_left="82%",
                                    pos_top="18%",
                                    orient="vertical",
                                    backgroundColor='rgb(255, 255, 255)',
                                    item_width=40,
                                    item_height=20,
                                    textstyle_opts=opts.TextStyleOpts(font_size=25)
                                    )
    )
    make_snapshot(snapshot, bar.render(to_file), svg_name)  # 生成svg图片