Skip to content

Commit

Permalink
switch to dark echarts theme if dark mode is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgerstmayr committed Nov 23, 2024
1 parent 9240212 commit f2bc7cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion frontend/src/panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export async function echarts(ctx: PanelCtx, elem: HTMLDivElement) {
}

const renderer = window.navigator.userAgent === "puppeteer" ? "svg" : undefined;
const chart = echartslib.init(elem, undefined, { renderer });
const isDarkMode = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
const theme = isDarkMode ? "dark" : undefined;
const chart = echartslib.init(elem, theme, { renderer });
if (options.onClick) {
chart.on("click", (options as any).onClick);
delete options.onClick;
Expand All @@ -47,6 +49,9 @@ export async function echarts(ctx: PanelCtx, elem: HTMLDivElement) {
chart.on("dblclick", (options as any).onDblClick);
delete options.onDblClick;
}
if (theme === "dark" && options.backgroundColor === undefined) {
options.backgroundColor = "transparent";
}
chart.setOption(options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/fava_dashboards/FavaDashboards.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/fava_dashboards/templates/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
text-align: center;
}
#dashboard a {
color: #333;
color: #333; /* --heading-color from fava */
}

/* set panel min-width to 100% on screens < 802px (navbar + padding + 2*300px) */
Expand All @@ -20,8 +20,9 @@
min-width: 100%;
}
}

@media (prefers-color-scheme: dark) {
#dashboard a{
color: #ccc !important
#dashboard a {
color: #d7dce2; /* --heading-color from fava */
}
}

0 comments on commit f2bc7cc

Please sign in to comment.