Update: update example

This commit is contained in:
chenjiandongx 2019-03-25 18:46:39 +08:00
parent 4df3b96ac3
commit 2831d63d4c
26 changed files with 51 additions and 456 deletions

View File

@ -1,4 +1,7 @@
# coding=utf-8
import json
import os
from example.commons import Collector
from pyecharts import options as opts
from pyecharts.charts import Graph, Page
@ -54,4 +57,28 @@ def graph_with_opts() -> Graph:
return c
@C.funcs
def graph_weibo() -> Graph:
with open(os.path.join("fixtures", "weibo.json"), "r", encoding="utf-8") as f:
j = json.load(f)
nodes, links, categories, cont, mid, userl = j
c = (
Graph()
.add(
"",
nodes,
links,
categories,
repulsion=50,
linestyle_opts=opts.LineStyleOpts(curve=0.2),
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
legend_opts=opts.LegendOpts(is_show=False),
title_opts=opts.TitleOpts(title="Graph-微博转发关系图"),
)
)
return c
Page().add(*[fn() for fn, _ in C.charts]).render()

View File

@ -1,4 +1,7 @@
# coding=utf-8
import json
import os
from example.commons import Collector
from pyecharts import options as opts
from pyecharts.charts import Page, Sankey
@ -38,4 +41,22 @@ def sankey_base() -> Sankey:
return c
@C.funcs
def sankey_offical() -> Sankey:
with open(os.path.join("fixtures", "energy.json"), "r", encoding="utf-8") as f:
j = json.load(f)
c = (
Sankey()
.add(
"sankey",
nodes=j["nodes"],
links=j["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="Sankey-官方示例"))
)
return c
Page().add(*[fn() for fn, _ in C.charts]).render()

View File

@ -1,4 +1,3 @@
# coding=utf-8
# flake8: noqa
from pyecharts._version import __author__, __version__

View File

@ -21,6 +21,7 @@ class Graph(Chart):
nodes: List[Union[opts.GraphNode, dict]],
links: List[Union[opts.GraphLink, dict]],
categories: Union[List[Union[opts.GraphCategory, dict]], None] = None,
*,
is_focusnode: bool = True,
is_roam: bool = True,
is_rotate_label: bool = False,

View File

View File

@ -1,6 +1,6 @@
# coding=utf-8
from ..commons.types import List, Numeric, Optional, Sequence, Union
from ..globals import *
from ..globals import RenderType
from ..options.series_options import (
LabelOpts,
LineStyleOpts,

View File

@ -51,7 +51,7 @@ class LineStyleOpts:
self.opts: dict = {
"width": width,
"opacity": opacity,
"curve": curve,
"curveness": curve,
"type": type_,
"color": color,
}

View File

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding=utf-8
from __future__ import unicode_literals

View File

@ -5,61 +5,6 @@ from __future__ import unicode_literals
from pyecharts import EffectScatter
def test_effectscatter_default():
v1 = [10, 20, 30, 40, 50, 60]
v2 = [25, 20, 15, 10, 60, 33]
es = EffectScatter("动态散点图示例")
es.add("effectScatter", v1, v2)
es.render()
def test_effectscatter_multiple_symbol_type():
es = EffectScatter("动态散点图各种图形示例")
es.add(
"", [10], [10], symbol_size=20, effect_scale=3.5, effect_period=3, symbol="pin"
)
es.add(
"", [20], [20], symbol_size=12, effect_scale=4.5, effect_period=4, symbol="rect"
)
es.add(
"",
[30],
[30],
symbol_size=30,
effect_scale=5.5,
effect_period=5,
symbol="roundRect",
)
es.add(
"",
[40],
[40],
symbol_size=10,
effect_scale=6.5,
effect_brushtype="fill",
symbol="diamond",
)
es.add(
"",
[50],
[50],
symbol_size=16,
effect_scale=5.5,
effect_period=3,
symbol="arrow",
)
es.add(
"",
[60],
[60],
symbol_size=6,
effect_scale=2.5,
effect_period=3,
symbol="triangle",
)
es.render()
def test_effectscatter_splitline():
es = EffectScatter("动态散点图各种图形示例")
es.add("", [10], [10])

View File

@ -9,19 +9,6 @@ from pyecharts import Funnel
prices = [20, 40, 60, 80, 100, 120]
def test_funnel_labelpos_inside():
funnel = Funnel("漏斗图示例")
funnel.add(
"商品",
CLOTHES,
prices,
is_label_show=True,
label_pos="inside",
label_text_color="#fff",
)
funnel.render()
def test_funnel_other_style():
funnel = Funnel("漏斗图示例", title_pos="center")
funnel.add(

View File

@ -262,60 +262,6 @@ def test_geo_with_noexist_city():
geo.render()
def test_geo_guangdong_province():
data = [("汕头市", 50), ("汕尾市", 60), ("揭阳市", 35), ("阳江市", 44), ("肇庆市", 72)]
geo = Geo("广东城市空气质量", "data from pm2.5", **style.init_style)
attr, value = geo.cast(data)
geo.add(
"",
attr,
value,
maptype="广东",
type="effectScatter",
is_random=True,
effect_scale=5,
is_legend_show=False,
)
geo.render()
def test_geo_shantou_city():
data = [("澄海区", 30), ("南澳县", 40), ("龙湖区", 50), ("金平区", 60)]
geo = Geo("汕头市地图示例", **style.init_style)
attr, value = geo.cast(data)
geo.add(
"",
attr,
value,
maptype="汕头",
is_visualmap=True,
tooltip_formatter="{b}",
is_legend_show=False,
label_emphasis_textsize=15,
label_emphasis_pos="right",
)
geo.render()
def test_geo_user_define_coords():
coords = {
"0": [0.572430556, 19.246],
"1": [0.479039352, 1.863],
"2": (0.754143519, -20.579),
}
geo = Geo(**style.init_style)
geo.add(
"",
["0", "1", "2"],
[6, 5.8, 6.2],
is_visualmap=True,
geo_cities_coords=coords,
maptype="world",
)
geo.render()
def test_geo_visualmap_pieces():
data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)]
geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
@ -338,46 +284,3 @@ def test_geo_visualmap_pieces():
content = geo._repr_html_()
assert '"max": 13' in content
assert '"label": "14 < x < 16"' in content
def test_full_example():
data = [("广州", 45), ("漳州", 35), ("A市", 43)]
geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
coordinate = geo.get_coordinate("广州")
assert 2 == len(coordinate)
with assert_raises(ValueError):
geo.get_coordinate("A市", raise_exception=True)
attr, value = geo.cast(data)
with assert_raises(ValueError):
geo.add(
"",
attr,
value,
type="effectScatter",
is_random=True,
is_visualmap=True,
is_piecewise=True,
visual_text_color="#fff",
pieces=[
{"min": 0, "max": 13, "label": "0 < x < 13"},
{"min": 14, "max": 16, "label": "14 < x < 16"},
],
effect_scale=5,
)
geo.add_coordinate("A市", 119.3, 26.08)
geo.add(
"",
attr,
value,
type="effectScatter",
is_random=True,
is_visualmap=True,
is_piecewise=True,
visual_text_color="#fff",
pieces=[
{"min": 0, "max": 13, "label": "0 < x < 13"},
{"min": 14, "max": 16, "label": "14 < x < 16"},
],
effect_scale=5,
)
geo.render()

View File

@ -20,16 +20,6 @@ nodes = [
]
def test_graph_force_layout():
links = []
for i in nodes:
for j in nodes:
links.append({"source": i.get("name"), "target": j.get("name")})
graph = Graph("关系图-力引导布局示例")
graph.add("", nodes, links, repulsion=8000, line_color="#aaa")
graph.render()
def test_graph_circular_layout():
links = []
for i in nodes:

View File

@ -66,31 +66,3 @@ def test_heatmap_yaxis_formatter():
assert r'"formatter": "{value} "' in html_content
assert "Saturday" in html_content
assert "Monday" in html_content
def test_heatmap_calendar():
import datetime
begin = datetime.date(2017, 1, 1)
end = datetime.date(2017, 12, 31)
data = [
[str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
for i in range((end - begin).days + 1)
]
heatmap = HeatMap("日历热力图示例", "某人 2017 年微信步数情况", width=1100)
heatmap.add(
"",
data,
is_calendar_heatmap=True,
visual_text_color="#000",
visual_range_text=["", ""],
visual_range=[1000, 25000],
calendar_cell_size=["auto", 30],
is_visualmap=True,
calendar_date_range="2017",
visual_orient="horizontal",
visual_pos="center",
visual_top="80%",
is_piecewise=True,
)
heatmap.render()

View File

@ -12,13 +12,6 @@ clothes_v1 = [5, 20, 36, 10, 10, 100]
clothes_v2 = [55, 60, 16, 20, 15, 80]
def test_line_marks():
line = Line("折线图示例")
line.add("商家A", CLOTHES, clothes_v1, mark_point=["average"])
line.add("商家B", CLOTHES, clothes_v2, is_smooth=True, mark_line=["max", "average"])
line.render()
def test_line_user_define_markpoint():
line = Line("折线图示例")
line.add(
@ -61,32 +54,6 @@ def test_line_user_define_marks():
assert '"symbolSize":50' not in line._repr_html_()
def test_line_negative_value():
line = Line("折线图示例")
line.add(
"最高气温",
WEEK,
[11, 11, 15, 13, 12, 13, 10],
mark_point=["max", "min"],
mark_line=["average"],
)
line.add(
"最低气温",
WEEK,
[1, -2, 2, 5, 3, 2, 0],
mark_point=["max", "min"],
mark_line=["average"],
)
line.render()
def test_line_type_stack():
line = Line("折线图-数据堆叠示例")
line.add("商家A", CLOTHES, clothes_v1, is_stack=True, is_label_show=True)
line.add("商家B", CLOTHES, clothes_v2, is_stack=True, is_label_show=True)
line.render()
def test_line_type_step():
line = Line("折线图-阶梯图示例")
line.add("商家A", CLOTHES, clothes_v1, is_step=True, is_label_show=True)
@ -116,18 +83,6 @@ def test_line_type_fill():
assert '"step": true' not in line._repr_html_()
def test_line_log_yaxis():
line = Line("折线图示例")
line.add("商家A", CLOTHES, [math.log10(random.randint(1, 99999)) for _ in range(6)])
line.add(
"商家B",
CLOTHES,
[math.log10(random.randint(1, 99999999)) for _ in range(6)],
yaxis_type="log",
)
line.render()
def test_line_mark_point_raw():
line = Line()
line.add(

View File

@ -5,12 +5,6 @@ from __future__ import unicode_literals
from pyecharts import Liquid
def test_liquid_default():
liquid = Liquid("水球图示例")
liquid.add("Liquid", [0.6])
liquid.render()
def test_liquid_multiple_data():
liquid = Liquid("水球图示例")
liquid.add("Liquid", [0.6, 0.5, 0.4, 0.3], is_liquid_outline_show=False)

View File

@ -8,21 +8,6 @@ from pyecharts import NULL, Bar, EffectScatter, Kline, Line, Overlap, Scatter
from pyecharts.javascripthon.dom import JsValue
def test_overlap_bar_line():
attr = ["A", "B", "C", "D", "E", "F"]
v1 = [10, 20, 30, 40, 50, 60]
v2 = [38, 28, 58, 48, 78, 68]
bar = Bar("Line-Bar 示例")
bar.add("bar", attr, v1)
line = Line()
line.add("line", attr, v2)
overlap = Overlap()
overlap.add(bar)
overlap.add(line)
overlap.render()
def test_overlap_es_scatter():
v1 = [10, 20, 30, 40, 50, 60]
v2 = [30, 30, 30, 30, 30, 30]
@ -112,19 +97,6 @@ def test_overlap_two_yaxis():
overlap.render()
def test_line_es():
v1 = [5, 20, 36, 10, 10, 100]
line = Line("line-EffectScatter 示例")
line.add("", CLOTHES, v1, is_random=True)
es = EffectScatter()
es.add("", CLOTHES, v1, effect_scale=8)
overlap = Overlap()
overlap.add(line)
overlap.add(es)
overlap.render()
def test_not_set_in_overlap():
attr = ["A", "B", "C", "D", "E", "F"]
v1 = [10, 20, 30, 40, 50, 60]

View File

@ -5,65 +5,6 @@ from __future__ import unicode_literals
from pyecharts import Parallel
def test_parallel_default():
schema = ["data", "AQI", "PM2.5", "PM10", "CO", "NO2"]
data = [
[1, 91, 45, 125, 0.82, 34],
[2, 65, 27, 78, 0.86, 45],
[3, 83, 60, 84, 1.09, 73],
[4, 109, 81, 121, 1.28, 68],
[5, 106, 77, 114, 1.07, 55],
[6, 109, 81, 121, 1.28, 68],
[7, 106, 77, 114, 1.07, 55],
[8, 89, 65, 78, 0.86, 51, 26],
[9, 53, 33, 47, 0.64, 50, 17],
[10, 80, 55, 80, 1.01, 75, 24],
[11, 117, 81, 124, 1.03, 45],
]
parallel = Parallel("平行坐标系-默认指示器")
parallel.set_schema(schema)
parallel.add("parallel", data, is_random=True)
parallel.render()
def test_parallel_user_define():
c_schema = [
{"dim": 0, "name": "data"},
{"dim": 1, "name": "AQI"},
{"dim": 2, "name": "PM2.5"},
{"dim": 3, "name": "PM10"},
{"dim": 4, "name": "CO"},
{"dim": 5, "name": "NO2"},
{"dim": 6, "name": "CO2"},
{
"dim": 7,
"name": "等级",
"type": "category",
"data": ["", "", "轻度污染", "中度污染", "重度污染", "严重污染"],
},
]
data = [
[1, 91, 45, 125, 0.82, 34, 23, ""],
[2, 65, 27, 78, 0.86, 45, 29, ""],
[3, 83, 60, 84, 1.09, 73, 27, ""],
[4, 109, 81, 121, 1.28, 68, 51, "轻度污染"],
[5, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
[6, 109, 81, 121, 1.28, 68, 51, "轻度污染"],
[7, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
[8, 89, 65, 78, 0.86, 51, 26, ""],
[9, 53, 33, 47, 0.64, 50, 17, ""],
[10, 80, 55, 80, 1.01, 75, 24, ""],
[11, 117, 81, 124, 1.03, 45, 24, "轻度污染"],
[12, 99, 71, 142, 1.1, 62, 42, ""],
[13, 95, 69, 130, 1.28, 74, 50, ""],
[14, 116, 87, 131, 1.47, 84, 40, "轻度污染"],
]
parallel = Parallel("平行坐标系-用户自定义指示器")
parallel.set_schema(c_schema=c_schema)
parallel.add("parallel", data)
parallel.render()
def test_parallel_line_style():
schema = ["data", "AQI", "PM2.5", "PM10", "CO", "NO2"]
data = [[1, 91, 45, 125, 0.82, 34]]

View File

@ -23,15 +23,6 @@ def test_polar_type_scatter_one():
assert '"type": "scatter"' in polar._repr_html_()
def test_polar_type_scatter_more():
data_1 = [(10, random.randint(1, 100)) for i in range(300)]
data_2 = [(11, random.randint(1, 100)) for i in range(300)]
polar = Polar("极坐标系-散点图示例", width=1200, height=600)
polar.add("", data_1, type="scatter")
polar.add("", data_2, type="scatter")
polar.render()
def test_polar_type_effectscatter():
data = [(i, random.randint(1, 100)) for i in range(10)]
polar = Polar("极坐标系-动态散点图示例", width=1200, height=600)

View File

@ -8,52 +8,3 @@ import os
import sys
from pyecharts import Sankey
PY2 = sys.version_info[0] == 2
def test_sankey_default():
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category5", "target": "category6", "value": 25},
]
sankey = Sankey("桑基图示例", width=1200, height=600)
sankey.add(
"sankey",
nodes,
links,
line_opacity=0.2,
line_curve=0.5,
line_color="source",
is_label_show=True,
label_pos="right",
)
sankey.render()
with codecs.open(
os.path.join("fixtures", "energy.json"), "r", encoding="utf-8"
) as f:
j = json.load(f)
sankey = Sankey("桑基图示例", width=1200, height=600)
sankey.add(
"sankey",
nodes=j["nodes"],
links=j["links"],
line_opacity=0.2,
line_curve=0.5,
line_color="source",
is_label_show=True,
label_pos="right",
)
sankey.render()

View File

@ -8,18 +8,6 @@ from nose.tools import eq_
from pyecharts import Scatter3D
def test_scatter3d():
import random
data = [
[random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)]
for _ in range(80)
]
scatter3d = Scatter3D("3D 散点图示例", width=1200, height=600)
scatter3d.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR)
scatter3d.render()
def test_scatter3d_must_use_canvas():
scatter3d = Scatter3D()
eq_(scatter3d.renderer, "canvas")

View File

@ -9,47 +9,6 @@ from pyecharts import NULL, Bar, Line, Map, Overlap, Pie, Style, Timeline
from pyecharts.javascripthon.dom import JsValue
def test_timeline_bar():
bar_1 = Bar("2012 年销量", "数据纯属虚构")
bar_1.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_1.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_1.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_2 = Bar("2013 年销量", "数据纯属虚构")
bar_2.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_2.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_2.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_3 = Bar("2014 年销量", "数据纯属虚构")
bar_3.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_3.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_3.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_4 = Bar("2015 年销量", "数据纯属虚构")
bar_4.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_4.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_4.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_5 = Bar("2016 年销量", "数据纯属虚构")
bar_5.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_5.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
bar_5.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)], is_legend_show=True)
timeline = Timeline(is_auto_play=True, timeline_bottom=0)
timeline.add(bar_1, "2012 年")
timeline.add(bar_2, "2013 年")
timeline.add(bar_3, "2014 年")
timeline.add(bar_4, "2015 年")
timeline.add(bar_5, "2016 年")
assert len(timeline._option.get("baseOption").get("series")) == 0
timeline.render()
def test_timeline_pie():
style = Style()
pie_style = style.add(is_label_show=True, radius=[30, 55], rosetype="radius")