Polar refactor (#677)

* Update: polar refactor

* Update: 细节修正

* Fix: 测试修复
This commit is contained in:
陈键冬 2018-08-14 22:24:55 +08:00 committed by GitHub
parent 7fe8ca2d7d
commit 15d6123056
5 changed files with 234 additions and 255 deletions

View File

@ -2295,26 +2295,26 @@ polar.render()
```python
from pyecharts import Polar
radius = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
angle = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
polar = Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
polar.add(
"",
[1, 2, 3, 4, 3, 5, 1],
radius_data=radius,
angle_data=angle,
type="barAngle",
is_stack=True,
)
polar.add(
"",
[2, 4, 6, 1, 2, 3, 1],
radius_data=radius,
angle_data=angle,
type="barAngle",
is_stack=True,
)
polar.add(
"",
[1, 2, 3, 4, 1, 2, 5],
radius_data=radius,
angle_data=angle,
type="barAngle",
is_stack=True,
)

View File

@ -98,6 +98,38 @@ class Polar(Chart):
if kwargs.get("area_color", None) is None:
_area_style = None
_bar_type_series = {
"type": "bar",
"coordinateSystem": "polar",
"stack": is_stack,
"name": name,
"data": data,
}
_radius_axis_opt = {
"show": is_radiusaxis_show,
"type": polar_type,
"data": radius_data,
"min": _amin,
"max": _amax,
"axisLine": chart["axis_line"],
"axisLabel": {"rotate": rotate_step},
"z": radiusaxis_z_index,
}
_angle_axis_opt = {
"show": is_angleaxis_show,
"type": polar_type,
"data": angle_data,
"clockwise": is_clockwise,
"startAngle": start_angle,
"boundaryGap": boundary_gap,
"splitLine": chart["split_line"],
"axisLine": chart["axis_line"],
"axisLabel": {"interval": angleaxis_label_interval},
"z": angleaxis_z_index,
}
if type in ("scatter", "line"):
self._option.get("series").append(
{
@ -128,45 +160,14 @@ class Polar(Chart):
)
elif type == "barRadius":
self._option.get("series").append(
{
"type": "bar",
"stack": is_stack,
"name": name,
"coordinateSystem": "polar",
"data": data,
}
)
self._option.get("series").append(_bar_type_series)
self._option.update(angleAxis={})
self._option.update(
radiusAxis={
"type": polar_type,
"data": radius_data,
"z": radiusaxis_z_index,
}
)
self._option.update(radiusAxis=_radius_axis_opt)
elif type == "barAngle":
self._option.get("series").append(
{
"type": "bar",
"stack": is_stack,
"name": name,
"coordinateSystem": "polar",
"data": data,
}
)
self._option.get("series").append(_bar_type_series)
self._option.update(radiusAxis={"show": is_radiusaxis_show})
self._option.update(
angleAxis={
"show": is_angleaxis_show,
"type": polar_type,
"data": radius_data,
"z": angleaxis_z_index,
"startAngle": start_angle,
"splitLine": chart["split_line"],
}
)
self._option.update(angleAxis=_angle_axis_opt)
elif type == "custom":
assert render_item is not None
@ -181,30 +182,7 @@ class Polar(Chart):
)
if type not in ("barAngle", "barRadius"):
self._option.update(
angleAxis={
"show": is_angleaxis_show,
"type": polar_type,
"data": angle_data,
"clockwise": is_clockwise,
"startAngle": start_angle,
"boundaryGap": boundary_gap,
"splitLine": chart["split_line"],
"axisLine": chart["axis_line"],
"axisLabel": {"interval": angleaxis_label_interval}
}
)
self._option.update(
radiusAxis={
"show": is_radiusaxis_show,
"type": polar_type,
"data": radius_data,
"min": _amin,
"max": _amax,
"axisLine": chart["axis_line"],
"axisLabel": {"rotate": rotate_step},
"z": radiusaxis_z_index,
}
)
self._option.update(angleAxis=_angle_axis_opt)
self._option.update(radiusAxis=_radius_axis_opt)
self._option.update(polar={})
self._config_components(**kwargs)

View File

@ -6,262 +6,263 @@
"axisLine": {
"lineStyle": {
"normal": {
"curveness": 0,
"opacity": 1,
"type": "solid",
"curveness": 0,
"opacity": 1,
"type": "solid",
"width": 1
}
},
},
"show": true
},
"boundaryGap": false,
"clockwise": true,
"show": true,
"clockwise": true,
"show": true,
"splitLine": {
"lineStyle": {
"normal": {
"curveness": 0,
"opacity": 1,
"type": "solid",
"curveness": 0,
"opacity": 1,
"type": "solid",
"width": 1
}
},
},
"show": false
},
"startAngle": 90,
"type": "category"
},
},
"startAngle": 90,
"type": "category",
"z": 50
},
"color": [
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597",
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597",
"#f6f5ec"
],
],
"legend": [
{
"data": [
""
],
"left": "center",
"orient": "horizontal",
"selectedMode": "multiple",
"show": true,
],
"left": "center",
"orient": "horizontal",
"selectedMode": "multiple",
"show": true,
"textStyle": {
"fontSize": 12
},
},
"top": "top"
}
],
"polar": {},
],
"polar": {},
"radiusAxis": {
"axisLabel": {
"rotate": 0
},
},
"axisLine": {
"lineStyle": {
"normal": {
"curveness": 0,
"opacity": 1,
"type": "solid",
"curveness": 0,
"opacity": 1,
"type": "solid",
"width": 1
}
},
},
"show": true
},
"show": true,
"type": "category",
},
"show": true,
"type": "category",
"z": 50
},
},
"series": [
{
"coordinateSystem": "polar",
"coordinateSystem": "polar",
"data": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
100
],
],
"label": {
"emphasis": {
"show": true,
"show": true,
"textStyle": {
"fontSize": 12
}
},
},
"normal": {
"position": "top",
"show": false,
"position": "top",
"show": false,
"textStyle": {
"fontSize": 12
}
}
},
"symbol": "circle",
"symbolSize": 4,
},
"symbol": "circle",
"symbolSize": 4,
"type": "scatter"
}
],
"series_id": "1",
],
"series_id": "1",
"title": [
{
"left": "auto",
"left": "auto",
"subtextStyle": {
"fontSize": 12
},
"text": "\u6781\u5750\u6807\u7cfb-\u6563\u70b9\u56fe\u793a\u4f8b",
},
"text": "Polar",
"textStyle": {
"fontSize": 18
},
},
"top": "auto"
}
],
],
"toolbox": {
"feature": {
"dataView": {
"show": true
},
},
"restore": {
"show": true
},
},
"saveAsImage": {
"show": true,
"show": true,
"title": "\u4e0b\u8f7d\u56fe\u7247"
}
},
"left": "95%",
"orient": "vertical",
"show": true,
},
"left": "95%",
"orient": "vertical",
"show": true,
"top": "center"
},
},
"tooltip": {
"axisPointer": {
"type": "line"
},
"backgroundColor": "rgba(50,50,50,0.7)",
"borderColor": "#333",
"borderWidth": 0,
},
"backgroundColor": "rgba(50,50,50,0.7)",
"borderColor": "#333",
"borderWidth": 0,
"textStyle": {
"fontSize": 14
},
"trigger": "item",
},
"trigger": "item",
"triggerOn": "mousemove|click"
}
}
}

View File

@ -20,7 +20,7 @@ def test_polar_type_scatter_one(patched):
fixture = "polar_options.json"
patched.return_value = "1"
data = [i for i in range(101)]
polar = Polar("极坐标系-散点图示例")
polar = Polar("Polar")
polar.add(
"",
data,

View File

@ -70,21 +70,21 @@ def test_polar_type_barangle():
polar.add(
"",
[1, 2, 3, 4, 3, 5, 1],
radius_data=WEEK,
angle_data=WEEK,
type="barAngle",
is_stack=True,
)
polar.add(
"",
[2, 4, 6, 1, 2, 3, 1],
radius_data=WEEK,
anglle_data=WEEK,
type="barAngle",
is_stack=True,
)
polar.add(
"",
[1, 2, 3, 4, 1, 2, 5],
radius_data=WEEK,
angle_data=WEEK,
type="barAngle",
is_stack=True,
)