instaui 0.1.11__py3-none-any.whl → 0.1.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- instaui/extra_libs/_echarts.py +3 -0
- instaui/extra_libs/_import_error.py +9 -0
- instaui/extra_libs/_mermaid.py +3 -0
- instaui/extra_libs/_shiki_code.py +3 -0
- instaui/static/insta-ui.css +1 -1
- instaui/static/insta-ui.esm-browser.prod.js +3717 -3717
- instaui/static/vue.global.prod.js +9 -9
- instaui/systems/module_system.py +22 -6
- instaui/ui/__init__.py +10 -6
- instaui/ui/__init__.pyi +12 -2
- {instaui-0.1.11.dist-info → instaui-0.1.12.dist-info}/METADATA +1 -1
- {instaui-0.1.11.dist-info → instaui-0.1.12.dist-info}/RECORD +14 -14
- instaui/components/echarts/echarts.js +0 -130
- instaui/components/echarts/echarts.py +0 -194
- instaui/components/echarts/static/echarts.esm.min.js +0 -45
- instaui/components/mermaid.py +0 -0
- {instaui-0.1.11.dist-info → instaui-0.1.12.dist-info}/WHEEL +0 -0
- {instaui-0.1.11.dist-info → instaui-0.1.12.dist-info}/licenses/LICENSE +0 -0
instaui/systems/module_system.py
CHANGED
@@ -1,29 +1,45 @@
|
|
1
1
|
from importlib import import_module
|
2
2
|
from types import ModuleType
|
3
|
-
from typing import Any, List
|
3
|
+
from typing import Any, Callable, List, Optional
|
4
|
+
from instaui.runtime.context import get_context
|
4
5
|
|
5
6
|
|
6
7
|
class LazyModule(ModuleType):
|
7
|
-
def __init__(
|
8
|
+
def __init__(
|
9
|
+
self,
|
10
|
+
name: str,
|
11
|
+
member: str,
|
12
|
+
*,
|
13
|
+
import_error_callback: Optional[Callable[[Exception], None]] = None,
|
14
|
+
):
|
8
15
|
super().__init__(name)
|
9
16
|
self._name = name
|
10
17
|
self._mod = None
|
11
18
|
self._member_obj = None
|
12
19
|
self._member = member
|
20
|
+
self._import_error_callback = import_error_callback
|
13
21
|
|
14
22
|
def __getattr__(self, attr: str) -> Any:
|
15
|
-
self.
|
16
|
-
return getattr(self._member_obj, attr)
|
23
|
+
return self.__try_run(lambda: getattr(self._member_obj, attr)) # type: ignore
|
17
24
|
|
18
25
|
def __call__(self, *args: Any, **kwds: Any) -> Any:
|
19
|
-
self.
|
20
|
-
return self._member_obj(*args, **kwds) # type: ignore
|
26
|
+
return self.__try_run(lambda: self._member_obj(*args, **kwds)) # type: ignore
|
21
27
|
|
22
28
|
def __dir__(self) -> List[str]:
|
23
29
|
if self._mod is None:
|
24
30
|
self._mod = import_module(self._name)
|
25
31
|
return dir(self._mod)
|
26
32
|
|
33
|
+
def __try_run(self, fn: Callable[..., Any]):
|
34
|
+
try:
|
35
|
+
self.__try_import()
|
36
|
+
return fn() # type: ignore
|
37
|
+
except ImportError as e:
|
38
|
+
if get_context().debug_mode and (self._import_error_callback is not None):
|
39
|
+
self._import_error_callback(e)
|
40
|
+
else:
|
41
|
+
raise e
|
42
|
+
|
27
43
|
def __try_import(self):
|
28
44
|
if self._mod is None:
|
29
45
|
self._mod = import_module(self._name)
|
instaui/ui/__init__.py
CHANGED
@@ -68,6 +68,7 @@ __all__ = [
|
|
68
68
|
"markdown",
|
69
69
|
"echarts",
|
70
70
|
"use_shadcn_classless",
|
71
|
+
"mermaid",
|
71
72
|
]
|
72
73
|
|
73
74
|
# -- static imports
|
@@ -130,11 +131,14 @@ from instaui.ui_functions.str_format import str_format
|
|
130
131
|
from instaui.ui_functions.ui_types import TBindable, is_bindable
|
131
132
|
|
132
133
|
from .events import on_page_request_lifespan
|
134
|
+
from instaui.extra_libs._import_error import show_error # noqa: E402, F401
|
133
135
|
|
134
136
|
# -- dynamic imports
|
135
|
-
from instaui.systems.module_system import LazyModule
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
from instaui.systems.module_system import LazyModule as _LazyModule
|
138
|
+
markdown = _LazyModule('instaui.components.markdown.markdown', 'Markdown')
|
139
|
+
webview = _LazyModule('instaui.webview', 'WebviewWrapper')
|
140
|
+
use_shadcn_classless = _LazyModule('instaui.shadcn_classless._index', 'use_shadcn_classless')
|
141
|
+
# -- extra libs
|
142
|
+
mermaid = _LazyModule('instaui.extra_libs._mermaid', 'mermaid', import_error_callback=show_error('Mermaid is not installed. Please run "pip install instaui-mermaid" to install it.'),)
|
143
|
+
code = _LazyModule('instaui.extra_libs._shiki_code', 'code', import_error_callback=show_error('Shiki is not installed. Please run "pip install instaui-shiki" to install it.'),)
|
144
|
+
echarts = _LazyModule('instaui.extra_libs._echarts', 'echarts', import_error_callback=show_error('Echarts is not installed. Please run "pip install instaui-echarts" to install it.'),)
|
instaui/ui/__init__.pyi
CHANGED
@@ -68,6 +68,7 @@ __all__ = [
|
|
68
68
|
"markdown",
|
69
69
|
"echarts",
|
70
70
|
"use_shadcn_classless",
|
71
|
+
"mermaid",
|
71
72
|
]
|
72
73
|
|
73
74
|
# -- static imports
|
@@ -130,10 +131,19 @@ from instaui.ui_functions.str_format import str_format
|
|
130
131
|
from instaui.ui_functions.ui_types import TBindable, is_bindable
|
131
132
|
|
132
133
|
from .events import on_page_request_lifespan
|
134
|
+
from instaui.extra_libs._import_error import show_error # noqa: E402, F401
|
133
135
|
|
134
136
|
# -- dynamic imports
|
135
|
-
from instaui.components.shiki_code.shiki_code import Code as code
|
136
137
|
from instaui.components.markdown.markdown import Markdown as markdown
|
137
138
|
from instaui.webview import WebviewWrapper as webview
|
138
|
-
from instaui.components.echarts.echarts import ECharts as echarts
|
139
139
|
from instaui.shadcn_classless._index import use_shadcn_classless
|
140
|
+
|
141
|
+
# -- extra libs
|
142
|
+
# mermaid = _LazyModule('instaui.extra_libs._mermaid', 'mermaid', import_error_callback=show_error('Mermaid is not installed. Please run "pip install instaui-mermaid" to install it.'),)
|
143
|
+
from instaui_mermaid import Mermaid as mermaid # type: ignore
|
144
|
+
|
145
|
+
# code = _LazyModule('instaui.extra_libs._shiki_code', 'code', import_error_callback=show_error('Shiki is not installed. Please run "pip install instaui-shiki" to install it.'),)
|
146
|
+
from instaui_shiki import shiki as code # type: ignore
|
147
|
+
|
148
|
+
# echarts = _LazyModule('instaui.extra_libs._echarts', 'echarts', import_error_callback=show_error('Echarts is not installed. Please run "pip install instaui-echarts" to install it.'),)
|
149
|
+
from instaui_echarts import echarts # type: ignore
|
@@ -109,16 +109,12 @@ instaui/components/element.py,sha256=PYvIRFhfY3gh05vwj_TGB4Cknm8XtVzHwV1DN4gJ1V8
|
|
109
109
|
instaui/components/grid.py,sha256=h9Lzxqiw4HB-8VG2JGHVz-KGn4bHTtsibtUb8UCgHO4,7529
|
110
110
|
instaui/components/label.py,sha256=Fp7malMB2i6MjJjZnxdIl2tg6rb33-1PdgxEhGecoTM,118
|
111
111
|
instaui/components/match.py,sha256=B3wV1h-SkvYnX8RiMObdM2tfJb8nW2gjFxXQvNeZWWM,2774
|
112
|
-
instaui/components/mermaid.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
113
112
|
instaui/components/row.py,sha256=c0dxJwt955EF7PXlrFpqIoQNZ59tJm-UvZlx_zjeuBg,570
|
114
113
|
instaui/components/slot.py,sha256=RT0eU7wH7ffFDkl5ucfrNXB1nbsKDq688Hp920TZaoo,2287
|
115
114
|
instaui/components/transition_group.py,sha256=H9zx9NTlCoQnBArWfmxmh7CMKb5hZn8vKrFe4OFxPrE,201
|
116
115
|
instaui/components/value_element.py,sha256=wRIAaR3_Cq9qLNJw2KPhWt7dJmclj1mrttzlGpb01Y0,1412
|
117
116
|
instaui/components/vfor.py,sha256=A6hvCpmY-5oNZLnIs2yvfQ12C1-GggKVAthqhi5E4lY,4031
|
118
117
|
instaui/components/vif.py,sha256=2E62-8J9NIlZDhvgIOuDwz0tLLb6VoJ1ji1K4okrapw,1165
|
119
|
-
instaui/components/echarts/echarts.js,sha256=QJlvxMvgy6ZyyZ0hX3WC61z849rMyvWcfk9-L7zJVBs,2740
|
120
|
-
instaui/components/echarts/echarts.py,sha256=Up70IWBVLdW0_MZpV4GxM2-YFTe7u5ZWDoXHWaZVcEQ,5457
|
121
|
-
instaui/components/echarts/static/echarts.esm.min.js,sha256=KN8OVRa4kTlat9NIfArzA3rtGcYfyrkcwjFBy_07vu8,1033915
|
122
118
|
instaui/components/html/__init__.py,sha256=9bO1ai0aQCWwj80NKqDeq_3zwMg5gf17mE40a1IESAk,1088
|
123
119
|
instaui/components/html/_mixins.py,sha256=5dcSM9h1PswIKL6_eiqUxqW4H2OCuyNeCuRZq3gDGOc,876
|
124
120
|
instaui/components/html/_preset.py,sha256=c5rTj3r8W7UP0UHFLUW-ZSPedIa-gzrsU1goi60l20Q,94
|
@@ -164,6 +160,10 @@ instaui/event/vue_event.py,sha256=NRwEcAromivjyPtgMq5SEqHqx8GEc1OJZsRL2Nj43RY,21
|
|
164
160
|
instaui/event/web_event.py,sha256=sojugqfXyF0q4gDCQsVjcfdBcuELVGeucZveFTDno10,3607
|
165
161
|
instaui/experimental/__init__.py,sha256=nKvudMaBaDsxflSZQ00ck8Cc4hmrF0f6Xzs4mhIYa08,75
|
166
162
|
instaui/experimental/debug.py,sha256=UGUWgNZ3ShanpuxfuPdx52TgQrkO9hByABYMnPZEIiE,1325
|
163
|
+
instaui/extra_libs/_echarts.py,sha256=HCF4mxmzVyKRtxHuehiqf7kmBq7G14_dc2m9XQEM-fQ,78
|
164
|
+
instaui/extra_libs/_import_error.py,sha256=qwmDoCoGutqjQpVmvtH5iUkrtyuiTTPZXgEMZzYBAG4,294
|
165
|
+
instaui/extra_libs/_mermaid.py,sha256=2b0EymPyHUUBrNadvhK7lRtInh9K-7pzQJFZhj_WkNQ,89
|
166
|
+
instaui/extra_libs/_shiki_code.py,sha256=UTC7gvTF8BEgVerhkL45xwpZKY9tPN2_Ddbe0jxFYjQ,79
|
167
167
|
instaui/fastapi_server/_utils.py,sha256=MCqbebS4UkBOV8fp3Oy415Tvxnqi2mnMl5Eqe6yJogg,1177
|
168
168
|
instaui/fastapi_server/_uvicorn.py,sha256=n-es5ajWepXb6xF9EP0ft2lrEbsyLGWMUE7uVqpkUAs,1174
|
169
169
|
instaui/fastapi_server/debug_mode_router.py,sha256=EcYtPxI4FMnUqZcn-CZhZiMLgciHVNZpSRfiSIDRChc,1547
|
@@ -204,13 +204,13 @@ instaui/spa_router/_router_output.py,sha256=Nc6N8yO_9IrUbaYbPZMkOX_9VlwBKzyXMaha
|
|
204
204
|
instaui/spa_router/_router_param_var.py,sha256=KCy54xBZxGMqLO3Zlbzr6XV8ts-M6jCOKunL2gz5IUc,1455
|
205
205
|
instaui/spa_router/_types.py,sha256=KuGuv5C6qivwllfdmV5qrvM0S_GWJ6u8OOTkCNmJImU,81
|
206
206
|
instaui/spa_router/templates/page_routes,sha256=8VjM_8f6pjFb01QbU9z5HNqpcNRdCiX3X0OqNHLq8fo,1355
|
207
|
-
instaui/static/insta-ui.css,sha256=
|
208
|
-
instaui/static/insta-ui.esm-browser.prod.js,sha256=
|
207
|
+
instaui/static/insta-ui.css,sha256=nVwKBfzSg887seRBCa4tkHoj_02rrhZqwNJBdvstI8A,293
|
208
|
+
instaui/static/insta-ui.esm-browser.prod.js,sha256=oCWDu2L1d4SSNupZprQ0-Cg6DJorC4UeJNt00SHyyoU,109845
|
209
209
|
instaui/static/insta-ui.ico,sha256=08FJg4qWolvOjfodoh8IJLStslrvd8sDyuRcTUDq5ak,1150
|
210
210
|
instaui/static/insta-ui.js.map,sha256=PNEEw_xSUfYtFrnLZikz1-tMruQ-I31fniVaesyqTRY,663608
|
211
211
|
instaui/static/instaui-tools-browser.js,sha256=cLHKNXYaYMZriMxV-yKGAHTrHSdNRUlDVZmv6uc6mMw,14455
|
212
212
|
instaui/static/vue.esm-browser.prod.js,sha256=vwQkXANuVYQuEFc0VgiokJdhNyMmvxMKyb1FmrYrNb4,162662
|
213
|
-
instaui/static/vue.global.prod.js,sha256=
|
213
|
+
instaui/static/vue.global.prod.js,sha256=YO-UVLcXWjFOKfGU2uRrIMYpliGY2y48OmEjV464Z7M,157933
|
214
214
|
instaui/static/vue.runtime.esm-browser.prod.js,sha256=74FfP_s9pycfQXWAiGWx6SbjV_oJvMwZLFBkEXeW1Ek,102024
|
215
215
|
instaui/static/templates/web.html,sha256=E-CpEyAXV5E9X7CxkiJ8qy1IpudrCT8pQD4l1mFyAGU,1802
|
216
216
|
instaui/static/templates/webview.html,sha256=NMISXyV5289WNdJYqL40srYUtjF1bo0jkoE-ouDyrAc,1875
|
@@ -219,7 +219,7 @@ instaui/static/templates/debug/sse.html,sha256=qw5pzfjbU_XM-hA_SJCt2F8Imbvp17tW5
|
|
219
219
|
instaui/systems/file_system.py,sha256=q8k_mSHhldkSRYXT73T9s8zvERZZo9HL1U2-4mwau-I,163
|
220
220
|
instaui/systems/func_system.py,sha256=CER3Qm5luetdskMNVhJslvZK-QKbLe_n1aIGCe_i6Lc,3174
|
221
221
|
instaui/systems/js_system.py,sha256=t_r7SFPmfvTiIrxzuf1YgHyi_Oi_81W0UH_kkC5MwmM,685
|
222
|
-
instaui/systems/module_system.py,sha256=
|
222
|
+
instaui/systems/module_system.py,sha256=dtM7eWV0o5lYozQTXf4T0UycLdiT7wbq5uhJl9bjfn4,1552
|
223
223
|
instaui/systems/pydantic_system.py,sha256=qibHh4QqjLNPBzyrCkJVJwCk1dC_H8gEDYYf8Sb-5ps,691
|
224
224
|
instaui/systems/string_system.py,sha256=NzB7rgy7BZAYXAYDEWJQSvuYNui2TbLbrc9itVZGLmE,247
|
225
225
|
instaui/tailwind/__init__.py,sha256=HNexMZAMG2c0QtkX3oNXmpWnyWDuJPrxuq5IBGvcjVs,75
|
@@ -232,8 +232,8 @@ instaui/template/env.py,sha256=ZqVsqpfSY1mupbgpBSkvOJytNui8xfNR5kNNC9rv4Ps,150
|
|
232
232
|
instaui/template/web_template.py,sha256=BmZY13q4E_ZP4YVgfBKbbXvPHcGZfOl2f54wp_0DjJA,1603
|
233
233
|
instaui/template/webview_template.py,sha256=rd51iPi600QOPQ9PMjgYk61oIxn3L2p3_sJ3eBPG_24,1557
|
234
234
|
instaui/template/zero_template.py,sha256=E88VGsyjb1qbHFJlMW-xmLRFkwUXZA7VDoZ_Jd8YubA,3514
|
235
|
-
instaui/ui/__init__.py,sha256=
|
236
|
-
instaui/ui/__init__.pyi,sha256=
|
235
|
+
instaui/ui/__init__.py,sha256=4aHnUvEv-0UjpZNu5fU6hvcj1ZGlWwIIobabWUJk-Mc,4818
|
236
|
+
instaui/ui/__init__.pyi,sha256=VyyxCXkUhUe7V6lm23o0RYn8SFOE9Jm6aiRNqcCG3A4,4898
|
237
237
|
instaui/ui/events.py,sha256=lfhiINwn-Kh0MezsSeLJPttWm6G1aWiwyk3TRo0NrlA,809
|
238
238
|
instaui/ui_functions/input_slient_data.py,sha256=0A5DegIt_MqdZgbj1RiVFNmB_RUqgov9FYtkw6VX0DE,511
|
239
239
|
instaui/ui_functions/server.py,sha256=B4w8KwBUMGStY19uUG8E4vRG7-L4cedttLkh35xr698,357
|
@@ -277,7 +277,7 @@ instaui/webview/resource.py,sha256=kFT6N5UZK5GLE0KmW3TrEYDNlViw9DL2OshRh41wBXs,5
|
|
277
277
|
instaui/zero/__init__.py,sha256=N0LuRUAcaurxHSspcEDuwZg62W2S3qL4VtrMKxOivBE,49
|
278
278
|
instaui/zero/func.py,sha256=8cA_wJMtRmoAARjWY8yY5MmLXDAQ7hyVW6f1Vbejtoc,3576
|
279
279
|
instaui/zero/scope.py,sha256=HGohYOqnpRGVkkoz_gvR6-DgCc48AtJAcDwbOnnGHLM,3753
|
280
|
-
instaui-0.1.
|
281
|
-
instaui-0.1.
|
282
|
-
instaui-0.1.
|
283
|
-
instaui-0.1.
|
280
|
+
instaui-0.1.12.dist-info/METADATA,sha256=NDS9aCL1CfE0u6XGLL9Sdh2E19Ej2M6wfV0avDTKLRI,3591
|
281
|
+
instaui-0.1.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
282
|
+
instaui-0.1.12.dist-info/licenses/LICENSE,sha256=_JjnAWrikJ6qkwT7PazeFNRlcIu8q_RH3mYcHTxEF5c,1094
|
283
|
+
instaui-0.1.12.dist-info/RECORD,,
|
@@ -1,130 +0,0 @@
|
|
1
|
-
import { h, onMounted, shallowRef, watch } from "vue";
|
2
|
-
import * as echarts from 'echarts';
|
3
|
-
|
4
|
-
|
5
|
-
export default {
|
6
|
-
props: ['option', 'theme', 'initOptions', 'resizeOption', 'updateOptions', 'chartEvents', 'zrEvents'],
|
7
|
-
setup(props, { attrs, emit }) {
|
8
|
-
const root = shallowRef();
|
9
|
-
const chartIns = shallowRef();
|
10
|
-
|
11
|
-
onMounted(() => {
|
12
|
-
init(root, chartIns, props);
|
13
|
-
autoResize(root, chartIns, props);
|
14
|
-
|
15
|
-
setOption(root, chartIns, props);
|
16
|
-
setChartEvents(root, chartIns, emit, props);
|
17
|
-
})
|
18
|
-
|
19
|
-
watch(() => props.option, (newVal, oldVal) => {
|
20
|
-
|
21
|
-
setOption(root, chartIns, props);
|
22
|
-
|
23
|
-
}, { deep: true })
|
24
|
-
|
25
|
-
|
26
|
-
return () => {
|
27
|
-
return h("div", { ...attrs, ref: root })
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
function init(root, chartIns, props) {
|
35
|
-
if (!root.value) {
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
|
39
|
-
chartIns.value = echarts.init(
|
40
|
-
root.value,
|
41
|
-
props.theme,
|
42
|
-
props.initOptions,
|
43
|
-
)
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
function setOption(root, chartIns, props) {
|
48
|
-
if (!chartIns.value) {
|
49
|
-
init(root, chartIns, props);
|
50
|
-
} else {
|
51
|
-
chartIns.value.setOption(props.option || {}, props.updateOptions || {});
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
function autoResize(root, chartIns, props) {
|
57
|
-
|
58
|
-
watch(() => props.resizeOption, (resizeOption, _, onCleanup) => {
|
59
|
-
|
60
|
-
let ro = null;
|
61
|
-
|
62
|
-
if (resizeOption) {
|
63
|
-
const { offsetWidth, offsetHeight } = root.value;
|
64
|
-
const { throttle = 100 } = resizeOption;
|
65
|
-
|
66
|
-
let isInitialResize = false;
|
67
|
-
const callback = () => {
|
68
|
-
chartIns.value.resize()
|
69
|
-
}
|
70
|
-
const resizeCallback = throttle ? echarts.throttle(callback, throttle) : callback;
|
71
|
-
|
72
|
-
ro = new ResizeObserver(() => {
|
73
|
-
|
74
|
-
if (!isInitialResize) {
|
75
|
-
isInitialResize = true;
|
76
|
-
if (
|
77
|
-
root.value.offsetWidth === offsetWidth &&
|
78
|
-
root.value.offsetHeight === offsetHeight
|
79
|
-
) {
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
resizeCallback();
|
84
|
-
})
|
85
|
-
|
86
|
-
ro.observe(root.value);
|
87
|
-
}
|
88
|
-
|
89
|
-
onCleanup(() => {
|
90
|
-
if (ro) {
|
91
|
-
ro.disconnect();
|
92
|
-
ro = null;
|
93
|
-
}
|
94
|
-
});
|
95
|
-
|
96
|
-
}, { deep: true, immediate: true })
|
97
|
-
|
98
|
-
}
|
99
|
-
|
100
|
-
|
101
|
-
function setChartEvents(root, chartIns, emit, props) {
|
102
|
-
|
103
|
-
const { chartEvents, zrEvents } = props;
|
104
|
-
|
105
|
-
if (chartEvents) {
|
106
|
-
chartEvents.forEach(event => {
|
107
|
-
chartIns.value.on(event, (...args) => {
|
108
|
-
if (args.length > 0) {
|
109
|
-
const eventArgs = args[0]
|
110
|
-
delete eventArgs['event']
|
111
|
-
delete eventArgs['$vars']
|
112
|
-
}
|
113
|
-
|
114
|
-
emit(`chart:${event}`, ...args)
|
115
|
-
});
|
116
|
-
})
|
117
|
-
}
|
118
|
-
|
119
|
-
if (zrEvents) {
|
120
|
-
zrEvents.forEach(event => {
|
121
|
-
chartIns.value.getZr().on(event, (...args) => emit(`zr:${event}`, ...args));
|
122
|
-
})
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
}
|
130
|
-
|
@@ -1,194 +0,0 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
from typing import Dict, Literal, Optional, Set, Union
|
3
|
-
from typing_extensions import TypedDict
|
4
|
-
from instaui import ui
|
5
|
-
from instaui.event.event_mixin import EventMixin
|
6
|
-
|
7
|
-
_STATIC_DIR = Path(__file__).parent / "static"
|
8
|
-
_ECHARTS_JS_FILE = _STATIC_DIR / "echarts.esm.min.js"
|
9
|
-
|
10
|
-
|
11
|
-
_IMPORT_MAPS = {
|
12
|
-
"echarts": _ECHARTS_JS_FILE,
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
TEChartsEvent = Literal[
|
17
|
-
"highlight",
|
18
|
-
"downplay",
|
19
|
-
"selectchanged",
|
20
|
-
"legendselectchanged",
|
21
|
-
"legendselected",
|
22
|
-
"legendunselected",
|
23
|
-
"legendselectall",
|
24
|
-
"legendinverseselect",
|
25
|
-
"legendscroll",
|
26
|
-
"datazoom",
|
27
|
-
"datarangeselected",
|
28
|
-
"timelinechanged",
|
29
|
-
"timelineplaychanged",
|
30
|
-
"restore",
|
31
|
-
"dataviewchanged",
|
32
|
-
"magictypechanged",
|
33
|
-
"geoselectchanged",
|
34
|
-
"geoselected",
|
35
|
-
"geounselected",
|
36
|
-
"axisareaselected",
|
37
|
-
"brush",
|
38
|
-
"brushEnd",
|
39
|
-
"brushselected",
|
40
|
-
"globalcursortaken",
|
41
|
-
"rendered",
|
42
|
-
"finished",
|
43
|
-
"click",
|
44
|
-
"dblclick",
|
45
|
-
"mouseover",
|
46
|
-
"mouseout",
|
47
|
-
"mousemove",
|
48
|
-
"mousedown",
|
49
|
-
"mouseup",
|
50
|
-
"globalout",
|
51
|
-
"contextmenu",
|
52
|
-
]
|
53
|
-
|
54
|
-
|
55
|
-
TZRenderEvent = Literal[
|
56
|
-
"click", "mousedown", "mouseup", "mousewheel", "dblclick", "contextmenu"
|
57
|
-
]
|
58
|
-
|
59
|
-
|
60
|
-
class TResizeOptions(TypedDict, total=False):
|
61
|
-
throttle: int
|
62
|
-
|
63
|
-
|
64
|
-
class TInitOptions(TypedDict, total=False):
|
65
|
-
devicePixelRatio: int
|
66
|
-
renderer: Literal["canvas", "svg"]
|
67
|
-
width: Union[int, str]
|
68
|
-
height: Union[int, str]
|
69
|
-
locale: str
|
70
|
-
pointerSize: int
|
71
|
-
|
72
|
-
|
73
|
-
class ECharts(
|
74
|
-
ui.element,
|
75
|
-
esm="./echarts.js",
|
76
|
-
externals=_IMPORT_MAPS,
|
77
|
-
):
|
78
|
-
"""ECharts component
|
79
|
-
|
80
|
-
Example usage:
|
81
|
-
.. code-block:: python
|
82
|
-
|
83
|
-
opts = {
|
84
|
-
"title": {"text": "ECharts Getting Started Example"},
|
85
|
-
"tooltip": {},
|
86
|
-
"legend": {"data": ["sales"]},
|
87
|
-
"xAxis": {
|
88
|
-
"data": ["Shirts", "Cardigans", "Chiffons", "Pants", "Heels", "Socks"]
|
89
|
-
},
|
90
|
-
"yAxis": {},
|
91
|
-
"series": [{"name": "sales", "type": "bar", "data": [5, 20, 36, 10, 10, 20]}],
|
92
|
-
}
|
93
|
-
|
94
|
-
ui.echarts(opts)
|
95
|
-
|
96
|
-
"""
|
97
|
-
|
98
|
-
def __init__(
|
99
|
-
self,
|
100
|
-
option: ui.TMaybeRef[Dict],
|
101
|
-
*,
|
102
|
-
theme: Optional[Union[Path, str, Dict]] = None,
|
103
|
-
init_options: Optional[TInitOptions] = None,
|
104
|
-
update_options: Optional[Dict] = None,
|
105
|
-
resize_options: Optional[TResizeOptions] = None,
|
106
|
-
):
|
107
|
-
"""Create an ECharts component
|
108
|
-
|
109
|
-
Args:
|
110
|
-
option (ui.TMaybeRef[Dict]): Chart option.
|
111
|
-
theme (Optional[Union[Path, str, Dict]], optional): Theme file or object. Defaults to None.
|
112
|
-
init_options (Optional[TInitOptions], optional): Chart initialization options. Defaults to None.
|
113
|
-
update_options (Optional[Dict], optional): Chart update options. Defaults to None.
|
114
|
-
resize_options (Optional[TResizeOptions], optional): Chart resize options. Defaults to None.
|
115
|
-
|
116
|
-
Example usage:
|
117
|
-
|
118
|
-
resize_options:
|
119
|
-
|
120
|
-
.. code-block:: python
|
121
|
-
ui.echarts(opts, resize_options={"throttle": 100})
|
122
|
-
|
123
|
-
chart event:
|
124
|
-
.. code-block:: python
|
125
|
-
opts = ui.state(
|
126
|
-
{
|
127
|
-
"title": {"text": "ECharts Getting Started Example"},
|
128
|
-
"tooltip": {},
|
129
|
-
"legend": {"data": ["sales"]},
|
130
|
-
"xAxis": {
|
131
|
-
"data": ["Shirts", "Cardigans", "Chiffons", "Pants", "Heels", "Socks"]
|
132
|
-
},
|
133
|
-
"yAxis": {},
|
134
|
-
"series": [
|
135
|
-
{"name": "sales", "type": "bar", "data": [5, 20, 36, 10, 10, 20]}
|
136
|
-
],
|
137
|
-
}
|
138
|
-
)
|
139
|
-
|
140
|
-
msg = ui.state("Click the bars in the chart.")
|
141
|
-
|
142
|
-
@ui.event(inputs=[ui.event_context.e()], outputs=[msg])
|
143
|
-
def click(arg):
|
144
|
-
return f'You clicked on "{arg["name"]}"'
|
145
|
-
|
146
|
-
ui.content(msg)
|
147
|
-
ui.echarts(opts).on_chart("click", click)
|
148
|
-
|
149
|
-
"""
|
150
|
-
|
151
|
-
super().__init__()
|
152
|
-
self._chart_events: Set[str] = set()
|
153
|
-
self._zr_events: Set[str] = set()
|
154
|
-
self.props({"option": option})
|
155
|
-
|
156
|
-
if init_options is not None:
|
157
|
-
self.props({"initOptions": init_options})
|
158
|
-
|
159
|
-
if update_options:
|
160
|
-
self.props({"updateOptions": update_options})
|
161
|
-
|
162
|
-
if theme:
|
163
|
-
if isinstance(theme, (str, Path)):
|
164
|
-
raise NotImplementedError("Theme file not supported yet")
|
165
|
-
else:
|
166
|
-
self.props({"theme": theme})
|
167
|
-
|
168
|
-
self.props({"resizeOption": resize_options or {}})
|
169
|
-
|
170
|
-
self.style("width: 100%; height: 100%;min-width:0;")
|
171
|
-
|
172
|
-
def on_chart(
|
173
|
-
self,
|
174
|
-
event_name: TEChartsEvent,
|
175
|
-
handler: EventMixin,
|
176
|
-
):
|
177
|
-
self._chart_events.add(event_name)
|
178
|
-
return self.on(f"chart:{event_name}", handler)
|
179
|
-
|
180
|
-
def on_zr(self, event_name: TZRenderEvent, handler: EventMixin):
|
181
|
-
self._zr_events.add(event_name)
|
182
|
-
return self.on(f"zr:{event_name}", handler)
|
183
|
-
|
184
|
-
def _to_json_dict(self):
|
185
|
-
data = super()._to_json_dict()
|
186
|
-
props = data.get("props", {})
|
187
|
-
|
188
|
-
if self._chart_events:
|
189
|
-
props["chartEvents"] = list(self._chart_events)
|
190
|
-
|
191
|
-
if self._zr_events:
|
192
|
-
props["zrEvents"] = list(self._zr_events)
|
193
|
-
|
194
|
-
return data
|