From 63bea595f2e3f6786f4d1a4a7b900bbea05b6aec Mon Sep 17 00:00:00 2001 From: hustcc Date: Wed, 3 Mar 2021 09:32:22 +0800 Subject: [PATCH 1/3] docs: update documents (#22) * docs: update documents * fix: typo * chore: add badge --- README.md | 8 ++++++-- README_ZH.md | 8 ++++++-- docs/how.md | 4 +++- docs/jupyter.md | 1 + docs/plot.md | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f01ed9b..ece433b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![Latest Stable Version](https://img.shields.io/pypi/v/pyg2plot.svg)](https://pypi.python.org/pypi/pyg2plot) [![build Status](https://github.com/hustcc/pyg2plot/workflows/build/badge.svg?branch=main)](https://github.com/hustcc/pyg2plot/actions?query=workflow%3Abuild) +[![Pypi Download](https://img.shields.io/pypi/dm/pyg2plot)](https://pypi.python.org/pypi/pyg2plot) +
@@ -98,9 +100,11 @@ Now, only has one API of `pyg2plot`. 4. *plot.render_notebook(env, **kwargs)*: render plot on jupyter preview. -5. *plot.render_html(env, **kwargs)*: render out html string by setting jinja2 env and kwargs. +5. *plot.render_jupyter_lab(env, **kwargs)*: render plot on jupyter lab preview. + +6. *plot.render_html(env, **kwargs)*: render out html string by setting jinja2 env and kwargs. -6. *plot.dump_js_options(env, **kwargs)*: dump js options by setting jinja2 env and kwargs, use it for HTTP request. +7. *plot.dump_js_options(env, **kwargs)*: dump js options by setting jinja2 env and kwargs, use it for HTTP request. > More apis is on the way. diff --git a/README_ZH.md b/README_ZH.md index 752f73d..af0df63 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -4,6 +4,8 @@ [![Latest Stable Version](https://img.shields.io/pypi/v/pyg2plot.svg)](https://pypi.python.org/pypi/pyg2plot) [![build Status](https://github.com/hustcc/pyg2plot/workflows/build/badge.svg?branch=main)](https://github.com/hustcc/pyg2plot/actions?query=workflow%3Abuild) +[![Pypi Download](https://img.shields.io/pypi/dm/pyg2plot)](https://pypi.python.org/pypi/pyg2plot) +
@@ -97,9 +99,11 @@ line.render_jupyter_lab() 4. *plot.render_notebook(env, **kwargs)*: 将图形渲染到 jupyter 的预览。 -5. *plot.render_html(env, **kwargs)*: 渲染出 HTML 字符串,同时可以传入 jinja2 env 和 kwargs 参数。 +5. *plot.render_jupyter_lab(env, **kwargs)*: 将图形渲染到 jupyter lab 的预览。 + +6. *plot.render_html(env, **kwargs)*: 渲染出 HTML 字符串,同时可以传入 jinja2 env 和 kwargs 参数。 -6. *plot.dump_js_options(env, **kwargs)*: 输出 Javascript 的 option 配置结构,同时可以传入 jinja2 env 和 kwargs 参数,可以用于 Server 中的 HTTP 结构返回数据结构。 +7. *plot.dump_js_options(env, **kwargs)*: 输出 Javascript 的 option 配置结构,同时可以传入 jinja2 env 和 kwargs 参数,可以用于 Server 中的 HTTP 结构返回数据结构。 > 更多区分 Plot 级别的语法糖 API 还在筹备中。 diff --git a/docs/how.md b/docs/how.md index 6b3e406..de6fc8c 100644 --- a/docs/how.md +++ b/docs/how.md @@ -34,8 +34,10 @@ line.set_options({ line.render("plot.html") # 2. 渲染成 html 字符串 line.render_html() -# 2. 渲染到 Jupyter 的预览区 +# 3. 渲染到 Jupyter 的预览区 line.render_notebook() +# 4. 渲染到 Jupyter Lab 的预览区 +line.render_jupyter_lab() ``` > 所以对于 PyG2Plot,核心文件是: diff --git a/docs/jupyter.md b/docs/jupyter.md index 38edba6..ad3d889 100644 --- a/docs/jupyter.md +++ b/docs/jupyter.md @@ -109,5 +109,6 @@ scatter.render_notebook() ![image](https://user-images.githubusercontent.com/7856674/105945664-ab4e4780-60a0-11eb-88d9-602a86e39368.png) +而对于 Jupyter Lab,除了上述代码中的 `render_notebook` 改成 `render_jupyter_lab` 之外,其他用法完全一样。 > 大概就是这样的一个使用方式了,本质没有任何使用区别。更多其他的图表类型,可以参考 [绘制常用统计图表](./plot.md)。 diff --git a/docs/plot.md b/docs/plot.md index a6440bd..b1b4b22 100644 --- a/docs/plot.md +++ b/docs/plot.md @@ -79,4 +79,4 @@ ---- -> 更多其他图表的使用,可以参考上述的做法,当然欢迎大家在下方扩展更多图表的使用方法和示例! \ No newline at end of file +> 更多其他图表的使用,可以参考上述的做法,对于图表的名称和 G2Plot 官网的名称保持完全一致。欢迎大家在下方扩展更多图表的使用方法和示例! \ No newline at end of file From 56cba7f0a04a596c3afea1610efb435078d9f8d5 Mon Sep 17 00:00:00 2001 From: hustcc Date: Wed, 3 Mar 2021 10:23:14 +0800 Subject: [PATCH 2/3] chore: keyword typo (#23) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 905def3..6895cbc 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ def read(*names, **kwargs): __extra_requires__ = { } -__keywords__ = ["AntV", "G2Plot" "charts", "visualazation"] +__keywords__ = ["AntV", "G2Plot", "charts", "PyG2Plot", "visualization"] # Load the package's _version.py module as a dictionary. here = os.path.abspath(os.path.dirname(__file__)) From e469c7327519c848710f994ac033f41b2147c5df Mon Sep 17 00:00:00 2001 From: hustcc Date: 2021年4月25日 21:08:30 +0800 Subject: [PATCH 3/3] feat: add JS api (#27) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 逍为 --- README.md | 30 ++++++++++++++++++++++++++++++ README_ZH.md | 30 ++++++++++++++++++++++++++++++ pyg2plot/helper/code.py | 10 ++++++++-- pyg2plot/meta.py | 2 +- 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ece433b..9281a0e 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,36 @@ line.render_notebook() line.render_jupyter_lab() ``` +#### **use JavaScript callback** + +```py +from pyg2plot import Plot, JS + +line = Plot("Line") + +line.set_options({ + "height": 400, # set a default height in jupyter preview + "data": [ + { "year": "1991", "value": 3 }, + { "year": "1992", "value": 4 }, + { "year": "1993", "value": 3.5 }, + { "year": "1994", "value": 5 }, + { "year": "1995", "value": 4.9 }, + { "year": "1996", "value": 6 }, + { "year": "1997", "value": 7 }, + { "year": "1998", "value": 9 }, + { "year": "1999", "value": 13 }, + ], + "xField": "year", + "yField": "value", + "lineStye": JS('''function() { + return { stroke: 'red' }; + }''') +}) +``` + +Use `JS` API, you can use JavaScript syntax for callback. + ## API diff --git a/README_ZH.md b/README_ZH.md index af0df63..dbd3d9b 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -84,6 +84,36 @@ line.render_notebook() line.render_jupyter_lab() ``` +#### **使用 JavaScript 回调** + +```py +from pyg2plot import Plot, JS + +line = Plot("Line") + +line.set_options({ + "height": 400, # set a default height in jupyter preview + "data": [ + { "year": "1991", "value": 3 }, + { "year": "1992", "value": 4 }, + { "year": "1993", "value": 3.5 }, + { "year": "1994", "value": 5 }, + { "year": "1995", "value": 4.9 }, + { "year": "1996", "value": 6 }, + { "year": "1997", "value": 7 }, + { "year": "1998", "value": 9 }, + { "year": "1999", "value": 13 }, + ], + "xField": "year", + "yField": "value", + "lineStye": JS('''function() { + return { stroke: 'red' }; + }''') +}) +``` + +使用 `JS` 方法,你可以创建一个 JavaScript 的代码片段去处理各种回调方法属性。 + ## API diff --git a/pyg2plot/helper/code.py b/pyg2plot/helper/code.py index 4f58b55..9d1bda8 100644 --- a/pyg2plot/helper/code.py +++ b/pyg2plot/helper/code.py @@ -3,10 +3,12 @@ import re import datetime +# no JSON.stringigy in Python +SEP = "!!-_-____-_-!!" class JS: def __init__(self, js_code: str): - self.js_code = js_code + self.js_code = "%s%s%s" % (SEP, js_code, SEP) def replace(self, pattern: str, repl: str): self.js_code = re.sub(pattern, repl, self.js_code) @@ -22,4 +24,8 @@ def _json_dump_default(o: object): def json_dump_to_js(options: object): - return simplejson.dumps(options, indent=2, default=_json_dump_default, ignore_nan=True) + return re.sub( + '"?%s"?' % SEP, + "", + simplejson.dumps(options, indent=2, default=_json_dump_default, ignore_nan=True) + ) diff --git a/pyg2plot/meta.py b/pyg2plot/meta.py index 82e9d58..c3df4b3 100644 --- a/pyg2plot/meta.py +++ b/pyg2plot/meta.py @@ -6,5 +6,5 @@ > pkg meta information ''' -__version__ = "0.1.7" +__version__ = "0.1.8" __author__ = "hustcc"

AltStyle によって変換されたページ (->オリジナル) /