コード例 #1
0
def test_page():
    page = Page()
    line = Line("折线图示例")
    line.chart_id = "id_my_cell_line"
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
    )

    # pie
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center", width="600px")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    page.add([line, pie, create_a_bar(TITLE)])
    # Start render and test
    html = page._repr_html_()
    # Test base html structure
    assert html.count("<script>") == html.count("</script>") == 2
    assert html.count("<div") == html.count("</div>") == 3
    assert html.count("require.config") == html.count("function(echarts)") == 1
    # Test some chart attributes
    json_encoded_title = json.dumps(TITLE)
    assert json_encoded_title in html
    assert "nbextensions/echarts" in html  # default jshost
    assert html.count("height:400px") == 3
    assert html.count("width:600px") == 1
    assert html.count("width:800px") == 2
    assert html.count("id_my_cell_line") == 6
コード例 #2
0
ファイル: test_notebook.py プロジェクト: Jesszen/pyecharts
def test_page():
    page = Page()
    line = Line("折线图示例")
    line.chart_id = "id_my_cell_line"
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
    )

    # pie
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center", width="600px")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    page.add([line, pie, create_a_bar(TITLE)])
    # Start render and test
    html = page._repr_html_()
    # Test base html structure
    assert html.count("<script>") == html.count("</script>") == 2
    assert html.count("<div") == html.count("</div>") == 3
    assert html.count("require.config") == html.count("function(echarts)") == 1
    # Test some chart attributes
    json_encoded_title = json.dumps(TITLE)
    assert json_encoded_title in html
    assert "nbextensions/echarts" in html  # default jshost
    assert html.count("height:400px") == 3
    assert html.count("width:600px") == 1
    assert html.count("width:800px") == 2
    assert html.count("id_my_cell_line") == 6