Skip to content

Commit 7cae5c8

Browse files
committed
A huge update for more charts and options
1 parent ca36e2e commit 7cae5c8

21 files changed

Lines changed: 1079 additions & 17 deletions

example/fixtures/product.json

Lines changed: 604 additions & 0 deletions
Large diffs are not rendered by default.

example/grid_example.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import List, Union
22

33
from pyecharts import options as opts
4-
from pyecharts.charts import Bar, Grid, Kline, Line, Page, Scatter
4+
from pyecharts.charts import Bar, Geo, Grid, Kline, Line, Page, Scatter
55
from pyecharts.faker import Collector, Faker
6+
from pyecharts.globals import ChartType, SymbolType
67

78
C = Collector()
89

@@ -540,4 +541,32 @@ def grid_overlap_multi_x_y_axis() -> Grid:
540541
return grid
541542

542543

544+
@C.funcs
545+
def grid_geo_bar() -> Grid:
546+
bar = (
547+
Bar()
548+
.add_xaxis(Faker.choose())
549+
.add_yaxis("商家A", Faker.values())
550+
.add_yaxis("商家B", Faker.values())
551+
.set_global_opts(legend_opts=opts.LegendOpts(pos_left="20%"))
552+
)
553+
geo = (
554+
Geo()
555+
.add_schema(maptype="china")
556+
.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
557+
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
558+
.set_global_opts(
559+
visualmap_opts=opts.VisualMapOpts(),
560+
title_opts=opts.TitleOpts(title="Grid-Geo-Bar"),
561+
)
562+
)
563+
564+
grid = (
565+
Grid()
566+
.add(bar, grid_opts=opts.GridOpts(pos_top="50%", pos_right="75%"))
567+
.add(geo, grid_opts=opts.GridOpts(pos_left="60%"))
568+
)
569+
return grid
570+
571+
543572
Page().add(*[fn() for fn, _ in C.charts]).render()

example/radar_example.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,61 @@ def radar_air_quality() -> Radar:
104104
return c
105105

106106

107+
@C.funcs
108+
def radar_angle_radius_axis_opts() -> Radar:
109+
data = [
110+
{
111+
"value": [4, -4, 2, 3, 0, 1],
112+
"name": "预算分配"
113+
},
114+
]
115+
c_schema = [
116+
{"name": "销售", "max": 4, "min": -4},
117+
{"name": "管理", "max": 4, "min": -4},
118+
{"name": "技术", "max": 4, "min": -4},
119+
{"name": "客服", "max": 4, "min": -4},
120+
{"name": "研发", "max": 4, "min": -4},
121+
{"name": "市场", "max": 4, "min": -4},
122+
]
123+
c = (
124+
Radar()
125+
.set_colors(["#4587E7"])
126+
.add_schema(
127+
schema=c_schema,
128+
shape="circle",
129+
center=["50%", "50%"],
130+
radius="80%",
131+
angleaxis_opts=opts.AngleAxisOpts(
132+
min_=0,
133+
max_=360,
134+
is_clockwise=False,
135+
interval=5,
136+
axistick_opts=opts.AxisTickOpts(is_show=False),
137+
axislabel_opts=opts.LabelOpts(is_show=False),
138+
axisline_opts=opts.AxisLineOpts(is_show=False),
139+
splitline_opts=opts.SplitLineOpts(is_show=False),
140+
),
141+
radiusaxis_opts=opts.RadiusAxisOpts(
142+
min_=-4,
143+
max_=4,
144+
interval=2,
145+
splitarea_opts=opts.SplitAreaOpts(
146+
is_show=True,
147+
areastyle_opts=opts.AreaStyleOpts(opacity=1),
148+
)
149+
),
150+
polar_opts=opts.PolarOpts(),
151+
splitarea_opt=opts.SplitAreaOpts(is_show=False),
152+
splitline_opt=opts.SplitLineOpts(is_show=False),
153+
)
154+
.add(
155+
series_name="预算",
156+
data=data,
157+
areastyle_opts=opts.AreaStyleOpts(opacity=0.1),
158+
linestyle_opts=opts.LineStyleOpts(width=1),
159+
)
160+
)
161+
return c
162+
163+
107164
Page().add(*[fn() for fn, _ in C.charts]).render()

example/sankey_example.py

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def sankey_base() -> Sankey:
3636
)
3737
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
3838
)
39-
4039
return c
4140

4241

@@ -58,4 +57,99 @@ def sankey_offical() -> Sankey:
5857
return c
5958

6059

60+
@C.funcs
61+
def sankey_vertical() -> Sankey:
62+
colors = [
63+
"#67001f",
64+
"#b2182b",
65+
"#d6604d",
66+
"#f4a582",
67+
"#fddbc7",
68+
"#d1e5f0",
69+
"#92c5de",
70+
"#4393c3",
71+
"#2166ac",
72+
"#053061",
73+
]
74+
nodes = [
75+
{"name": "a"},
76+
{"name": "b"},
77+
{"name": "a1"},
78+
{"name": "b1"},
79+
{"name": "c"},
80+
{"name": "e"},
81+
]
82+
links = [
83+
{"source": "a", "target": "a1", "value": 5},
84+
{"source": "e", "target": "b", "value": 3},
85+
{"source": "a", "target": "b1", "value": 3},
86+
{"source": "b1", "target": "a1", "value": 1},
87+
{"source": "b1", "target": "c", "value": 2},
88+
{"source": "b", "target": "c", "value": 1},
89+
]
90+
c = (
91+
Sankey()
92+
.set_colors(colors)
93+
.add(
94+
"sankey",
95+
nodes=nodes,
96+
links=links,
97+
pos_bottom="10%",
98+
focus_node_adjacency="allEdges",
99+
orient="vertical",
100+
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
101+
label_opts=opts.LabelOpts(position="top"),
102+
)
103+
.set_global_opts(
104+
title_opts=opts.TitleOpts(title="Sankey-Vertical"),
105+
tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"),
106+
)
107+
)
108+
return c
109+
110+
111+
@C.funcs
112+
def sankey_with_level_setting() -> Sankey:
113+
with open(os.path.join("fixtures", "product.json"), "r", encoding="utf-8") as f:
114+
j = json.load(f)
115+
c = (
116+
Sankey()
117+
.add(
118+
"sankey",
119+
nodes=j["nodes"],
120+
links=j["links"],
121+
pos_top="10%",
122+
focus_node_adjacency=True,
123+
levels=[
124+
opts.SankeyLevelsOpts(
125+
depth=0,
126+
itemstyle_opts=opts.ItemStyleOpts(color="#fbb4ae"),
127+
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
128+
),
129+
opts.SankeyLevelsOpts(
130+
depth=1,
131+
itemstyle_opts=opts.ItemStyleOpts(color="#b3cde3"),
132+
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
133+
),
134+
opts.SankeyLevelsOpts(
135+
depth=2,
136+
itemstyle_opts=opts.ItemStyleOpts(color="#ccebc5"),
137+
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
138+
),
139+
opts.SankeyLevelsOpts(
140+
depth=3,
141+
itemstyle_opts=opts.ItemStyleOpts(color="#decbe4"),
142+
linestyle_opts=opts.LineStyleOpts(color="source", opacity=0.6),
143+
),
144+
],
145+
linestyle_opt=opts.LineStyleOpts(curve=0.5),
146+
)
147+
.set_global_opts(
148+
title_opts=opts.TitleOpts(title="Sankey-Level Settings"),
149+
tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"),
150+
)
151+
)
152+
return c
153+
154+
61155
Page().add(*[fn() for fn, _ in C.charts]).render()

example/timeline_example.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pyecharts.commons.utils import JsCode
22

33
from pyecharts import options as opts
4-
from pyecharts.charts import Bar, BMap, Map, Page, Pie, Sankey, Timeline
4+
from pyecharts.charts import Bar, BMap, Grid, Map, Page, Pie, Sankey, Timeline
55
from pyecharts.faker import Collector, Faker
66

77
C = Collector()
@@ -23,6 +23,28 @@ def timeline_bar() -> Timeline:
2323
return tl
2424

2525

26+
@C.funcs
27+
def timeline_bar_reversal() -> Timeline:
28+
tl = Timeline()
29+
for i in range(2015, 2020):
30+
bar = (
31+
Bar()
32+
.add_xaxis(Faker.choose())
33+
.add_yaxis(
34+
"商家A", Faker.values(), label_opts=opts.LabelOpts(position="right")
35+
)
36+
.add_yaxis(
37+
"商家B", Faker.values(), label_opts=opts.LabelOpts(position="right")
38+
)
39+
.reversal_axis()
40+
.set_global_opts(
41+
title_opts=opts.TitleOpts("Timeline-Bar-Reversal (时间: {} 年)".format(i))
42+
)
43+
)
44+
tl.add(bar, "{}年".format(i))
45+
return tl
46+
47+
2648
@C.funcs
2749
def timeline_bar_with_graphic() -> Timeline:
2850
x = Faker.choose()
@@ -161,11 +183,7 @@ def timeline_sankey() -> Timeline:
161183
@C.funcs
162184
def timeline_bmap() -> Timeline:
163185
tl = Timeline()
164-
tl.add_schema(
165-
pos_left="50%",
166-
pos_right="10px",
167-
pos_bottom="15px",
168-
)
186+
tl.add_schema(pos_left="50%", pos_right="10px", pos_bottom="15px")
169187
for i in range(2015, 2020):
170188
bmap = (
171189
BMap()
@@ -177,7 +195,9 @@ def timeline_bmap() -> Timeline:
177195
)
178196
.set_global_opts(
179197
title_opts=opts.TitleOpts(title="Timeline-BMap-热力图-{}年".format(i)),
180-
visualmap_opts=opts.VisualMapOpts(pos_bottom="center", pos_right="10px"),
198+
visualmap_opts=opts.VisualMapOpts(
199+
pos_bottom="center", pos_right="10px"
200+
),
181201
tooltip_opts=opts.TooltipOpts(formatter=None),
182202
)
183203
)

pyecharts/charts/basic_charts/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def add(
3030
gravity: types.Numeric = 0.2,
3131
repulsion: types.Numeric = 50,
3232
edge_label: types.Label = None,
33-
edge_symbol: types.Optional[str] = None,
33+
edge_symbol: types.Union[types.Sequence[str], str] = None,
3434
edge_symbol_size: types.Numeric = 10,
3535
label_opts: types.Label = opts.LabelOpts(),
3636
linestyle_opts: types.LineStyle = opts.LineStyleOpts(),

pyecharts/charts/basic_charts/radar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ def add_schema(
2121
splitline_opt: types.SplitLine = opts.SplitLineOpts(is_show=True),
2222
splitarea_opt: types.SplitArea = opts.SplitAreaOpts(),
2323
axisline_opt: types.AxisLine = opts.AxisLineOpts(),
24+
radiusaxis_opts: types.RadiusAxis = None,
25+
angleaxis_opts: types.AngleAxis = None,
26+
polar_opts: types.Polar = None,
2427
):
28+
29+
self.options.update(
30+
radiusAxis=radiusaxis_opts,
31+
angleAxis=angleaxis_opts,
32+
polar=polar_opts,
33+
)
34+
2535
indicators = []
2636
for s in schema:
2737
if isinstance(s, opts.RadarIndicatorItem):

pyecharts/charts/basic_charts/sankey.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,45 @@ def add(
2020
links: types.Sequence,
2121
*,
2222
is_selected: bool = True,
23+
pos_left: types.Union[str, types.Numeric] = "5%",
24+
pos_top: types.Union[str, types.Numeric] = "5%",
25+
pos_right: types.Union[str, types.Numeric] = "20%",
26+
pos_bottom: types.Union[str, types.Numeric] = "5%",
2327
node_width: types.Numeric = 20,
2428
node_gap: types.Numeric = 8,
29+
node_align: str = "justify",
30+
layout_iterations: types.Numeric = 32,
31+
orient: str = "horizontal",
32+
is_draggable: bool = True,
33+
focus_node_adjacency: types.Union[bool, str] = False,
34+
levels: types.SankeyLevel = None,
2535
label_opts: types.Label = opts.LabelOpts(),
2636
linestyle_opt: types.LineStyle = opts.LineStyleOpts(),
2737
tooltip_opts: types.Tooltip = None,
2838
itemstyle_opts: types.ItemStyle = None,
2939
):
40+
if layout_iterations < 32:
41+
layout_iterations = 32
42+
3043
self._append_legend(series_name, is_selected)
3144
self.options.get("series").append(
3245
{
3346
"type": ChartType.SANKEY,
3447
"name": series_name,
3548
"data": nodes,
3649
"links": links,
50+
"left": pos_left,
51+
"top": pos_top,
52+
"right": pos_right,
53+
"bottom": pos_bottom,
3754
"nodeWidth": node_width,
3855
"nodeGap": node_gap,
56+
"nodeAlign": node_align,
57+
"layoutIteration": layout_iterations,
58+
"orient": orient,
59+
"draggable": is_draggable,
60+
"focusNodeAdjacency": focus_node_adjacency,
61+
"levels": levels,
3962
"label": label_opts,
4063
"lineStyle": linestyle_opt,
4164
"tooltip": tooltip_opts,

pyecharts/charts/basic_charts/tree.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def add(
4646
pos_bottom: types.Optional[str] = None,
4747
pos_right: types.Optional[str] = None,
4848
collapse_interval: types.Numeric = 0,
49+
is_roam: bool = False,
4950
is_expand_and_collapse: bool = True,
5051
initial_tree_depth: types.Optional[types.Numeric] = None,
5152
label_opts: types.Label = opts.LabelOpts(),
@@ -65,6 +66,7 @@ def add(
6566
"bottom": pos_bottom,
6667
"symbol": symbol,
6768
"symbolSize": symbol_size,
69+
"roam": is_roam,
6870
"expandAndCollapse": is_expand_and_collapse,
6971
"initialTreeDepth": initial_tree_depth,
7072
"layout": layout,

pyecharts/charts/basic_charts/treemap.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def add(
2323
pos_right: types.Optional[str] = None,
2424
pos_top: types.Optional[str] = None,
2525
pos_bottom: types.Optional[str] = None,
26+
width: types.Union[str, types.Numeric] = "80%",
27+
height: types.Union[str, types.Numeric] = "80%",
2628
drilldown_icon: str = "▶",
29+
roam: types.Union[bool, str] = True,
30+
node_click: types.Union[bool, str] = "zoomToNode",
2731
visual_min: types.Optional[types.Numeric] = None,
2832
visual_max: types.Optional[types.Numeric] = None,
2933
label_opts: types.Label = opts.LabelOpts(),
@@ -39,10 +43,14 @@ def add(
3943
"left": pos_left,
4044
"right": pos_right,
4145
"top": pos_top,
46+
"width": width,
47+
"height": height,
4248
"bottom": pos_bottom,
4349
"label": label_opts,
4450
"leafDepth": leaf_depth,
4551
"drillDownIcon": drilldown_icon,
52+
"roam": roam,
53+
"nodeClick": node_click,
4654
"visualMin": visual_min,
4755
"visualMax": visual_max,
4856
"tooltip": tooltip_opts,

0 commit comments

Comments
 (0)