예제 #1
0
def test_polar():
    # polar type 'scatter'
    import random
    data = [(i, random.randint(1, 100)) for i in range(101)]
    polar = Polar("极坐标系-散点图示例")
    polar.add("",
              data,
              boundary_gap=False,
              type='scatter',
              is_splitline_show=False,
              is_axisline_show=True)
    assert '"type": "scatter"' in polar._repr_html_()

    # polar type 'scatter'
    data_1 = [(10, random.randint(1, 100)) for i in range(300)]
    data_2 = [(11, random.randint(1, 100)) for i in range(300)]
    polar = Polar("极坐标系-散点图示例", width=1200, height=600)
    polar.add("", data_1, type='scatter')
    polar.add("", data_2, type='scatter')
    polar.render()

    # polar type 'effectScatter'
    data = [(i, random.randint(1, 100)) for i in range(10)]
    polar = Polar("极坐标系-动态散点图示例", width=1200, height=600)
    polar.add("", data, type='effectScatter', effect_scale=10, effect_period=5)
    assert '"type": "effectScatter"' in polar._repr_html_()

    # polar type 'barRadius'
    radius = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    polar = Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
    polar.add("A", [1, 2, 3, 4, 3, 5, 1],
              radius_data=radius,
              type='barRadius',
              is_stack=True)
    polar.add("B", [2, 4, 6, 1, 2, 3, 1],
              radius_data=radius,
              type='barRadius',
              is_stack=True)
    polar.add("C", [1, 2, 3, 4, 1, 2, 5],
              radius_data=radius,
              type='barRadius',
              is_stack=True)
    polar.render()

    # polar type 'barAngle'
    radius = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    polar = Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
    polar.add("", [1, 2, 3, 4, 3, 5, 1],
              radius_data=radius,
              type='barAngle',
              is_stack=True)
    polar.add("", [2, 4, 6, 1, 2, 3, 1],
              radius_data=radius,
              type='barAngle',
              is_stack=True)
    polar.add("", [1, 2, 3, 4, 1, 2, 5],
              radius_data=radius,
              type='barAngle',
              is_stack=True)
    polar.render()
예제 #2
0
def test_polor_custom_type():
    def render_item(params, api):
        values = [api.value(0), api.value(1)]
        coord = api.coord(values)
        size = api.size([1, 1], values)
        return {
            "type": "sector",
            "shape": {
                "cx": params.coordSys.cx,
                "cy": params.coordSys.cy,
                "r0": coord[2] - size[0] / 2,
                "r": coord[2] + size[0] / 2,
                "startAngle": coord[3] - size[1] / 2,
                "endAngle": coord[3] + size[1] / 2,
            },
            "style": api.style({"fill": api.visual("color")}),
        }

    polar = Polar("自定义渲染逻辑示例", width=1200, height=600)
    polar.add("", [[
        random.randint(0, 6),
        random.randint(1, 24),
        random.randint(1, 24),
    ] for _ in range(100)],
              render_item=render_item,
              type="custom",
              angle_data=X_TIME,
              radius_data=WEEK,
              is_visualmap=True,
              visual_range=[0, 30])
    html_content = polar._repr_html_()
    assert "function render_item(params, api) {" in html_content
    assert '"type": "custom"' in html_content
예제 #3
0
def test_polar_type_scatter_one():
    data = [(i, random.randint(1, 100)) for i in range(101)]
    polar = Polar("极坐标系-散点图示例")
    polar.add("",
              data,
              boundary_gap=False,
              type='scatter',
              is_splitline_show=False,
              is_axisline_show=True)
    assert '"type": "scatter"' in polar._repr_html_()
예제 #4
0
def test_polar_type_scatter_one():
    data = [(i, random.randint(1, 100)) for i in range(101)]
    polar = Polar("极坐标系-散点图示例")
    polar.add(
        "",
        data,
        boundary_gap=False,
        type="scatter",
        is_splitline_show=False,
        is_axisline_show=True,
    )
    assert '"type": "scatter"' in polar._repr_html_()
예제 #5
0
def test_polar_type_effectscatter():
    data = [(i, random.randint(1, 100)) for i in range(10)]
    polar = Polar("极坐标系-动态散点图示例", width=1200, height=600)
    polar.add("", data, type="effectScatter", effect_scale=10, effect_period=5)
    assert '"type": "effectScatter"' in polar._repr_html_()
예제 #6
0
def test_polar_type_effectscatter():
    data = [(i, random.randint(1, 100)) for i in range(10)]
    polar = Polar("极坐标系-动态散点图示例", width=1200, height=600)
    polar.add("", data, type='effectScatter', effect_scale=10,
              effect_period=5)
    assert '"type": "effectScatter"' in polar._repr_html_()