Exemplo n.º 1
0
def test_page_with_custom_host():
    local_host = 'http://localhost:8000'
    page = Page(jshost=local_host)
    v1 = [5, 20, 36, 10, 75, 90]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    page.add(bar)

    html = page._repr_html_()
    assert local_host in html
    assert constants.CONFIGURATION['HOST'] != local_host
Exemplo n.º 2
0
def test_online_with_page():
    old_host = constants.CONFIGURATION['HOST']
    online()
    page = Page()
    v1 = [5, 20, 36, 10, 75, 90]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    page.add(bar)

    html = page._repr_html_()
    assert DEFAULT_HOST in html
    constants.CONFIGURATION['HOST'] = old_host
def test_online_with_page():
    old_host = constants.CONFIGURATION['HOST']
    online()
    page = Page()
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", attr, v1, is_stack=True)
    page.add(bar)

    html = page._repr_html_()
    assert DEFAULT_HOST in html
    constants.CONFIGURATION['HOST'] = old_host
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
def test_page_extra_html_text_label():
    page = Page()
    line = Line("折线图示例",
                extra_html_text_label=["LINE TEXT LABEL", "color:red"])
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    page.add(line)

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

    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图", extra_html_text_label=["BAR TEXT LABEL"])
    bar.add("商家B", CLOTHES, v2)
    page.add(bar)

    html_content = page._repr_html_()
    assert '<p style="">BAR TEXT LABEL</p>' in html_content
    assert '<p style="color:red">LINE TEXT LABEL</p>' in html_content
    assert '<p style="">PIE TEXT LABEL</p>' in html_content