import { useMemo } from 'react'; import { scaleOrdinal } from 'd3'; import { mobileVisualisationPalette } from '@hero-design/colors'; // Only use colors that are not maasstrichtBlue const DEFAULT_COLORS = Object.entries(mobileVisualisationPalette) .filter(([key]) => !key.startsWith('maasstrichtBlue')) .map(([, value]) => value); /** * useColorScale - Returns a d3 ordinal scale for mapping labels to colors. * @param labels Array of labels (series names or keys) * @param customColors Optional custom color palette * @returns Ordinal scale function: (label: string) => color */ export default function useColorScale( labels: string[], customColors?: string[] ): (label: string) => string | undefined { return useMemo(() => { const palette = customColors && customColors.length > 0 ? customColors : DEFAULT_COLORS; return scaleOrdinal().domain(labels).range(palette); }, [labels, customColors]); }