Skip to content

Commit

Permalink
feat: Make all texts dark-grey in PNGs
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 4, 2024
1 parent 246bf0c commit 59e2be3
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions app/components/chart-shared.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { t, Trans } from "@lingui/macro";
import { Box, IconButton, Theme, useEventCallback } from "@mui/material";
import {
Box,
IconButton,
Theme,
useEventCallback,
useTheme,
} from "@mui/material";
import { makeStyles } from "@mui/styles";
import { ComponentProps, useEffect, useState } from "react";
import { select } from "d3-selection";
import {
ComponentProps,
useCallback,
useEffect,
useMemo,

Check failure on line 15 in app/components/chart-shared.tsx

View workflow job for this annotation

GitHub Actions / lint-typecheck-test

'useMemo' is declared but its value is never read.
useState,
} from "react";

import {
ChartDataFiltersList,
Expand Down Expand Up @@ -125,6 +138,7 @@ export const ChartMoreButton = ({
chartKey: string;
chartWrapperNode?: HTMLElement | null;
}) => {
const theme = useTheme();
const [state, dispatch] = useConfiguratorState(hasChartConfigs);
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
const handleClose = useEventCallback(() => setAnchor(null));
Expand All @@ -141,6 +155,19 @@ export const ChartMoreButton = ({
state.layout.type === "dashboard" &&
chartConfig.chartType === "table";

const modifyNode = useCallback(
(node: HTMLElement) => {
// Every text element should be dark-grey (currently we use primary.main to
// indicate interactive elements, which doesn't make sense for screenshots).
const color = theme.palette.grey[700];
select(node).selectAll("*").style("color", color);
// SVG elements have fill instead of color. Here we only target text elements,
// to avoid changing the color of other SVG elements (charts).
select(node).selectAll("text").style("fill", color);
},
[theme.palette.grey]
);

return disableButton ? null : (
<>
<IconButton
Expand Down Expand Up @@ -170,6 +197,7 @@ export const ChartMoreButton = ({
type="png"
screenshotName={chartKey}
screenshotNode={chartWrapperNode}
modifyNode={modifyNode}
/>
</>
) : null}
Expand Down Expand Up @@ -208,6 +236,7 @@ export const ChartMoreButton = ({
type="png"
screenshotName={chartKey}
screenshotNode={chartWrapperNode}
modifyNode={modifyNode}
/>
</>
) : null}
Expand Down

0 comments on commit 59e2be3

Please sign in to comment.