Skip to content

Commit

Permalink
Merge pull request pyecharts#1469 from pyecharts/dev
Browse files Browse the repository at this point in the history
Prepare For Version 1.6.1
  • Loading branch information
sunhailin-Leo authored Jan 3, 2020
2 parents 42717ac + c6066e5 commit a251268
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ notifications:
on_success: always # default: change
on_failure: always # default: always
python:
- "3.7-dev"
- "3.8-dev"
- "3.8"
- "3.7"
- "3.6"
before_install:
- pip install -r test/requirements.txt
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ environment:
PYTHON_VERSION: "3.6"
- PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7"
- PYTHON: "C:\\Python38-x64"
PYTHON_VERSION: "3.8"

install:
- "%PYTHON%\\python.exe -m pip install -r requirements.txt"
Expand Down
40 changes: 40 additions & 0 deletions example/graph_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import os

from pyecharts.commons.utils import JsCode

from pyecharts import options as opts
from pyecharts.charts import Graph, Page
from pyecharts.faker import Collector
Expand Down Expand Up @@ -56,6 +58,44 @@ def graph_with_opts() -> Graph:
return c


@C.funcs
def graph_with_edge_opts() -> Graph:
nodes_data = [
opts.GraphNode(name="结点1", symbol_size=10),
opts.GraphNode(name="结点2", symbol_size=20),
opts.GraphNode(name="结点3", symbol_size=30),
opts.GraphNode(name="结点4", symbol_size=40),
opts.GraphNode(name="结点5", symbol_size=50),
opts.GraphNode(name="结点6", symbol_size=60),
]
links_data = [
opts.GraphLink(source="结点1", target="结点2", value=2),
opts.GraphLink(source="结点2", target="结点3", value=3),
opts.GraphLink(source="结点3", target="结点4", value=4),
opts.GraphLink(source="结点4", target="结点5", value=5),
opts.GraphLink(source="结点5", target="结点6", value=6),
opts.GraphLink(source="结点6", target="结点1", value=7),
]
c = (
Graph()
.add(
"",
nodes_data,
links_data,
repulsion=4000,
edge_label=opts.LabelOpts(
is_show=True,
position="middle",
formatter="{b} 的数据 {c}",
),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="Graph-GraphNode-GraphLink-WithEdgeLabel")
)
)
return c


@C.funcs
def graph_weibo() -> Graph:
with open(os.path.join("fixtures", "weibo.json"), "r", encoding="utf-8") as f:
Expand Down
20 changes: 20 additions & 0 deletions example/heatmap_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@ def heatmap_base() -> HeatMap:
return c


@C.funcs
def heatmap_with_label_show() -> HeatMap:
value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]
c = (
HeatMap()
.add_xaxis(Faker.clock)
.add_yaxis(
"series0",
Faker.week,
value,
label_opts=opts.LabelOpts(is_show=True, position="inside"),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="HeatMap-Label 显示"),
visualmap_opts=opts.VisualMapOpts(),
)
)
return c


Page().add(*[fn() for fn, _ in C.charts]).render()
89 changes: 87 additions & 2 deletions example/timeline_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pyecharts.commons.utils import JsCode

from pyecharts import options as opts
from pyecharts.charts import Bar, Map, Page, Pie, Timeline
from pyecharts.charts import Bar, Map, Page, Pie, Sankey, Timeline
from pyecharts.faker import Collector, Faker

C = Collector()
Expand All @@ -21,6 +23,60 @@ def timeline_bar() -> Timeline:
return tl


@C.funcs
def timeline_bar_with_graphic() -> Timeline:
x = Faker.choose()
tl = Timeline()
for i in range(2015, 2020):
bar = (
Bar()
.add_xaxis(x)
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts("某商店{}年营业额 - With Graphic 组件".format(i)),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(
rotation=JsCode("Math.PI / 4"),
bounding="raw",
right=100,
bottom=110,
z=100,
),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="center", top="center", z=100
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=400, height=50
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="rgba(0,0,0,0.3)"
),
),
opts.GraphicText(
graphic_item=opts.GraphicItem(
left="center", top="center", z=100
),
graphic_textstyle_opts=opts.GraphicTextStyleOpts(
text="某商店{}年营业额".format(i),
font="bold 26px Microsoft YaHei",
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="#fff"
),
),
),
],
)
],
)
)
tl.add(bar, "{}年".format(i))
return tl


@C.funcs
def timeline_pie() -> Timeline:
attr = Faker.choose()
Expand Down Expand Up @@ -59,7 +115,7 @@ def timeline_map() -> Timeline:


@C.funcs
def timeline_with_multi_axis():
def timeline_with_multi_axis() -> Timeline:
tl = Timeline()
for i in range(2015, 2020):
bar = (
Expand All @@ -73,4 +129,33 @@ def timeline_with_multi_axis():
return tl


@C.funcs
def timeline_sankey() -> Timeline:
tl = Timeline()
names = ("商家A", "商家B", "商家C")
nodes = [{"name": name} for name in names]
for i in range(2015, 2020):
links = [
{"source": names[0], "target": names[1], "value": Faker.values()[0]},
{"source": names[1], "target": names[2], "value": Faker.values()[0]},
]
sankey = (
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(
opacity=0.2, curve=0.5, color="source"
),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="{}年商店(A, B, C)营业额差".format(i))
)
)
tl.add(sankey, "{}年".format(i))
return tl


Page().add(*[fn() for fn, _ in C.charts]).render()
2 changes: 1 addition & 1 deletion pyecharts/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.6.0"
__version__ = "1.6.1"
__author__ = "chenjiandongx"
5 changes: 5 additions & 0 deletions pyecharts/charts/basic_charts/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def add(
edge_length: types.Numeric = 50,
gravity: types.Numeric = 0.2,
repulsion: types.Numeric = 50,
edge_label: types.Label = None,
edge_symbol: types.Optional[str] = None,
edge_symbol_size: types.Numeric = 10,
label_opts: types.Label = opts.LabelOpts(),
Expand All @@ -54,6 +55,9 @@ def add(
c = c.opts
self._append_legend(c.get("name", ""), is_selected)

if edge_label is None:
edge_label = opts.LabelOpts(is_show=False)

if edge_symbol is None:
edge_symbol = [None, None]

Expand All @@ -77,6 +81,7 @@ def add(
"focusNodeAdjacency": is_focusnode,
"data": _nodes,
"categories": categories,
"edgeLabel": edge_label,
"edgeSymbol": edge_symbol,
"edgeSymbolSize": edge_symbol_size,
"links": _links,
Expand Down
4 changes: 4 additions & 0 deletions pyecharts/charts/basic_charts/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def add_yaxis(
is_smooth: bool = False,
is_step: bool = False,
is_hover_animation: bool = True,
z_level: types.Numeric = 0,
z: types.Numeric = 0,
markpoint_opts: types.MarkPoint = None,
markline_opts: types.MarkLine = None,
tooltip_opts: types.Tooltip = None,
Expand Down Expand Up @@ -65,6 +67,8 @@ def add_yaxis(
"markLine": markline_opts,
"tooltip": tooltip_opts,
"itemStyle": itemstyle_opts,
"zlevel": z_level,
"z": z,
}
)
return self
4 changes: 2 additions & 2 deletions pyecharts/charts/composite_charts/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ def add(self, chart: Base, time_point: str):
self.js_dependencies.add(dep)
self._time_points.append(time_point)

series_data = [{"data": s.get("data")} for s in chart.options.get("series")]
self.options.get("baseOption").get("timeline").update(data=self._time_points)
self.options.get("options").append(
{
"legend": chart.options.get("legend"),
"series": series_data,
"series": chart.options.get("series"),
"xAxis": chart.options.get("xAxis"),
"title": chart.options.get("title"),
"tooltip": chart.options.get("tooltip"),
"visualMap": chart.options.get("visualMap"),
"color": chart.options.get("color"),
"graphic": chart.options.get("graphic")
}
)
self.__check_components(chart)
Expand Down
4 changes: 4 additions & 0 deletions pyecharts/options/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def __init__(
pos_right: Optional[str] = None,
pos_top: Optional[str] = None,
pos_bottom: Optional[str] = None,
padding: Union[Sequence, Numeric] = 5,
item_gap: Numeric = 10,
title_textstyle_opts: Union[TextStyleOpts, dict, None] = None,
subtitle_textstyle_opts: Union[TextStyleOpts, dict, None] = None,
):
Expand All @@ -192,6 +194,8 @@ def __init__(
"right": pos_right,
"top": pos_top,
"bottom": pos_bottom,
"padding": padding,
"itemGap": item_gap,
"textStyle": title_textstyle_opts,
"subtextStyle": subtitle_textstyle_opts,
}
Expand Down
8 changes: 7 additions & 1 deletion pyecharts/render/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def make_snapshot(
logger.info("Generating file ...")
file_type = output_name.split(".")[-1]

content = engine.make_snapshot(file_name, file_type, delay, pixel_ratio, **kwargs)
content = engine.make_snapshot(
html_path=file_name,
file_type=file_type,
delay=delay,
pixel_ratio=pixel_ratio,
**kwargs,
)
if file_type in [SVG_FORMAT, B64_FORMAT]:
save_as_text(content, output_name)
else:
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
__extra_requires__ = {
"selenium": ["snapshot-selenium"],
"phantomjs": ["snapshot-phantomjs"],
"pyppeteer": ["snapshot-pyppeteer"],
"images": ["PIL"],
}

Expand Down Expand Up @@ -90,6 +91,7 @@ def run(self):
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Libraries",
],
cmdclass={"upload": UploadCommand},
Expand Down
20 changes: 20 additions & 0 deletions test/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def test_graph_draggable_and_symbol_size(fake_writer):
assert_in("symbolSize", content)


@patch("pyecharts.render.engine.write_utf8_html_file")
def test_graph_edge_label_opts(fake_writer):
nodes = [
{"name": "结点1", "symbolSize": 10},
{"name": "结点2", "symbolSize": 20},
{"name": "结点3", "symbolSize": 30},
{"name": "结点4", "symbolSize": 40},
]
links = []
for i in nodes:
for j in nodes:
links.append({"source": i.get("name"), "target": j.get("name")})
c = Graph().add(
"", nodes, links, repulsion=4000, edge_label=opts.LabelOpts(is_show=True)
)
c.render()
_, content = fake_writer.call_args[0]
assert_in("edgeLabel", content)


def test_graph_item():
node_name, link_source = "test_node_name", "test_link_source"
node = opts.GraphNode(name=node_name)
Expand Down
14 changes: 14 additions & 0 deletions test/test_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ def test_data_label_none_animation_opts(fake_writer):
c.render()
_, content = fake_writer.call_args[0]
assert_in("hoverAnimation", content)


@patch("pyecharts.render.engine.write_utf8_html_file")
def test_line_opts_with_zlevel_z(fake_writer):
c = (
Line()
.add_xaxis(["A", "B", "C"])
.add_yaxis("series0", [1, 2, 4])
.add_yaxis("series1", [2, 3, 6], z_level=2, z=1)
)
c.render()
_, content = fake_writer.call_args[0]
assert_in("zlevel", content)
assert_in("z", content)

0 comments on commit a251268

Please sign in to comment.