Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix pie chart label not visible on dark theme (#67639)

Mahatthana (Kelvin) Nomsawadi112d1d0235ce
diff --git a/.loki/reference/chrome_laptop_viz_PieChart_Dark_Theme.png b/.loki/reference/chrome_laptop_viz_PieChart_Dark_Theme.png
new file mode 100644
index 00000000000..e54326356fe
Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_PieChart_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_viz_PieChart_Embedded_Dashcard.png b/.loki/reference/chrome_laptop_viz_PieChart_Embedded_Dashcard.png
new file mode 100644
index 00000000000..1e5abdccdf2
Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_PieChart_Embedded_Dashcard.png differ
diff --git a/.loki/reference/chrome_laptop_viz_PieChart_Embedded_Question.png b/.loki/reference/chrome_laptop_viz_PieChart_Embedded_Question.png
new file mode 100644
index 00000000000..cbc83acce78
Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_PieChart_Embedded_Question.png differ
diff --git a/frontend/src/metabase/common/hooks/use-palette.ts b/frontend/src/metabase/common/hooks/use-palette.ts
index 06cfae670d4..c7531fa4416 100644
--- a/frontend/src/metabase/common/hooks/use-palette.ts
+++ b/frontend/src/metabase/common/hooks/use-palette.ts
@@ -2,25 +2,17 @@ import { useMemo } from "react";
import type { ColorPalette } from "metabase/lib/colors/types";
import { useMantineTheme } from "metabase/ui";
+import { ALL_COLOR_NAMES } from "metabase/ui/utils/colors";
/**
- * Extracts a color palette from a subset of colors in the Mantine theme.
- *
* Allows palettes to be overridden by the user, primarily via the React embedding SDK.
*/
export function usePalette(): ColorPalette {
const theme = useMantineTheme();
return useMemo(() => {
- return {
- white: theme.fn.themeColor("white"),
- border: theme.fn.themeColor("border"),
- "text-dark": theme.fn.themeColor("text-dark"),
- "text-medium": theme.fn.themeColor("text-medium"),
- "text-light": theme.fn.themeColor("text-light"),
- "text-white": theme.fn.themeColor("text-white"),
- "text-primary": theme.fn.themeColor("text-primary"),
- "bg-white": theme.fn.themeColor("bg-white"),
- };
+ return Object.fromEntries(
+ ALL_COLOR_NAMES.map((name) => [name, theme.fn.themeColor(name)]),
+ );
}, [theme]);
}
diff --git a/frontend/src/metabase/styled-components/theme/css-variables.ts b/frontend/src/metabase/styled-components/theme/css-variables.ts
index c1933b45155..049a11c31d6 100644
--- a/frontend/src/metabase/styled-components/theme/css-variables.ts
+++ b/frontend/src/metabase/styled-components/theme/css-variables.ts
@@ -26,7 +26,6 @@ export function getMetabaseCssVariables(theme: MantineTheme) {
return css`
:root {
- --mb-default-font-family: "${theme.fontFamily}";
--mb-default-monospace-font-family: ${theme.fontFamilyMonospace};
/* Semantic colors */
diff --git a/frontend/src/metabase/ui/utils/colors.ts b/frontend/src/metabase/ui/utils/colors.ts
index ad32d4d90fe..f6eb1d738a5 100644
--- a/frontend/src/metabase/ui/utils/colors.ts
+++ b/frontend/src/metabase/ui/utils/colors.ts
@@ -4,7 +4,7 @@ import { colorConfig } from "metabase/lib/colors";
import type { ColorName } from "metabase/lib/colors/types";
type ColorShades = MantineTheme["colors"]["dark"];
-const allColorNames = Object.keys(colorConfig);
+export const ALL_COLOR_NAMES = Object.keys(colorConfig);
const ORIGINAL_COLORS = [
"dark",
@@ -65,7 +65,7 @@ export function color(colorName: ColorName): string {
}
export const isColorName = (name?: string | null): name is ColorName => {
- return !!name && allColorNames.includes(name);
+ return !!name && ALL_COLOR_NAMES.includes(name);
};
/**
diff --git a/frontend/src/metabase/visualizations/visualizations/PieChart/PieChart.stories.tsx b/frontend/src/metabase/visualizations/visualizations/PieChart/PieChart.stories.tsx
index 2b3a9b745d1..440ff4efa8d 100644
--- a/frontend/src/metabase/visualizations/visualizations/PieChart/PieChart.stories.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/PieChart/PieChart.stories.tsx
@@ -70,11 +70,6 @@ export const EmbeddedQuestion = {
isDashboard: false,
backgroundColor: "#ebe6e2",
},
-
- parameters: {
- // TODO unskip this and the next story once rendering delay is completely gone.
- loki: { skip: true },
- },
};
export const EmbeddedDashcard = {
@@ -84,12 +79,16 @@ export const EmbeddedDashcard = {
isDashboard: true,
backgroundColor: "#dee9e9",
},
-
- parameters: {
- loki: { skip: true },
- },
};
+export const DarkTheme: StoryFn = () => (
+ <VisualizationWrapper displayTheme="dark">
+ <Box h={500}>
+ <Visualization rawSeries={data.defaultSettings as unknown as Series} />
+ </Box>
+ </VisualizationWrapper>
+);
+
export const Watermark: StoryFn = () => (
<VisualizationWrapper
initialStore={createMockState({
diff --git a/frontend/test/__support__/storybook.tsx b/frontend/test/__support__/storybook.tsx
index ab1a1dfb02c..b998c1235c7 100644
--- a/frontend/test/__support__/storybook.tsx
+++ b/frontend/test/__support__/storybook.tsx
@@ -34,11 +34,13 @@ export const ReduxProvider = ({
export const VisualizationWrapper = ({
theme,
+ displayTheme,
children,
initialStore = createMockState(),
}: {
children: React.ReactElement;
theme?: MantineThemeOverride;
+ displayTheme?: "light" | "dark";
initialStore?: State;
}) => {
const store = getStore(mainReducers, initialStore);
@@ -49,6 +51,7 @@ export const VisualizationWrapper = ({
withRouter={false}
withKBar={false}
theme={theme}
+ displayTheme={displayTheme}
withDND
withCssVariables
>
diff --git a/frontend/test/__support__/ui.tsx b/frontend/test/__support__/ui.tsx
index eb7f2049a4e..df56abb1731 100644
--- a/frontend/test/__support__/ui.tsx
+++ b/frontend/test/__support__/ui.tsx
@@ -12,6 +12,7 @@ import type { History } from "history";
import { createMemoryHistory } from "history";
import { KBarProvider } from "kbar";
import type * as React from "react";
+import { useMemo } from "react";
import { DragDropContextProvider } from "react-dnd";
import HTML5Backend from "react-dnd-html5-backend";
import { Route, useRouterHistory } from "react-router";
@@ -26,8 +27,9 @@ import { MetabaseReduxProvider } from "metabase/lib/redux";
import { makeMainReducers } from "metabase/reducers-main";
import { publicReducers } from "metabase/reducers-public";
import { RouterProvider } from "metabase/router";
+import { getMetabaseCssVariables } from "metabase/styled-components/theme/css-variables";
import type { MantineThemeOverride } from "metabase/ui";
-import { ThemeProvider } from "metabase/ui";
+import { ThemeProvider, useMantineTheme } from "metabase/ui";
import { ThemeProviderContext } from "metabase/ui/components/theme/ThemeProvider/context";
import type { State } from "metabase-types/store";
import { createMockState } from "metabase-types/store/mocks";
@@ -222,9 +224,13 @@ export function getTestStoreAndWrapper({
/**
* A minimal version of the GlobalStyles component, for use in Storybook stories.
- * Contains strictly only the base styles to act as CSS resets, without font files.
+ * Contains strictly only the base styles to act as CSS resets and css variables, without font files.
**/
-const GlobalStylesForTest = () => <Global styles={baseStyle} />;
+const GlobalStylesForTest = () => {
+ const theme = useMantineTheme();
+ const cssVariables = useMemo(() => getMetabaseCssVariables(theme), [theme]);
+ return <Global styles={[baseStyle, cssVariables]} />;
+};
export function TestWrapper({
children,
@@ -235,6 +241,7 @@ export function TestWrapper({
withDND,
withUndos,
theme,
+ displayTheme,
withCssVariables = false,
}: {
children: React.ReactElement;
@@ -245,13 +252,14 @@ export function TestWrapper({
withDND: boolean;
withUndos?: boolean;
theme?: MantineThemeOverride;
+ displayTheme?: "light" | "dark";
withCssVariables?: boolean;
}): JSX.Element {
return (
<MetabaseReduxProvider store={store}>
<MaybeDNDProvider hasDND={withDND}>
<ThemeProviderContext.Provider value={{ withCssVariables }}>
- <ThemeProvider theme={theme}>
+ <ThemeProvider theme={theme} displayTheme={displayTheme}>
<GlobalStylesForTest />
<MaybeKBar hasKBar={withKBar}>