Skip to content

Commit

Permalink
update geo, kline, sankey charts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhailin-Leo committed Aug 16, 2023
1 parent 9acd818 commit fd1fb59
Show file tree
Hide file tree
Showing 8 changed files with 622 additions and 514 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ omit =
pyecharts/render/templates/*
setup.py
install.py
test.py
test/*

[report]
show_missing = True
Expand Down
31 changes: 31 additions & 0 deletions pyecharts/charts/basic_charts/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def add(
symbol_size: types.Numeric = 12,
blur_size: types.Numeric = 20,
point_size: types.Numeric = 20,
radius: types.Optional[types.Sequence] = None,
color: types.Optional[str] = None,
is_polyline: bool = False,
is_large: bool = False,
Expand Down Expand Up @@ -186,6 +187,33 @@ def add(
"data": data,
}
)
elif type_ == ChartType.PIE:
if not radius:
radius = ["0%", "5%"]

if not tooltip_opts:
tooltip_opts = {"formatter": "{b}: {c} ({d}%)"}

if not isinstance(data[0], opts.PieItem):
data = [{"name": n, "value": v} for n, v in data]

self.options.get("series").append(
{
"type": type_,
"coordinateSystem": self._coordinate_system,
"data": data,
"tooltip": tooltip_opts,
"label": label_opts,
"center": self.get_coordinate(series_name),
"radius": radius,
}
)
# Legend (hard code here)
legend = self.options.get("legend")[0]
pie_series_name = [d.get("name") for d in data]
if len(legend.get("data")) < len(pie_series_name):
legend["data"] = pie_series_name

return self


Expand All @@ -207,6 +235,9 @@ def __init__(
self._is_ignore_nonexistent_coord = is_ignore_nonexistent_coord

def _feed_data(self, data_pair: types.Sequence, type_: str) -> types.Sequence:
if type_ == ChartType.PIE:
return data_pair

result = []
for n, v in data_pair:
try:
Expand Down
2 changes: 2 additions & 0 deletions pyecharts/charts/basic_charts/kline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def add_yaxis(
y_axis: types.Sequence[types.Union[opts.CandleStickItem, dict]],
*,
color_by: types.Optional[str] = "series",
bar_width: types.Optional[types.Numeric] = None,
layout: types.Optional[str] = None,
xaxis_index: types.Optional[types.Numeric] = None,
yaxis_index: types.Optional[types.Numeric] = None,
Expand All @@ -46,6 +47,7 @@ def add_yaxis(
"name": series_name,
"colorBy": color_by,
"layout": layout,
"barWidth": bar_width,
"xAxisIndex": xaxis_index,
"yAxisIndex": yaxis_index,
"data": y_axis,
Expand Down
2 changes: 2 additions & 0 deletions pyecharts/charts/basic_charts/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def add(
layout_iterations: types.Numeric = 32,
orient: str = "horizontal",
is_draggable: bool = True,
edge_label_opt: types.Label = None,
focus_node_mode: str = "none",
levels: types.SankeyLevel = None,
label_opts: types.Label = opts.LabelOpts(),
Expand Down Expand Up @@ -56,6 +57,7 @@ def add(
"layoutIteration": layout_iterations,
"orient": orient,
"draggable": is_draggable,
"edgeLabel": edge_label_opt,
"emphasis": {
"focus": focus_node_mode,
},
Expand Down
Loading

0 comments on commit fd1fb59

Please sign in to comment.