Skip to content

Commit

Permalink
Clean code (pyecharts#1081)
Browse files Browse the repository at this point in the history
* Format: code

* Remove: #coding=utf-8

* Add: 新增示例以及数据 json 文件

* Update: 移除 List 使用 Sequence 代替,移除 instance 判断

* Update: 修复 Geo Lines 线条丢失的问题

* Remove: 移除 Mark* data 类型判断

* Update: js_functions/bmap_js_funtions 分开处理

* Update: 解决 Grid 图 title 不为 List 的问题

* Update: self.color 对外暴露

* Test: 完善测试

* Update: 更新测试和示例

* Fix: test

* Fix: 修复 Grid 不能正常渲染主题以及标题的问题

* Add: Bar 图新增 gap 参数

* Add: example

* Update: 百度地图 ak 保存至环境变量中
  • Loading branch information
chenjiandongx authored May 8, 2019
1 parent 07f1c78 commit b8aad7d
Show file tree
Hide file tree
Showing 56 changed files with 6,125 additions and 206 deletions.
1 change: 0 additions & 1 deletion example/bar3d_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import random

from example.commons import Collector, Faker
Expand Down
29 changes: 28 additions & 1 deletion example/bar_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
from example.commons import Collector, Faker
from pyecharts import options as opts
from pyecharts.charts import Bar, Page
Expand Down Expand Up @@ -46,6 +45,18 @@ def bar_toolbox() -> Bar:
return c


@C.funcs
def bar_gap() -> Bar:
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values(), gap="0%")
.add_yaxis("商家B", Faker.values(), gap="0%")
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-不同系列柱间距离"))
)
return c


@C.funcs
def bar_yaxis_formatter() -> Bar:
c = (
Expand All @@ -63,6 +74,22 @@ def bar_yaxis_formatter() -> Bar:
return c


@C.funcs
def bar_xyaxis_name() -> 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-XY 轴名称"),
yaxis_opts=opts.AxisOpts(name="我是 Y 轴"),
xaxis_opts=opts.AxisOpts(name="我是 X 轴"),
)
)
return c


@C.funcs
def bar_reversal_axis() -> Bar:
c = (
Expand Down
127 changes: 126 additions & 1 deletion example/bmap_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import json
import os

from example.commons import Collector, Faker
from pyecharts import options as opts
from pyecharts.charts import BMap, Page
from pyecharts.globals import BMapType

C = Collector()
BAIDU_MAP_AK = os.environ.get("BAIDU_MAP_AK", "FAKE_AK")


@C.funcs
Expand All @@ -11,7 +16,7 @@ def bmap_base() -> BMap:
c = (
BMap()
.add_schema(
baidu_ak="Uf1rIjuIVVXxDwEy0iEU0tApwdoqGeGn",
baidu_ak=BAIDU_MAP_AK,
center=[120.13066322374, 30.240018034923],
)
.add(
Expand All @@ -24,4 +29,124 @@ def bmap_base() -> BMap:
return c


@C.funcs
def bmap_lines() -> BMap:
with open(
os.path.join("fixtures", "hangzhou-tracks.json"), "r", encoding="utf-8"
) as f:
j = json.load(f)
c = (
BMap()
.add_schema(
baidu_ak=BAIDU_MAP_AK,
center=[120.13066322374, 30.240018034923],
zoom=14,
is_roam=True,
map_style={
"styleJson": [
{
"featureType": "water",
"elementType": "all",
"stylers": {"color": "#d1d1d1"},
},
{
"featureType": "land",
"elementType": "all",
"stylers": {"color": "#f3f3f3"},
},
{
"featureType": "railway",
"elementType": "all",
"stylers": {"visibility": "off"},
},
{
"featureType": "highway",
"elementType": "all",
"stylers": {"color": "#fdfdfd"},
},
{
"featureType": "highway",
"elementType": "labels",
"stylers": {"visibility": "off"},
},
{
"featureType": "arterial",
"elementType": "geometry",
"stylers": {"color": "#fefefe"},
},
{
"featureType": "arterial",
"elementType": "geometry.fill",
"stylers": {"color": "#fefefe"},
},
{
"featureType": "poi",
"elementType": "all",
"stylers": {"visibility": "off"},
},
{
"featureType": "green",
"elementType": "all",
"stylers": {"visibility": "off"},
},
{
"featureType": "subway",
"elementType": "all",
"stylers": {"visibility": "off"},
},
{
"featureType": "manmade",
"elementType": "all",
"stylers": {"color": "#d1d1d1"},
},
{
"featureType": "local",
"elementType": "all",
"stylers": {"color": "#d1d1d1"},
},
{
"featureType": "arterial",
"elementType": "labels",
"stylers": {"visibility": "off"},
},
{
"featureType": "boundary",
"elementType": "all",
"stylers": {"color": "#fefefe"},
},
{
"featureType": "building",
"elementType": "all",
"stylers": {"color": "#d1d1d1"},
},
{
"featureType": "label",
"elementType": "labels.text.fill",
"stylers": {"color": "#999999"},
},
]
},
)
.add(
"",
type_="lines",
data_pair=j,
is_polyline=True,
is_large=True,
linestyle_opts=opts.LineStyleOpts(color="purple", opacity=0.6, width=1),
)
.add_control_panel(
copyright_control_opts=opts.BMapCopyrightType(position=3),
maptype_control_opts=opts.BMapTypeControl(
type_=BMapType.BMAP_MAPTYPE_CONTROL_DROPDOWN
),
scale_control_opts=opts.BMapScaleControlOpts(),
overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
navigation_control_opts=opts.BMapNavigationControlOpts(),
)
.set_global_opts(title_opts=opts.TitleOpts(title="BMap-Lines"))
)
return c


Page().add(*[fn() for fn, _ in C.charts]).render()
1 change: 0 additions & 1 deletion example/boxplot_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
from example.commons import Collector
from pyecharts import options as opts
from pyecharts.charts import Boxplot, Page
Expand Down
1 change: 0 additions & 1 deletion example/calendar_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import datetime
import random

Expand Down
1 change: 0 additions & 1 deletion example/commons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import os
import random

Expand Down
1 change: 0 additions & 1 deletion example/effectscatter_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
from example.commons import Collector, Faker
from pyecharts import options as opts
from pyecharts.charts import EffectScatter, Page
Expand Down
Loading

0 comments on commit b8aad7d

Please sign in to comment.