Skip to content

Commit

Permalink
Release version 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx authored Jun 19, 2019
2 parents 50ae9bf + afafebc commit d6eba30
Show file tree
Hide file tree
Showing 76 changed files with 1,072 additions and 562 deletions.
12 changes: 12 additions & 0 deletions example/echarts_china_counties_js_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.datasets import register_url

register_url("https://echarts-maps.github.io/echarts-china-counties-js/")

g = (
Geo()
.add_schema(maptype="海淀区")
.set_global_opts(title_opts=opts.TitleOpts(title="海淀区"))
)
g.render()
12 changes: 12 additions & 0 deletions example/echarts_countries_js_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.datasets import register_url

register_url("https://echarts-maps.github.io/echarts-countries-js/")

g = (
Geo()
.add_schema(maptype="瑞士")
.set_global_opts(title_opts=opts.TitleOpts(title="瑞士"))
)
g.render()
198 changes: 198 additions & 0 deletions example/graphic_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
from example.commons import Collector, Faker
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Page
from pyecharts.commons.utils import JsCode

C = Collector()


@C.funcs
def bar_graphic_rect_text_one_component() -> Bar:
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 1 组件示例"),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(
rotation=JsCode("Math.PI / 4"),
bounding="raw",
right=110,
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="pyecharts bar chart",
font="bold 26px Microsoft YaHei",
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="#fff"
),
),
),
],
)
],
)
)
return c


@C.funcs
def bar_graphic_rect_text_two_component() -> Bar:
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 2 组件示例"),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(left="50%", top="15%"),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
z=100, left="center", top="middle"
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=190, height=90
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="#fff",
stroke="#555",
line_width=2,
shadow_blur=8,
shadow_offset_x=3,
shadow_offset_y=3,
shadow_color="rgba(0,0,0,0.3)",
),
),
opts.GraphicText(
graphic_item=opts.GraphicItem(
left="center", top="middle", z=100
),
graphic_textstyle_opts=opts.GraphicTextStyleOpts(
text=JsCode(
"['横轴表示数据类别',"
"'纵轴表示数值的值',"
"'这个文本块可以放在图中各',"
"'种位置'].join('\\n')"
),
font="14px Microsoft YaHei",
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="#333"
),
),
),
],
)
],
)
)
return c


@C.funcs
def bar_graphic_image_component() -> Bar:
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-Graphic Image 组件示例"),
graphic_opts=[
opts.GraphicImage(
graphic_item=opts.GraphicItem(
id_="logo",
right=20,
top=20,
z=-10,
bounding="raw",
origin=[75, 75],
),
graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
image="http://echarts.baidu.com/images/favicon.png",
width=150,
height=150,
opacity=0.4,
),
)
],
)
)
return c


@C.funcs
def bar_graphic_image_with_js_component() -> Grid:
bar = (
Bar(init_opts=opts.InitOpts(chart_id="1234"))
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-Graphic Image(旋转功能)组件示例"),
graphic_opts=[
opts.GraphicImage(
graphic_item=opts.GraphicItem(
id_="logo",
right=20,
top=20,
z=-10,
bounding="raw",
origin=[75, 75],
),
graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
image="http://echarts.baidu.com/images/favicon.png",
width=150,
height=150,
opacity=0.4,
),
)
],
)
)
c = (
Grid(init_opts=opts.InitOpts(chart_id="1234"))
.add(
chart=bar,
grid_opts=opts.GridOpts(pos_left="5%", pos_right="4%", pos_bottom="5%"),
)
.add_js_funcs(
"""
var rotation = 0;
setInterval(function () {
chart_1234.setOption({
graphic: {
id: 'logo',
rotation: (rotation += Math.PI / 360) % (Math.PI * 2)
}
});
}, 30);
"""
)
)
return c


Page().add(*[fn() for fn, _ in C.charts]).render()
26 changes: 26 additions & 0 deletions example/pie_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ def pie_rosetype() -> Pie:
return c


@C.funcs
def pie_scroll_legend() -> Pie:
c = (
Pie()
.add(
"",
[
list(z)
for z in zip(
Faker.choose() + Faker.choose() + Faker.choose(),
Faker.values() + Faker.values() + Faker.values(),
)
],
center=["40%", "50%"],
)
.set_global_opts(
title_opts=opts.TitleOpts(title="Pie-Legend 滚动"),
legend_opts=opts.LegendOpts(
type_="scroll", pos_left="80%", orient="vertical"
),
)
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
return c


@C.funcs
def pie_rich_label() -> Pie:
c = (
Expand Down
13 changes: 7 additions & 6 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
with open(os.path.join(here, "pyecharts", "_version.py")) as f:
exec(f.read(), about)

UNINSTALL = "{} uninstall pyecharts -y"
INSTALL = "{} install -U dist/pyecharts-{}-py3-none-any.whl --no-cache-dir"

os.system("python setup.py bdist_wheel")
os.system("pip uninstall pyecharts -y")
os.system(
"pip install -U dist/pyecharts-{}-py3-none-any.whl --no-cache-dir".format(
about["__version__"]
)
)
os.system(UNINSTALL.format("pip"))
os.system(UNINSTALL.format("pip3"))
os.system(INSTALL.format("pip", about["__version__"]))
os.system(INSTALL.format("pip3", about["__version__"]))
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.2.0"
__version__ = "1.2.1"
__author__ = "chenjiandongx"
32 changes: 19 additions & 13 deletions pyecharts/charts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,42 @@
import json
import os
import uuid
from typing import Sequence

from jinja2 import Environment

from ..commons import utils
from ..commons.types import Optional
from ..datasets import FILENAMES
from ..globals import CurrentConfig, NotebookType, ThemeType
from ..options import InitOpts
from ..options.series_options import BasicOpts
from ..render.display import HTML, Javascript
from ..render.engine import RenderEngine
from ..types import Optional, Sequence, Union


class Base:
"""
`Base`类是所有图形类的基类,提供部分初始化参数和基本的方法
`Base` is the root class for all graphical class, it provides
part of the initialization parameters and common methods
"""

def __init__(self, init_opts: InitOpts = InitOpts()):
self.width = init_opts.width
self.height = init_opts.height
self.renderer = init_opts.renderer
self.page_title = init_opts.page_title
self.theme = init_opts.theme
self.chart_id = init_opts.chart_id or uuid.uuid4().hex
def __init__(self, init_opts: Union[InitOpts, dict] = InitOpts()):
_opts = init_opts
if isinstance(init_opts, InitOpts):
_opts = init_opts.opts

self.width = _opts.get("width")
self.height = _opts.get("height")
self.renderer = _opts.get("renderer")
self.page_title = _opts.get("page_title")
self.theme = _opts.get("theme")
self.chart_id = _opts.get("chart_id") or uuid.uuid4().hex

self.options: dict = {}
self.js_host: str = init_opts.js_host or CurrentConfig.ONLINE_HOST
self.js_host: str = _opts.get("js_host") or CurrentConfig.ONLINE_HOST
self.js_functions: utils.OrderedSet = utils.OrderedSet()
self.js_dependencies: utils.OrderedSet = utils.OrderedSet("echarts")
self.options.update(backgroundColor=init_opts.bg_color)
self.options.update(backgroundColor=_opts.get("bg_color"))
self._is_geo_chart: bool = False

def add_js_funcs(self, *fns):
Expand All @@ -45,7 +49,9 @@ def get_options(self) -> dict:
return utils.remove_key_with_none_value(self.options)

def dump_options(self) -> str:
return json.dumps(self.get_options(), indent=4, default=default)
return utils.replace_placeholder(
json.dumps(self.get_options(), indent=4, default=default)
)

def render(
self,
Expand Down
29 changes: 13 additions & 16 deletions pyecharts/charts/basic_charts/bar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ... import options as opts
from ... import types
from ...charts.chart import RectChart
from ...commons.types import Numeric, Optional, Sequence, Union
from ...globals import ChartType


Expand All @@ -12,26 +12,23 @@ class Bar(RectChart):
with heights or lengths proportional to the values that they represent.
"""

def __init__(self, init_opts: opts.InitOpts = opts.InitOpts()):
super().__init__(init_opts=init_opts)

def add_yaxis(
self,
series_name: str,
yaxis_data: Sequence[Union[Numeric, opts.BarItem, dict]],
yaxis_data: types.Sequence[types.Union[types.Numeric, opts.BarItem, dict]],
*,
is_selected: bool = True,
xaxis_index: Optional[Numeric] = None,
yaxis_index: Optional[Numeric] = None,
color: Optional[str] = None,
stack: Optional[str] = None,
category_gap: Union[Numeric, str] = "20%",
gap: Optional[str] = None,
label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(),
markpoint_opts: Union[opts.MarkPointOpts, dict, None] = None,
markline_opts: Union[opts.MarkLineOpts, dict, None] = None,
tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,
itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,
xaxis_index: types.Optional[types.Numeric] = None,
yaxis_index: types.Optional[types.Numeric] = None,
color: types.Optional[str] = None,
stack: types.Optional[str] = None,
category_gap: types.Union[types.Numeric, str] = "20%",
gap: types.Optional[str] = None,
label_opts: types.Label = opts.LabelOpts(),
markpoint_opts: types.MarkPoint = None,
markline_opts: types.MarkLine = None,
tooltip_opts: types.Tooltip = None,
itemstyle_opts: types.ItemStyle = None,
):
self._append_color(color)
self._append_legend(series_name, is_selected)
Expand Down
Loading

0 comments on commit d6eba30

Please sign in to comment.