Vanessa 2025-03-06 11:30:54 +08:00
parent 8b69979fba
commit a742bd49a6
2 changed files with 12 additions and 6 deletions

View File

@ -32,16 +32,20 @@ export const chartRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
}
const renderElement = e.firstElementChild.nextElementSibling as HTMLElement;
try {
window.echarts.dispose(renderElement);
const chartInstance = window.echarts.getInstanceById(renderElement.getAttribute("_echarts_instance_"))
const option = await looseJsonParse(Lute.UnEscapeHTMLStr(e.getAttribute("data-content")));
if (chartInstance && chartInstance.getOption().series[0]?.type !== option.series[0]?.type) {
chartInstance.clear();
}
renderElement.classList.remove("ft__error");
renderElement.style.height = e.style.height;
const option = await looseJsonParse(Lute.UnEscapeHTMLStr(e.getAttribute("data-content")));
window.echarts.init(renderElement, window.siyuan.config.appearance.mode === 1 ? "dark" : undefined, {width}).setOption(option);
e.setAttribute("data-render", "true");
if (!renderElement.textContent.endsWith(Constants.ZWSP)) {
renderElement.firstElementChild.insertAdjacentText("beforeend", Constants.ZWSP);
}
} catch (error) {
window.echarts.dispose(renderElement);
renderElement.classList.add("ft__error");
renderElement.innerHTML = `echarts render error: <br>${error}`;
}

View File

@ -138,6 +138,8 @@ interface Window {
dispose(element: Element): void;
getInstanceById(id: string): {
resize: () => void
clear: () => void
getOption: () => { series: { type: string }[] }
};
}
ABCJS: {