Update: set_series_opts 新增 kwargs,允许传入任意变量 (#1090)

* Update: set_series_opts 新增 kwargs,允许传入任意变量

* Update: 统一测试 eq_ 方式

* Docs: update
This commit is contained in:
陈键冬 2019-05-08 10:44:59 +08:00 committed by GitHub
parent f3e070cabf
commit 3172dff53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 158 additions and 86 deletions

View File

@ -10,7 +10,7 @@
<img src="https://travis-ci.org/pyecharts/pyecharts.svg?branch=master" alt="Travis Build Status">
</a>
<a href="https://ci.appveyor.com/project/chenjiandongx/pyecharts">
<img src="https://ci.appveyor.com/api/projects/status/81cbsfjpfryv1cl8?svg=true" alt="Appveyor Build Status">
<img src="https://ci.appveyor.com/api/projects/status/81cbsfjpfryv1cl8/branch/master?svg=true" alt="Appveyor Build Status">
</a>
<a href="https://codecov.io/gh/pyecharts/pyecharts">
<img src="https://codecov.io/gh/pyecharts/pyecharts/branch/master/graph/badge.svg" alt="Codecov">

View File

@ -7,10 +7,10 @@
</p>
<p align="center">
<a href="https://travis-ci.org/pyecharts/pyecharts">
<img src="https://travis-ci.org/pyecharts/pyecharts.svg?branch=2019" alt="Travis Build Status">
<img src="https://travis-ci.org/pyecharts/pyecharts.svg?branch=master" alt="Travis Build Status">
</a>
<a href="https://ci.appveyor.com/project/chenjiandongx/pyecharts">
<img src="https://ci.appveyor.com/api/projects/status/81cbsfjpfryv1cl8?svg=true" alt="Appveyor Build Status">
<img src="https://ci.appveyor.com/api/projects/status/81cbsfjpfryv1cl8/branch/master?svg=true" alt="Appveyor Build Status">
</a>
<a href="https://codecov.io/gh/pyecharts/pyecharts">
<img src="https://codecov.io/gh/pyecharts/pyecharts/branch/master/graph/badge.svg" alt="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)
<div align="center">
<img src="https://user-images.githubusercontent.com/19553554/52197440-843a5200-289a-11e9-8601-3ce8d945b04a.gif" width="33%" alt="bar"/>

View File

@ -41,6 +41,7 @@ class Chart(Base):
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 @@ class Chart(Base):
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):

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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 @@ from pyecharts.charts import Polar
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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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 test_surface3d_base():
)
)
)
assert c.theme == "white"
assert c.renderer == "canvas"
c.render("render.html")
eq_(c.theme, "white")
eq_(c.renderer, "canvas")
c.render()

View File

@ -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()

View File

@ -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()

View File

@ -1,3 +1,5 @@
from nose.tools import eq_
from pyecharts.charts import WordCloud
words = [
@ -14,6 +16,6 @@ words = [
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()