Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: painter webgl renderer background color (#326)

islxyqwea7976553ca73
diff --git a/packages/graphic-walker/src/components/painter/index.tsx b/packages/graphic-walker/src/components/painter/index.tsx
index 5268c166..34305a05 100644
--- a/packages/graphic-walker/src/components/painter/index.tsx
+++ b/packages/graphic-walker/src/components/painter/index.tsx
@@ -21,8 +21,9 @@ import { Button } from '../ui/button';
import { Dialog, DialogContent } from '../ui/dialog';
import { Slider } from '../ui/slider';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '../ui/tabs';
-import { themeContext } from '@/store/theme';
+import { colorContext, themeContext } from '@/store/theme';
import { WebGLRenderer } from 'vega-webgl-renderer';
+import { parseColorToHex } from '@/utils/colors';
//@ts-ignore
CanvasHandler.prototype.context = function () {
@@ -611,15 +612,16 @@ const Painter = ({ themeConfig, themeKey }: { themeConfig?: GWGlobalConfig; them
}, []);
const mediaTheme = useContext(themeContext);
+ const colorConfig = useContext(colorContext);
const vegaConfig = useMemo<VegaGlobalConfig>(() => {
const presetConfig = themeConfig ?? builtInThemes[themeKey ?? 'vega'];
const config: VegaGlobalConfig = {
...presetConfig?.[mediaTheme],
- background: 'transparent',
+ background: parseColorToHex(colorConfig[mediaTheme].background),
};
return config;
- }, [themeConfig, themeKey, mediaTheme]);
+ }, [colorConfig, themeConfig, themeKey, mediaTheme]);
return (
<Dialog
diff --git a/packages/graphic-walker/src/utils/colors.ts b/packages/graphic-walker/src/utils/colors.ts
index 0c41b316..a640901d 100644
--- a/packages/graphic-walker/src/utils/colors.ts
+++ b/packages/graphic-walker/src/utils/colors.ts
@@ -1,6 +1,7 @@
import { IColorConfig, IColorPalette, IColorSet } from '../interfaces';
import colorString from 'color-string';
import rgb from 'color-space/rgb.js';
+import hsl from 'color-space/hsl.js';
import hwb from 'color-space/hwb.js';
import colors from 'tailwindcss/colors';
@@ -36,6 +37,10 @@ export function parseColorToHSL(color: string) {
return `${h} ${s}% ${l}%`;
}
+export function parseColorToHex(color: string) {
+ return colorString.to.hex(hsl.rgb(toHSL(color)));
+}
+
function ColorSetToCss(set: Required<IColorSet>) {
return Object.entries(set)
.map(([name, value]) => `--${name}:${parseColorToHSL(value)};`)