Skip to content

Commit

Permalink
Update: set_series_opts 新增 kwargs,允许传入任意变量 (pyecharts#1090)
Browse files Browse the repository at this point in the history
* Update: set_series_opts 新增 kwargs,允许传入任意变量

* Update: 统一测试 eq_ 方式

* Docs: update
  • Loading branch information
chenjiandongx authored May 8, 2019
1 parent f3e070c commit 3172dff
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 86 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -52,15 +52,15 @@

## ⏳ 版本

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

> 支持 Python2.7,3.4+
经开发团队决定,0.5.x 版本将不再进行维护,0.5.x 版本代码位于 *05x* 分支,文档位于 [05x-docs.pyecharts.org](http://05x-docs.pyecharts.org)

### V1.0.X
### V1

> 仅支持 Python3.6+
Expand Down Expand Up @@ -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"/>
Expand Down
5 changes: 5 additions & 0 deletions pyecharts/charts/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
23 changes: 20 additions & 3 deletions test/test_bar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from unittest.mock import patch

from nose.tools import assert_in, assert_not_in, eq_
Expand All @@ -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 = (
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions test/test_bar3d.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_boxplot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nose.tools import eq_

from pyecharts.charts import Boxplot


Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_calendar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import random

from nose.tools import eq_

from pyecharts import options as opts
from pyecharts.charts import Calendar

Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_effectscatter.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 5 additions & 3 deletions test/test_funnel.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 5 additions & 3 deletions test/test_gauge.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 5 additions & 3 deletions test/test_geo.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nose.tools import eq_

from pyecharts.charts import Graph


Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_heatmap.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_kline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nose.tools import eq_

from pyecharts import options as opts
from pyecharts.charts import Kline

Expand Down Expand Up @@ -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()
8 changes: 5 additions & 3 deletions test/test_line.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nose.tools import eq_

from pyecharts.charts import Line


Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_line3d.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
8 changes: 5 additions & 3 deletions test/test_liquid.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 5 additions & 3 deletions test/test_map.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nose.tools import eq_

from example.commons import Faker
from pyecharts.charts import Map

Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_parallel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from nose.tools import eq_

from pyecharts.charts import Parallel


Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_pie.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
8 changes: 5 additions & 3 deletions test/test_polar.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import random

from nose.tools import eq_

from pyecharts import options as opts
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()
Loading

0 comments on commit 3172dff

Please sign in to comment.