Skip to content

Commit

Permalink
fix plot image in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
plmrry committed Feb 13, 2024
1 parent 7f9ebbb commit ec78b73
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion flatfront/src/components/DownloadPlotButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { toPng } from "html-to-image";
import { Button } from "./ui/button";
import { useIsDarkMode } from "./DarkModeToggle";

export function DownloadPlotButton({
plotRef: ref,
Expand All @@ -9,14 +10,15 @@ export function DownloadPlotButton({
plotRef: React.RefObject<HTMLDivElement>;
imageName: string;
}) {
const is_dark_mode = useIsDarkMode();
const on_click = React.useCallback(() => {
if (ref.current === null) {
return;
}
toPng(ref.current, {
pixelRatio: 2,
cacheBust: true,
backgroundColor: `white`
backgroundColor: is_dark_mode ? `black` : `white`
})
.then((dataUrl) => {
const link = document.createElement("a");
Expand Down

0 comments on commit ec78b73

Please sign in to comment.