Skip to content

Commit

Permalink
Update config and Prepare for next version (#1578)
Browse files Browse the repository at this point in the history
* add more parameters

* add some charts item and update some configs

* update map support world map show China Provinces

* change bar.add_yaxis.yaxis_data to y_axis as same as the doc and other charts.
fix an error of toolbox_opts when bar in stack mode.

* commit huge changes -- by using latest stable version echart.min.js

* update test code and fix CI error

* fix CI error

* update gauge config and test code
  • Loading branch information
sunhailin-Leo committed Jun 7, 2020
1 parent 547f8d4 commit d7f9fb8
Show file tree
Hide file tree
Showing 31 changed files with 662 additions and 83 deletions.
11 changes: 10 additions & 1 deletion pyecharts/charts/base.py
@@ -1,11 +1,12 @@
import datetime
import uuid
import warnings

import simplejson as json
from jinja2 import Environment

from ..commons import utils
from ..globals import CurrentConfig, RenderType, ThemeType
from ..globals import CurrentConfig, RenderType, ThemeType, WarningType
from ..options import InitOpts
from ..options.global_options import AnimationOpts
from ..options.series_options import BasicOpts
Expand Down Expand Up @@ -40,6 +41,14 @@ def __init__(self, init_opts: Union[InitOpts, dict] = InitOpts()):
self.options.update(_opts.get("animationOpts", AnimationOpts()).opts)
self._is_geo_chart: bool = False

if WarningType.ShowWarning:
warnings.resetwarnings()
warnings.warn(
message="pyecharts 各 Chart 将在 1.9.0 版本开始强制使用 ChartItem 进行数据项配置",
category=PendingDeprecationWarning,
stacklevel=2,
)

def get_options(self) -> dict:
return utils.remove_key_with_none_value(self.options)

Expand Down
38 changes: 34 additions & 4 deletions pyecharts/charts/basic_charts/bar.py
Expand Up @@ -15,15 +15,30 @@ class Bar(RectChart):
def add_yaxis(
self,
series_name: str,
yaxis_data: types.Sequence[types.Union[types.Numeric, opts.BarItem, dict]],
y_axis: types.Sequence[types.Union[types.Numeric, opts.BarItem, dict]],
*,
is_selected: bool = True,
xaxis_index: types.Optional[types.Numeric] = None,
yaxis_index: types.Optional[types.Numeric] = None,
is_legend_hover_link: bool = True,
color: types.Optional[str] = None,
is_show_background: bool = False,
background_style: types.Union[types.BarBackground, dict, None] = None,
stack: types.Optional[str] = None,
bar_width: types.Union[types.Numeric, str] = None,
bar_max_width: types.Union[types.Numeric, str] = None,
bar_min_width: types.Union[types.Numeric, str] = None,
bar_min_height: types.Numeric = 0,
category_gap: types.Union[types.Numeric, str] = "20%",
gap: types.Optional[str] = None,
gap: types.Optional[str] = "30%",
is_large: bool = False,
large_threshold: types.Numeric = 400,
dimensions: types.Union[types.Sequence, None] = None,
series_layout_by: str = "column",
dataset_index: types.Numeric = 0,
is_clip: bool = True,
z_level: types.Numeric = 0,
z: types.Numeric = 2,
label_opts: types.Label = opts.LabelOpts(),
markpoint_opts: types.MarkPoint = None,
markline_opts: types.MarkLine = None,
Expand All @@ -35,18 +50,33 @@ def add_yaxis(
self._append_legend(series_name, is_selected)

if self.options.get("dataset") is not None:
yaxis_data = None
y_axis = None

self.options.get("series").append(
{
"type": ChartType.BAR,
"name": series_name,
"xAxisIndex": xaxis_index,
"yAxisIndex": yaxis_index,
"data": yaxis_data,
"legendHoverLink": is_legend_hover_link,
"data": y_axis,
"showBackground": is_show_background,
"backgroundStyle": background_style,
"stack": stack,
"barWidth": bar_width,
"barMaxWidth": bar_max_width,
"barMinWidth": bar_min_width,
"barMinHeight": bar_min_height,
"barCategoryGap": category_gap,
"barGap": gap,
"large": is_large,
"largeThreshold": large_threshold,
"dimensions": dimensions,
"seriesLayoutBy": series_layout_by,
"datasetIndex": dataset_index,
"clip": is_clip,
"zlevel": z_level,
"z": z,
"label": label_opts,
"markPoint": markpoint_opts,
"markLine": markline_opts,
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/boxplot.py
Expand Up @@ -16,7 +16,7 @@ class Boxplot(RectChart):
def add_yaxis(
self,
series_name: str,
y_axis: types.Sequence,
y_axis: types.Sequence[types.Union[opts.BoxplotItem, dict]],
*,
is_selected: bool = True,
xaxis_index: types.Optional[types.Numeric] = None,
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/effectscatter.py
Expand Up @@ -14,7 +14,7 @@ class EffectScatter(RectChart):
def add_yaxis(
self,
series_name: str,
y_axis: types.Sequence,
y_axis: types.Sequence[types.Union[opts.EffectScatterItem, dict]],
*,
is_selected: bool = True,
xaxis_index: types.Optional[types.Numeric] = None,
Expand Down
10 changes: 8 additions & 2 deletions pyecharts/charts/basic_charts/gauge.py
Expand Up @@ -23,8 +23,12 @@ def add(
radius: types.Union[types.Numeric, str] = "75%",
start_angle: types.Numeric = 225,
end_angle: types.Numeric = -45,
title_label_opts: types.Label = opts.LabelOpts(),
detail_label_opts: types.Label = opts.LabelOpts(formatter="{value}%"),
is_clock_wise: bool = True,
title_label_opts: types.GaugeTitle = opts.GaugeTitleOpts(),
detail_label_opts: types.GaugeDetail = opts.GaugeDetailOpts(
formatter="{value}%"
),
pointer: types.GaugePointer = opts.GaugePointerOpts(),
tooltip_opts: types.Tooltip = None,
axisline_opts: types.AxisLine = None,
itemstyle_opts: types.ItemStyle = None,
Expand All @@ -43,9 +47,11 @@ def add(
"radius": radius,
"startAngle": start_angle,
"endAngle": end_angle,
"clockwise": is_clock_wise,
"data": [{"name": n, "value": v} for n, v in data_pair],
"tooltip": tooltip_opts,
"axisLine": axisline_opts,
"pointer": pointer,
"itemStyle": itemstyle_opts,
}
)
Expand Down
4 changes: 2 additions & 2 deletions pyecharts/charts/basic_charts/heatmap.py
Expand Up @@ -20,8 +20,8 @@ def __init__(self, init_opts: types.Init = opts.InitOpts()):
def add_yaxis(
self,
series_name: str,
yaxis_data: types.Sequence,
value: types.Sequence,
yaxis_data: types.Sequence[types.Union[opts.HeatMapItem, dict]],
value: types.Sequence[types.Union[opts.HeatMapItem, dict]],
*,
is_selected: bool = True,
xaxis_index: types.Optional[types.Numeric] = None,
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/kline.py
Expand Up @@ -24,7 +24,7 @@ def __init__(self, init_opts: types.Init = opts.InitOpts()):
def add_yaxis(
self,
series_name: str,
y_axis: types.Sequence,
y_axis: types.Sequence[types.Union[opts.CandleStickItem, dict]],
*,
is_selected: bool = True,
xaxis_index: types.Optional[types.Numeric] = None,
Expand Down
4 changes: 3 additions & 1 deletion pyecharts/charts/basic_charts/line.py
Expand Up @@ -15,7 +15,7 @@ class Line(RectChart):
def add_yaxis(
self,
series_name: str,
y_axis: types.Sequence,
y_axis: types.Sequence[types.Union[opts.LineItem, dict]],
*,
is_selected: bool = True,
is_connect_nones: bool = False,
Expand All @@ -27,6 +27,7 @@ def add_yaxis(
symbol_size: types.Union[types.Numeric, types.Sequence] = 4,
stack: types.Optional[str] = None,
is_smooth: bool = False,
is_clip: bool = True,
is_step: bool = False,
is_hover_animation: bool = True,
z_level: types.Numeric = 0,
Expand Down Expand Up @@ -56,6 +57,7 @@ def add_yaxis(
"symbolSize": symbol_size,
"showSymbol": is_symbol_show,
"smooth": is_smooth,
"clip": is_clip,
"step": is_step,
"stack": stack,
"data": data,
Expand Down
12 changes: 11 additions & 1 deletion pyecharts/charts/basic_charts/liquid.py
Expand Up @@ -22,8 +22,11 @@ def add(
*,
shape: str = "circle",
color: types.Optional[types.Sequence[str]] = None,
background_color: types.Union[str, dict, None] = None,
is_animation: bool = True,
is_outline_show: bool = True,
outline_border_distance: types.Numeric = 8,
outline_itemstyle_opts: types.ItemStyle = None,
center: types.Sequence = None,
tooltip_opts: types.Tooltip = None,
label_opts: types.Label = opts.LabelOpts(font_size=50, position="inside"),
Expand All @@ -44,7 +47,14 @@ def add(
"animationDurationUpdate": _animation_dur_update,
"color": color,
"shape": shape,
"outline": {"show": is_outline_show},
"backgroundStyle": {
"color": background_color,
},
"outline": {
"show": is_outline_show,
"borderDistance": outline_border_distance,
"itemStyle": outline_itemstyle_opts,
},
"tooltip": tooltip_opts,
"label": label_opts,
"center": center,
Expand Down
9 changes: 7 additions & 2 deletions pyecharts/charts/basic_charts/map.py
Expand Up @@ -14,7 +14,7 @@ class MapMixin:
def add(
self,
series_name: str,
data_pair: types.Sequence,
data_pair: types.Sequence[types.Union[types.Sequence, opts.MapItem, dict]],
maptype: str = "china",
*,
is_selected: bool = True,
Expand All @@ -31,7 +31,12 @@ def add(
emphasis_itemstyle_opts: types.ItemStyle = None,
):
self.js_dependencies.add(maptype)
data = [{"name": n, "value": v} for n, v in data_pair]

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

self._append_legend(series_name, is_selected)
self.options.get("series").append(
{
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/parallel.py
Expand Up @@ -37,7 +37,7 @@ def add_schema(
def add(
self,
series_name: str,
data: types.Sequence,
data: types.Sequence[types.Union[opts.ParallelItem, dict]],
*,
is_smooth: bool = False,
is_selected: bool = True,
Expand Down
2 changes: 2 additions & 0 deletions pyecharts/charts/basic_charts/pictorialbar.py
Expand Up @@ -37,6 +37,7 @@ def add_yaxis(
markline_opts: types.MarkLine = None,
tooltip_opts: types.Tooltip = None,
itemstyle_opts: types.ItemStyle = None,
encode: types.Union[types.JsCode, dict] = None,
):
self._append_color(color)
self._append_legend(series_name, is_selected)
Expand All @@ -63,6 +64,7 @@ def add_yaxis(
"markLine": markline_opts,
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
"encode": encode,
}
)
return self
4 changes: 3 additions & 1 deletion pyecharts/charts/basic_charts/pie.py
Expand Up @@ -16,7 +16,7 @@ class Pie(Chart):
def add(
self,
series_name: str,
data_pair: types.Sequence,
data_pair: types.Sequence[types.Union[types.Sequence, opts.PieItem, dict]],
*,
color: types.Optional[str] = None,
radius: types.Optional[types.Sequence] = None,
Expand All @@ -33,6 +33,8 @@ def add(
self.options.get("legend")[0].update(
data=[d[0] for d in self.options.get("dataset").get("source")][1:]
)
elif isinstance(data_pair[0], opts.PieItem):
data = data_pair
else:
data = [{"name": n, "value": v} for n, v in data_pair]

Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/radar.py
Expand Up @@ -53,7 +53,7 @@ def add_schema(
def add(
self,
series_name: str,
data: types.Sequence,
data: types.Sequence[types.Union[opts.RadarItem, dict]],
*,
is_selected: bool = True,
symbol: types.Optional[str] = None,
Expand Down
34 changes: 24 additions & 10 deletions pyecharts/charts/basic_charts/scatter.py
Expand Up @@ -16,10 +16,28 @@ class Scatter(RectChart):
visualmap component can be used.
"""

def _parse_data(
self,
y_axis: types.Sequence[types.Union[opts.ScatterItem, dict]]
) -> types.Optional[types.Sequence]:
if self.options.get("dataset") is not None:
return None
elif len(self._xaxis_data) == 0:
return y_axis
elif isinstance(y_axis[0], (opts.ScatterItem, dict)):
return y_axis
elif isinstance(y_axis[0], types.Sequence):
return [
list(itertools.chain(list([x]), y))
for x, y in zip(self._xaxis_data, y_axis)
]
else:
return [list(z) for z in zip(self._xaxis_data, y_axis)]

def add_yaxis(
self,
series_name: str,
y_axis: types.Sequence,
y_axis: types.Sequence[types.Union[opts.ScatterItem, dict]],
*,
is_selected: bool = True,
xaxis_index: types.Optional[types.Numeric] = None,
Expand All @@ -31,21 +49,16 @@ def add_yaxis(
label_opts: types.Label = opts.LabelOpts(position="right"),
markpoint_opts: types.MarkPoint = None,
markline_opts: types.MarkLine = None,
markarea_opts: types.MarkArea = None,
tooltip_opts: types.Tooltip = None,
itemstyle_opts: types.ItemStyle = None,
encode: types.Union[types.JSFunc, dict, None] = None,
):
self._append_color(color)
self._append_legend(series_name, is_selected)
if len(y_axis) > 0 and isinstance(y_axis[0], types.Sequence):
data = [
list(itertools.chain(list([x]), y))
for x, y in zip(self._xaxis_data, y_axis)
]
elif self.options.get("dataset") is not None:
data = None
else:
data = [list(z) for z in zip(self._xaxis_data, y_axis)]

data = self._parse_data(y_axis=y_axis)

self.options.get("series").append(
{
"type": ChartType.SCATTER,
Expand All @@ -59,6 +72,7 @@ def add_yaxis(
"label": label_opts,
"markPoint": markpoint_opts,
"markLine": markline_opts,
"markArea": markarea_opts,
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
"encode": encode,
Expand Down
2 changes: 1 addition & 1 deletion pyecharts/charts/basic_charts/themeriver.py
Expand Up @@ -16,7 +16,7 @@ class ThemeRiver(Chart):
def add(
self,
series_name: types.Sequence,
data: types.Sequence,
data: types.Sequence[types.Union[opts.ThemeRiverItem, dict]],
*,
is_selected: bool = True,
label_opts: types.Label = opts.LabelOpts(),
Expand Down
6 changes: 4 additions & 2 deletions pyecharts/charts/basic_charts/tree.py
Expand Up @@ -38,8 +38,8 @@ def add(
data: types.Sequence[types.Union[opts.TreeItem, dict]],
*,
layout: str = "orthogonal",
symbol: str = "emptyCircle",
symbol_size: types.Numeric = 7,
symbol: types.JSFunc = "emptyCircle",
symbol_size: types.Union[types.JSFunc, types.Numeric, types.Sequence] = 7,
orient: str = "LR",
pos_top: types.Optional[str] = None,
pos_left: types.Optional[str] = None,
Expand All @@ -66,6 +66,8 @@ def add(
"bottom": pos_bottom,
"symbol": symbol,
"symbolSize": symbol_size,
"edgeShape": "",
"edgeForkPosition": "",
"roam": is_roam,
"expandAndCollapse": is_expand_and_collapse,
"initialTreeDepth": initial_tree_depth,
Expand Down
3 changes: 3 additions & 0 deletions pyecharts/charts/chart.py
Expand Up @@ -194,6 +194,9 @@ def overlap(self, chart: Base):
self.options.get("legend")[0].get("data").extend(
chart.options.get("legend")[0].get("data")
)
self.options.get("legend")[0].get("selected").update(
chart.options.get("legend")[0].get("selected")
)
self.options.get("series").extend(chart.options.get("series"))
return self

Expand Down

0 comments on commit d7f9fb8

Please sign in to comment.