Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Refresh ECharts after appearance mode changes https://github.com/siyuan-note/siyuan/issues/19013

Danielc24518005aea
diff --git a/app/src/protyle/render/chartRender.ts b/app/src/protyle/render/chartRender.ts
index fa566cc03d..d08757cf45 100644
--- a/app/src/protyle/render/chartRender.ts
+++ b/app/src/protyle/render/chartRender.ts
@@ -54,3 +54,26 @@ export const chartRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
});
});
};
+
+export const refreshChartTheme = (element: Element) => {
+ if (typeof window.echarts === "undefined") {
+ return;
+ }
+ let echartsElements: HTMLElement[] | NodeListOf<HTMLElement> = [];
+ if (element.matches('[data-subtype="echarts"]')) {
+ echartsElements = [element as HTMLElement];
+ } else {
+ echartsElements = element.querySelectorAll<HTMLElement>('[data-subtype="echarts"]');
+ }
+ const refreshElements: HTMLElement[] = [];
+ echartsElements.forEach((item) => {
+ const chartElement = item.querySelector<HTMLElement>("[_echarts_instance_]");
+ if (!chartElement) {
+ return;
+ }
+ window.echarts.dispose(chartElement);
+ item.removeAttribute("data-render");
+ refreshElements.push(item);
+ });
+ refreshElements.forEach(item => chartRender(item));
+};
diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts
index e95c91c1f1..9ad6a458e1 100644
--- a/app/src/util/assets.ts
+++ b/app/src/util/assets.ts
@@ -27,6 +27,7 @@ import {
getInlineStylesCSS,
loadInlineStyles
} from "../protyle/toolbar/inlineStyle";
+import {refreshChartTheme} from "../protyle/render/chartRender";
let headingNumberMeasurementRefreshTimer: number;
const DEJAVU_EMOJI_PRESENTATION_UNICODE_RANGE = "U+25fd-25fe, U+2614-2615, U+2648-2653, U+267f, U+2693, U+26a1, " +
@@ -96,10 +97,12 @@ export const loadAssets = (data: Config.IAppearance) => {
const changedThemeStyleElements: HTMLLinkElement[] = [];
let themeStylesChanged = false;
const htmlElement = document.getElementsByTagName("html")[0];
+ const previousThemeMode = htmlElement.getAttribute("data-theme-mode");
+ const themeMode = getThemeMode();
htmlElement.setAttribute("lang", window.siyuan.config.appearance.lang);
htmlElement.setAttribute("data-frontend", getFrontend()); // https://github.com/siyuan-note/siyuan/issues/12549
htmlElement.setAttribute("data-backend", getBackend());
- htmlElement.setAttribute("data-theme-mode", getThemeMode());
+ htmlElement.setAttribute("data-theme-mode", themeMode);
htmlElement.setAttribute("data-light-theme", window.siyuan.config.appearance.themeLight);
htmlElement.setAttribute("data-dark-theme", window.siyuan.config.appearance.themeDark);
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
@@ -110,6 +113,9 @@ export const loadAssets = (data: Config.IAppearance) => {
fetchPost("/api/system/setAppearanceMode", {mode: OSTheme === "light" ? 0 : 1});
window.siyuan.config.appearance.mode = (OSTheme === "light" ? 0 : 1);
}
+ if (previousThemeMode && previousThemeMode !== themeMode) {
+ refreshChartTheme(document.body);
+ }
const defaultStyleElement = document.getElementById("themeDefaultStyle");
const defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;
if (defaultStyleElement) {