Skip to content

Commit 3c896c9

Browse files
committed
feat: add component api
1 parent f717851 commit 3c896c9

File tree

6 files changed

+903
-5
lines changed

6 files changed

+903
-5
lines changed

examples/component_demo.ipynb

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "2142be9e-460c-45af-88aa-d356954b0caa",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pygwalker as pyg\n",
11+
"import pandas as pd"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"id": "7384b136-9098-482d-8914-1663547dc6ae",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"df = pd.read_csv(\"https://kanaries-app.s3.ap-northeast-1.amazonaws.com/public-datasets/bike_sharing_dc.csv\")"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "45cbe3c8-6606-498b-a741-455425798cc9",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"pyg.component(df).bar().encode(x=\"season\", y=\"sum(casual)\")"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "cf5f40ff-a2ed-44c6-9f85-d633b75fa020",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"component = pyg.component(df)\n",
42+
"component_0 = component.encode(x=\"season\", y=\"sum(casual)\")"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"id": "a98cf2a9-5286-4f4a-9279-d51a69d166bb",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"component_0.bar()"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"id": "d81d0c87-4c6f-42f8-8d22-8b32fc61384f",
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"component_0.area()"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": null,
68+
"id": "b5f1b05a-4b43-4f73-9558-1ce2edae81a3",
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"component_0.line()"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "9d8f9721-688f-4ade-aaaa-577be9bda56a",
79+
"metadata": {},
80+
"outputs": [],
81+
"source": [
82+
"component_0.trail()"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": null,
88+
"id": "901ecec4-cddc-4b74-afac-c82a7c52e98e",
89+
"metadata": {},
90+
"outputs": [],
91+
"source": [
92+
"component.scatter().encode(x=\"feeling_temp\", y=\"temperature\", color=\"humidity\")"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": null,
98+
"id": "98bb748f-0aaf-4b43-acbe-0524eafe10af",
99+
"metadata": {},
100+
"outputs": [],
101+
"source": [
102+
"component.circle().encode(x=\"feeling_temp\", y=\"temperature\", color=\"humidity\")"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"id": "80c52a23-b3e3-4957-860f-21dd80b6ef47",
109+
"metadata": {},
110+
"outputs": [],
111+
"source": [
112+
"(\n",
113+
"component\n",
114+
" .rect()\n",
115+
" .encode(x='bin(\"feeling_temp\", 6)', y='bin(\"temperature\", 6)', color=\"MEAN(humidity)\")\n",
116+
" .layout(height=400, width=460)\n",
117+
")"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"id": "4cbf2edb-8bef-4190-986f-62b48517e7f4",
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"component.arc().encode(theta=\"SUM(registered)\", color=\"season\")"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"id": "f622848b-6122-4ee4-a7b1-d8521520b63f",
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"component_0.bar().explorer()"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"id": "aafdd3b4-6819-480f-9c34-70c8d1aa410e",
144+
"metadata": {},
145+
"outputs": [],
146+
"source": [
147+
"component_0.profiling()"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"id": "bff819f3-209d-4a78-b723-103b70dfb2a5",
154+
"metadata": {},
155+
"outputs": [],
156+
"source": []
157+
}
158+
],
159+
"metadata": {
160+
"kernelspec": {
161+
"display_name": "Python 3 (ipykernel)",
162+
"language": "python",
163+
"name": "python3"
164+
},
165+
"language_info": {
166+
"codemirror_mode": {
167+
"name": "ipython",
168+
"version": 3
169+
},
170+
"file_extension": ".py",
171+
"mimetype": "text/x-python",
172+
"name": "python",
173+
"nbconvert_exporter": "python",
174+
"pygments_lexer": "ipython3",
175+
"version": "3.11.7"
176+
}
177+
},
178+
"nbformat": 4,
179+
"nbformat_minor": 5
180+
}

pygwalker/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
from pygwalker.services.global_var import GlobalVarManager
1111
from pygwalker.services.kaggle import show_tips_user_kaggle as __show_tips_user_kaggle
1212

13-
__version__ = "0.4.9.1"
13+
__version__ = "0.4.9.2"
1414
__hash__ = __rand_str()
1515

1616
from pygwalker.api.jupyter import walk, render, table
1717
from pygwalker.api.html import to_html
1818
from pygwalker.data_parsers.base import FieldSpec
19+
from pygwalker.api.component import component
1920

2021
if GlobalVarManager.privacy == 'offline':
2122
logging.getLogger(__name__).info("Running in offline mode. There might be newer releases available. Please check at https://github.com/Kanaries/pygwalker or https://pypi.org/project/pygwalker.")
2223

2324
if __check_kaggle():
2425
__show_tips_user_kaggle()
2526

26-
__all__ = ["walk", "render", "table", "to_html", "FieldSpec", "GlobalVarManager"]
27+
__all__ = ["walk", "render", "table", "to_html", "FieldSpec", "GlobalVarManager", "component"]

0 commit comments

Comments
 (0)