Skip to content

Commit 18ad284

Browse files
committed
fix: fixed color palette usecase
1 parent 7ce9e3a commit 18ad284

File tree

7 files changed

+51
-37
lines changed

7 files changed

+51
-37
lines changed

Diff for: src/components/charts-generic/histogram/histogram-state.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
useFormatCurrency,
2626
} from "src/domain/helpers";
2727
import { estimateTextWidth } from "src/lib/estimate-text-width";
28+
import { chartPalette } from "src/themes/palette";
2829

2930
const useHistogramState = ({
3031
data,
@@ -72,7 +73,7 @@ const useHistogramState = ({
7273

7374
const colors = scaleLinear<string>()
7475
.domain(colorDomain)
75-
.range(palette.diverging)
76+
.range(chartPalette.diverging.GO)
7677
.interpolate(interpolateHsl);
7778
// y
7879
const bins = bin<GenericObservation, number>()

Diff for: src/components/charts-generic/rangeplot/rangeplot-state.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from "src/domain/helpers";
3535
import { minMaxBy } from "src/lib/array";
3636
import { estimateTextWidth } from "src/lib/estimate-text-width";
37+
import { chartPalette } from "src/themes/palette";
3738

3839
export const DOT_RADIUS = 8;
3940
const OUTER_PADDING = 0.2;
@@ -98,7 +99,7 @@ const useRangePlotState = ({
9899

99100
const colors = scaleLinear<string, string>()
100101
.domain(colorDomain)
101-
.range(palette.diverging)
102+
.range(chartPalette.diverging.GO)
102103
.interpolate(interpolateLab);
103104
const left = estimateTextWidth(
104105
yScale.domain().length > 1

Diff for: src/components/price-color-legend.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { InfoDialogButton } from "src/components/info-dialog";
77
import { useFormatCurrency } from "src/domain/helpers";
88
import { IconClear } from "src/icons/ic-clear";
99
import { IconInfo } from "src/icons/ic-info";
10+
import { chartPalette } from "src/themes/palette";
1011

1112
const LEGEND_WIDTH = 215;
1213
const TOP_LABEL_HEIGHT = 14;
@@ -223,7 +224,9 @@ const ColorsLine = () => {
223224
height: 0,
224225
borderTop: `${COLOR_HEIGHT / 2}px solid transparent`,
225226
borderBottom: `${COLOR_HEIGHT / 2}px solid transparent`,
226-
borderRight: `${COLOR_HEIGHT / 2}px solid ${palette.diverging[0]}`,
227+
borderRight: `${COLOR_HEIGHT / 2}px solid ${
228+
chartPalette.diverging.GO[0]
229+
}`,
227230
}}
228231
/>
229232
<Box
@@ -235,7 +238,7 @@ const ColorsLine = () => {
235238
width: "100%",
236239
}}
237240
>
238-
{palette.diverging.map((bg, i) => (
241+
{chartPalette.diverging.GO.map((bg, i) => (
239242
<Box
240243
key={bg}
241244
sx={{
@@ -276,7 +279,7 @@ const ColorsLine = () => {
276279
borderTop: `${COLOR_HEIGHT / 2}px solid transparent`,
277280
borderBottom: `${COLOR_HEIGHT / 2}px solid transparent`,
278281
borderLeft: `${COLOR_HEIGHT / 2}px solid ${
279-
palette.diverging[palette.diverging.length - 1]
282+
chartPalette.diverging.GO[chartPalette.diverging.GO.length - 1]
280283
}`,
281284
}}
282285
/>

Diff for: src/domain/data.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useTheme } from "@mui/material";
21
import { range, scaleThreshold } from "d3";
32
import { useMemo } from "react";
43

54
import buildEnv from "src/env/build";
65
import { Observation as QueryObservation } from "src/graphql/queries";
6+
import { chartPalette } from "src/themes/palette";
77

88
export type ObservationValue = string | number | boolean | Date;
99
export type GenericObservation = Record<string, ObservationValue>;
@@ -52,17 +52,15 @@ export const useColorScale = ({
5252
medianValue: number | undefined;
5353
accessor: (x: QueryObservation) => number;
5454
}) => {
55-
const { palette } = useTheme();
56-
5755
return useMemo(() => {
5856
const m = medianValue ?? 0;
5957
const domain = [m * 0.85, m * 0.95, m * 1.05, m * 1.15];
6058
const scale = scaleThreshold<number, string>()
6159
.domain(domain)
62-
.range(palette.diverging);
60+
.range(chartPalette.diverging.GO);
6361

6462
return scale;
65-
}, [medianValue, palette.diverging]);
63+
}, [medianValue]);
6664
};
6765

6866
export type Entity = "municipality" | "operator" | "canton";

Diff for: src/domain/helpers.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { GenericObservation } from "src/domain/data";
2323
import { estimateTextWidth } from "src/lib/estimate-text-width";
2424
import { useLocale } from "src/lib/use-locale";
2525
import { d3FormatLocales, d3TimeFormatLocales } from "src/locales/locales";
26+
import { chartPalette } from "src/themes/palette";
2627

2728
export const isNumber = (x: $IntentionalAny): boolean =>
2829
typeof x === "number" && !isNaN(x);
@@ -159,7 +160,7 @@ export const getPalette = (
159160
case "set3":
160161
return schemeSet3;
161162
case "elcom":
162-
return theme.palette.categorical;
163+
return chartPalette.categorical;
163164
default:
164165
return schemeCategory10;
165166
}

Diff for: src/themes/index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ declare module "@mui/material/Typography" {
4444

4545
declare module "@mui/material/styles" {
4646
interface BreakpointOverrides extends FederalBreakpointOverrides {}
47+
48+
interface Palette {
49+
tertiary: { main: string };
50+
}
51+
52+
interface PaletteOptions {
53+
tertiary: { main: string };
54+
}
4755
}
4856

4957
export { theme } from "./elcom";

Diff for: src/themes/palette.ts

+28-26
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@ export const palette = {
1616
main: colors.cobalt[700],
1717
...colors.cobalt,
1818
},
19+
tertiary: {
20+
main: colors.monochrome[800],
21+
},
1922
} satisfies ThemeOptions["palette"];
2023

21-
// FIXME: Bring back once we use it to prevent knip from causing issues
22-
// export const chartPalette = {
23-
// categorical: [
24-
// "#3B82F6",
25-
// "#EC4899",
26-
// "#10B981",
27-
// "#8B5CF6",
28-
// "#059669",
29-
// "#6B7280",
30-
// "#EA580C",
31-
// ],
32-
// sequential: {
33-
// yellow: ["#FDE68A", "#FCD34D", "#FBBF24", "#F59E0B", "#D97706", "#B45309"],
34-
// orange: ["#FED7AA", "#FDBA74", "#FB923C", "#F97316", "#EA580C", "#C2410C"],
35-
// green: ["#A7F3D0", "#6EE7B7", "#34D399", "#10B981", "#059669", "#047857"],
36-
// teal: ["#98F6F3", "#5DE8EA", "#2BCED4", "#14AFB8", "#0D8B96", "#0F6B75"],
37-
// blue: ["#BFDBFE", "#93C5FD", "#60A5FA", "#3B82F6", "#2563EB", "#1D4ED8"],
38-
// indigo: ["#E0E7FF", "#C7D2FE", "#A5B4FC", "#818CF8", "#6366F1", "#4338CA"],
39-
// purple: ["#EDE9FE", "#DDD6FE", "#C4B5FD", "#A78BFA", "#8B5CF6", "#7C3AED"],
40-
// pink: ["#FBCFE8", "#F9A8D4", "#F472B6", "#EC4899", "#DB2777", "#BE185D"],
41-
// },
42-
// diverging: {
43-
// BP: ["#2563EB", "#60A5FA", "#BFDBFE", "#FBCFE8", "#DB2777"],
44-
// GO: ["#059669", "#34D399", "#A7F3D0", "#E4D78C", "#EA580C"],
45-
// },
46-
// };
24+
export const chartPalette = {
25+
categorical: [
26+
"#3B82F6",
27+
"#F59E0B",
28+
"#EC4899",
29+
"#0D8B96",
30+
"#8655F6",
31+
"#059669",
32+
"#EA580C",
33+
],
34+
sequential: {
35+
orange: ["#FED7AA", "#FDBA74", "#FB923C", "#F97316", "#EA580C", "#C2410C"],
36+
yellow: ["#FDE68A", "#FCD34D", "#FBBF24", "#F59E0B", "#D97706", "#B45309"],
37+
green: ["#A7F3D0", "#6EE7B7", "#34D399", "#10B981", "#059669", "#047857"],
38+
teal: ["#98F6F3", "#5DE8EA", "#2BCED4", "#14AFB8", "#0D8B96", "#0F6B75"],
39+
blue: ["#BFDBFE", "#93C5FD", "#60A5FA", "#3B82F6", "#2563EB", "#1D4ED8"],
40+
indigo: ["#E0E7FF", "#C7D2FE", "#A5B4FC", "#818CF8", "#6366F1", "#4338CA"],
41+
purple: ["#EDE9FE", "#DDD6FE", "#C4B5FD", "#A78BFA", "#8B5CF6", "#7C3AED"],
42+
pink: ["#FBCFE8", "#F9A8D4", "#F472B6", "#EC4899", "#DB2777", "#BE185D"],
43+
},
44+
diverging: {
45+
GO: ["#059669", "#34D399", "#A7F3D0", "#E4D78C", "#EA580C"],
46+
BP: ["#2563EB", "#60A5FA", "#BFDBFE", "#FBCFE8", "#DB2777"],
47+
},
48+
};

0 commit comments

Comments
 (0)