From 3172dff53a3bb83827a08c2f5b3f7ddfa0a1d2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=94=AE=E5=86=AC?= Date: Wed, 8 May 2019 10:44:59 +0800 Subject: [PATCH] =?UTF-8?q?Update:=20set=5Fseries=5Fopts=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20kwargs=EF=BC=8C=E5=85=81=E8=AE=B8=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E4=BB=BB=E6=84=8F=E5=8F=98=E9=87=8F=20(#1090)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update: set_series_opts 新增 kwargs,允许传入任意变量 * Update: 统一测试 eq_ 方式 * Docs: update --- README.en.md | 2 +- README.md | 10 +++++----- pyecharts/charts/chart.py | 5 +++++ test/test_bar.py | 23 ++++++++++++++++++++--- test/test_bar3d.py | 8 +++++--- test/test_boxplot.py | 8 +++++--- test/test_calendar.py | 8 +++++--- test/test_effectscatter.py | 8 +++++--- test/test_funnel.py | 8 +++++--- test/test_gauge.py | 8 +++++--- test/test_geo.py | 8 +++++--- test/test_graph.py | 8 +++++--- test/test_heatmap.py | 8 +++++--- test/test_kline.py | 8 +++++--- test/test_line.py | 8 +++++--- test/test_line3d.py | 8 +++++--- test/test_liquid.py | 8 +++++--- test/test_map.py | 8 +++++--- test/test_parallel.py | 8 +++++--- test/test_pie.py | 8 +++++--- test/test_polar.py | 8 +++++--- test/test_radar.py | 12 +++++++----- test/test_sankey.py | 8 +++++--- test/test_scatter.py | 8 +++++--- test/test_scatter3d.py | 8 +++++--- test/test_surface3d.py | 8 +++++--- test/test_tree.py | 8 +++++--- test/test_treemap.py | 8 +++++--- test/test_wordcloud.py | 8 +++++--- 29 files changed, 158 insertions(+), 86 deletions(-) diff --git a/README.en.md b/README.en.md index c8d61ee81..3148bc97e 100644 --- a/README.en.md +++ b/README.en.md @@ -10,7 +10,7 @@ Travis Build Status - Appveyor Build Status + Appveyor Build Status Codecov diff --git a/README.md b/README.md index d4e85bf62..1cccc96be 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@

- Travis Build Status + Travis Build Status - Appveyor Build Status + Appveyor Build Status Codecov @@ -52,7 +52,7 @@ ## ⏳ 版本 -v0.5.X 和 V1.0.X 间完全不兼容,V1.0.X 是一个全新的版本,详见 [ISSUE#892](https://github.com/pyecharts/pyecharts/issues/892) +v0.5.X 和 V1 间不兼容,V1 是一个全新的版本,详见 [ISSUE#892](https://github.com/pyecharts/pyecharts/issues/892) ### V0.5.X @@ -60,7 +60,7 @@ v0.5.X 和 V1.0.X 间完全不兼容,V1.0.X 是一个全新的版本,详见 经开发团队决定,0.5.x 版本将不再进行维护,0.5.x 版本代码位于 *05x* 分支,文档位于 [05x-docs.pyecharts.org](http://05x-docs.pyecharts.org)。 -### V1.0.X +### V1 > 仅支持 Python3.6+ @@ -151,7 +151,7 @@ make_snapshot(driver, bar_chart().render(), "bar.png") ## 🔖 Demo -> Demo 代码位于 example 文件夹下。 +> Demo 代码位于 example 文件夹下,欢迎参考 pyecharts 画廊 [pyecharts-gallery](https://github.com/pyecharts/pyecharts-gallery)。

bar diff --git a/pyecharts/charts/chart.py b/pyecharts/charts/chart.py index 87b9d6520..b86f5bb16 100644 --- a/pyecharts/charts/chart.py +++ b/pyecharts/charts/chart.py @@ -41,6 +41,7 @@ def set_series_opts( effect_opts: Union[opts.EffectOpts, dict] = opts.EffectOpts(), tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, + **kwargs, ): _series = self.options.get("series") if label_opts: @@ -87,6 +88,10 @@ def set_series_opts( for s in _series: s.update(itemStyle=itemstyle_opts) + if len(kwargs) > 0: + for s in _series: + s.update(kwargs) + return self def _append_legend(self, name, is_selected): diff --git a/test/test_bar.py b/test/test_bar.py index 2e23526c2..0b0323b12 100644 --- a/test/test_bar.py +++ b/test/test_bar.py @@ -1,3 +1,4 @@ +import re from unittest.mock import patch from nose.tools import assert_in, assert_not_in, eq_ @@ -15,20 +16,36 @@ def test_bar_base(): ) eq_(c.theme, "white") eq_(c.renderer, "canvas") - c.render("render.html") + c.render() @patch("pyecharts.render.engine.write_utf8_html_file") def test_bar_colors(fake_writer): c = Bar().add_xaxis(["A", "B", "C"]).add_yaxis("series0", [1, 2, 4]) c.set_colors(["#AABBCC", "#BBCCDD", "#CCDDEE"] + c.colors) - c.render("render.html") + c.render() _, content = fake_writer.call_args[0] assert_in("#AABBCC", content) assert_in("#BBCCDD", content) assert_in("#CCDDEE", content) +@patch("pyecharts.render.engine.write_utf8_html_file") +def test_bar_series_stack(fake_writer): + c = ( + Bar() + .add_xaxis(["A", "B", "C"]) + .add_yaxis("series0", [1, 2, 4]) + .add_yaxis("series1", [2, 3, 6]) + .add_yaxis("series2", [5, 8, 7]) + .set_series_opts(stack="MY_STACK_NAME") + ) + c.render() + _, content = fake_writer.call_args[0] + stack_cnt = re.findall("MY_STACK_NAME", content) + eq_(3, len(stack_cnt)) + + @patch("pyecharts.render.engine.write_utf8_html_file") def test_bar_title_options(fake_writer): c = ( @@ -41,7 +58,7 @@ def test_bar_title_options(fake_writer): ) ) ) - c.render("render.html") + c.render() file_name, content = fake_writer.call_args[0] eq_("render.html", file_name) assert_in("This is title.", content) diff --git a/test/test_bar3d.py b/test/test_bar3d.py index 48b9f45ad..c1cd1c8f4 100644 --- a/test/test_bar3d.py +++ b/test/test_bar3d.py @@ -1,5 +1,7 @@ import random +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import Bar3D @@ -18,6 +20,6 @@ def test_bar3d_base(): ) .set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=20)) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_boxplot.py b/test/test_boxplot.py index 7f5a352b2..473c2d2c2 100644 --- a/test/test_boxplot.py +++ b/test/test_boxplot.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import Boxplot @@ -14,6 +16,6 @@ def test_boxpolt_base(): c.add_xaxis(["expr1", "expr2"]).add_yaxis("A", c.prepare_data(v1)).add_yaxis( "B", c.prepare_data(v2) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_calendar.py b/test/test_calendar.py index fc8e7dadf..785d6039c 100644 --- a/test/test_calendar.py +++ b/test/test_calendar.py @@ -1,6 +1,8 @@ import datetime import random +from nose.tools import eq_ + from pyecharts import options as opts from pyecharts.charts import Calendar @@ -27,6 +29,6 @@ def test_calendar_base(): ) ) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_effectscatter.py b/test/test_effectscatter.py index c38b4d779..c9f3119cb 100644 --- a/test/test_effectscatter.py +++ b/test/test_effectscatter.py @@ -1,9 +1,11 @@ +from nose.tools import eq_ + from example.commons import Faker from pyecharts.charts import EffectScatter def test_effectscatter_base(): c = EffectScatter().add_xaxis(Faker.choose()).add_yaxis("", Faker.values()) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_funnel.py b/test/test_funnel.py index b4575ba86..8bf73e5de 100644 --- a/test/test_funnel.py +++ b/test/test_funnel.py @@ -1,9 +1,11 @@ +from nose.tools import eq_ + from example.commons import Faker from pyecharts.charts import Funnel def test_funnel_base(): c = Funnel().add("商品", [list(z) for z in zip(Faker.choose(), Faker.values())]) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_gauge.py b/test/test_gauge.py index 02ac847eb..ae224bc6d 100644 --- a/test/test_gauge.py +++ b/test/test_gauge.py @@ -1,8 +1,10 @@ +from nose.tools import eq_ + from pyecharts.charts import Gauge def test_gauge_base(): c = Gauge().add("", [("完成率", 66.6)]) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_geo.py b/test/test_geo.py index 01b2d85e7..dce0d4c65 100644 --- a/test/test_geo.py +++ b/test/test_geo.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import Geo @@ -11,6 +13,6 @@ def test_geo_base(): .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(visualmap_opts=opts.VisualMapOpts()) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_graph.py b/test/test_graph.py index 0aa2cfde4..b5b8170fa 100644 --- a/test/test_graph.py +++ b/test/test_graph.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import Graph @@ -13,6 +15,6 @@ def test_graph_base(): for j in nodes: links.append({"source": i.get("name"), "target": j.get("name")}) c = Graph().add("", nodes, links, repulsion=8000) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_heatmap.py b/test/test_heatmap.py index 4eba0b348..dec373b83 100644 --- a/test/test_heatmap.py +++ b/test/test_heatmap.py @@ -1,5 +1,7 @@ import random +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import HeatMap @@ -13,6 +15,6 @@ def test_heatmap_base(): .add_yaxis("series0", Faker.week, value) .set_global_opts(visualmap_opts=opts.VisualMapOpts()) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_kline.py b/test/test_kline.py index 62f939739..86ee2558b 100644 --- a/test/test_kline.py +++ b/test/test_kline.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts import options as opts from pyecharts.charts import Kline @@ -25,6 +27,6 @@ def test_kline_base(): xaxis_opts=opts.AxisOpts(is_scale=True), ) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_line.py b/test/test_line.py index 50a3da71c..2311c01ab 100644 --- a/test/test_line.py +++ b/test/test_line.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import Line @@ -8,6 +10,6 @@ def test_bar_base(): .add_yaxis("series0", [1, 2, 4]) .add_yaxis("series1", [2, 3, 6]) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_line3d.py b/test/test_line3d.py index 9357814c4..0e77ec12c 100644 --- a/test/test_line3d.py +++ b/test/test_line3d.py @@ -1,5 +1,7 @@ import math +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import Line3D @@ -28,6 +30,6 @@ def test_line3d_base(): ) ) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_liquid.py b/test/test_liquid.py index 184d43ecc..958128916 100644 --- a/test/test_liquid.py +++ b/test/test_liquid.py @@ -1,8 +1,10 @@ +from nose.tools import eq_ + from pyecharts.charts import Liquid def test_liquid_base(): c = Liquid().add("lq", [0.6, 0.7]) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_map.py b/test/test_map.py index 038f2b034..32de7a111 100644 --- a/test/test_map.py +++ b/test/test_map.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from example.commons import Faker from pyecharts.charts import Map @@ -6,6 +8,6 @@ def test_map_base(): c = Map().add( "商家A", [list(z) for z in zip(Faker.provinces, Faker.values())], "china" ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_parallel.py b/test/test_parallel.py index f3b4b4377..680641354 100644 --- a/test/test_parallel.py +++ b/test/test_parallel.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import Parallel @@ -24,6 +26,6 @@ def test_parallel_base(): ) .add("parallel", data) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_pie.py b/test/test_pie.py index c2594ebec..11e2f8d27 100644 --- a/test/test_pie.py +++ b/test/test_pie.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import Pie @@ -9,6 +11,6 @@ def test_pie_base(): .add("", [list(z) for z in zip(Faker.choose(), Faker.values())]) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_polar.py b/test/test_polar.py index f97a345b2..3e24691e1 100644 --- a/test/test_polar.py +++ b/test/test_polar.py @@ -1,5 +1,7 @@ import random +from nose.tools import eq_ + from pyecharts import options as opts from pyecharts.charts import Polar @@ -7,6 +9,6 @@ def test_polar_scatter(): data = [(i, random.randint(1, 100)) for i in range(101)] c = Polar().add("", data, type_="scatter", label_opts=opts.LabelOpts(is_show=False)) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_radar.py b/test/test_radar.py index dd5f9f4bb..34dd7602d 100644 --- a/test/test_radar.py +++ b/test/test_radar.py @@ -1,8 +1,10 @@ +from nose.tools import eq_ + from pyecharts import options as opts from pyecharts.charts import Radar -v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] -v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] +v1 = [(4300, 10000, 28000, 35000, 50000, 19000)] +v2 = [(5000, 14000, 28000, 31000, 42000, 21000)] def test_radar_base(): @@ -22,6 +24,6 @@ def test_radar_base(): .add("实际开销", v2) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_sankey.py b/test/test_sankey.py index b2dced400..26bdcb7df 100644 --- a/test/test_sankey.py +++ b/test/test_sankey.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts import options as opts from pyecharts.charts import Sankey @@ -16,6 +18,6 @@ def test_sankey_base(): linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"), label_opts=opts.LabelOpts(position="right"), ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_scatter.py b/test/test_scatter.py index 3cc72f90d..1e02a6bcc 100644 --- a/test/test_scatter.py +++ b/test/test_scatter.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import Scatter @@ -8,6 +10,6 @@ def test_bar_base(): .add_yaxis("series0", [1, 2, 4]) .add_yaxis("series1", [2, 3, 6]) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_scatter3d.py b/test/test_scatter3d.py index 0661c06fc..a8581ea0c 100644 --- a/test/test_scatter3d.py +++ b/test/test_scatter3d.py @@ -1,5 +1,7 @@ import random +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import Scatter3D @@ -17,6 +19,6 @@ def test_scatter3d_base(): visualmap_opts=opts.VisualMapOpts(range_color=Faker.visual_color) ) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_surface3d.py b/test/test_surface3d.py index ff58fa1d4..8a2412de7 100644 --- a/test/test_surface3d.py +++ b/test/test_surface3d.py @@ -1,5 +1,7 @@ import math +from nose.tools import eq_ + from example.commons import Faker from pyecharts import options as opts from pyecharts.charts import Surface3D @@ -32,6 +34,6 @@ def surface3d_data(): ) ) ) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_tree.py b/test/test_tree.py index e283dcbcf..e770453dc 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import Tree @@ -25,6 +27,6 @@ def test_tree_base(): } ] c = Tree().add("", data) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_treemap.py b/test/test_treemap.py index b4a9e3bdf..bb753a42a 100644 --- a/test/test_treemap.py +++ b/test/test_treemap.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import TreeMap @@ -23,6 +25,6 @@ def test_treemap_base(): ] c = TreeMap().add("演示数据", data) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render() diff --git a/test/test_wordcloud.py b/test/test_wordcloud.py index 80c79b45e..e27be158a 100644 --- a/test/test_wordcloud.py +++ b/test/test_wordcloud.py @@ -1,3 +1,5 @@ +from nose.tools import eq_ + from pyecharts.charts import WordCloud words = [ @@ -14,6 +16,6 @@ def test_wordcloud_base(): c = WordCloud().add("", words, word_size_range=[20, 100]) - assert c.theme == "white" - assert c.renderer == "canvas" - c.render("render.html") + eq_(c.theme, "white") + eq_(c.renderer, "canvas") + c.render()