Skip to content

Commit 42081e2

Browse files
committed
更新
1 parent 526bffa commit 42081e2

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

chartspy/charts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def json_type_convert(o: object):
248248
return json_encoder.default(o)
249249

250250

251-
ECHARTS_JS_URL = "https://cdn.staticfile.org/echarts/5.3.2/echarts.min.js"
251+
ECHARTS_JS_URL = "https://cdn.staticfile.org/echarts/5.4.3/echarts.min.js"
252252
ECHARTS_GL_JS_URL = "https://cdn.staticfile.org/echarts-gl/2.0.8/echarts-gl.min.js"
253253

254254

chartspy/g2plot.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ def render_notebook(self) -> Html:
8787
var plot_{plot.plot_id} = new G2Plot.{plot.plot_type}("{plot.plot_id}", {plot.js_options})
8888
plot_{plot.plot_id}.render();
8989
}});
90+
// 确保DOM加载完成后再初始化
91+
if (document.readyState === 'loading') {{
92+
document.addEventListener('DOMContentLoaded', function() {{
93+
require(['G2Plot'], function (G2Plot) {{
94+
var plot_{plot.plot_id} = new G2Plot.{plot.plot_type}("{plot.plot_id}", {plot.js_options})
95+
plot_{plot.plot_id}.render();
96+
}});
97+
}});
98+
}} else {{
99+
require(['G2Plot'], function (G2Plot) {{
100+
var plot_{plot.plot_id} = new G2Plot.{plot.plot_type}("{plot.plot_id}", {plot.js_options})
101+
plot_{plot.plot_id}.render();
102+
}});
103+
}}
90104
</script>
91105
"""
92106

@@ -111,16 +125,25 @@ def render_jupyterlab(self) -> Html:
111125
// load javascript
112126
113127
{plot.extra_js}
114-
new Promise(function(resolve, reject) {{
115-
var script = document.createElement("script");
116-
script.onload = resolve;
117-
script.onerror = reject;
118-
script.src = "{plot.js_url}";
119-
document.head.appendChild(script);
120-
}}).then(() => {{
121-
var plot_{plot.plot_id} = new G2Plot.{plot.plot_type}("{plot.plot_id}", {plot.js_options})
122-
plot_{plot.plot_id}.render();
123-
}});
128+
function initChart_{plot.plot_id}() {{
129+
new Promise(function(resolve, reject) {{
130+
var script = document.createElement("script");
131+
script.onload = resolve;
132+
script.onerror = reject;
133+
script.src = "{plot.js_url}";
134+
document.head.appendChild(script);
135+
}}).then(() => {{
136+
var plot_{plot.plot_id} = new G2Plot.{plot.plot_type}("{plot.plot_id}", {plot.js_options})
137+
plot_{plot.plot_id}.render();
138+
}});
139+
}}
140+
141+
// 确保DOM加载完成后再初始化
142+
if (document.readyState === 'loading') {{
143+
document.addEventListener('DOMContentLoaded', initChart_{plot.plot_id});
144+
}} else {{
145+
initChart_{plot.plot_id}();
146+
}}
124147
</script>
125148
"""
126149
return Html(html)

0 commit comments

Comments
 (0)