Skip to content

Commit

Permalink
enhance: darken all colorbrewer schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Aug 20, 2024
1 parent 8a289ce commit 1eb97af
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/@ourworldindata/grapher/src/color/ColorBrewerSchemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
ColorSchemeInterface,
ColorSchemeName,
} from "@ourworldindata/types"
import ColorJS from "colorjs.io"
import { memoize } from "@ourworldindata/utils"

type ColorSchemeProps = { displayName: string; singleColorScale: boolean }

Expand Down Expand Up @@ -59,6 +61,14 @@ const ColorBrewerSchemeIndex: {
PuBu: { displayName: "Purple-Blue shades", singleColorScale: true },
} as const

const _darkenColorForContrast = (color: string) => {

Check warning on line 64 in packages/@ourworldindata/grapher/src/color/ColorBrewerSchemes.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing return type on function

Check warning on line 64 in packages/@ourworldindata/grapher/src/color/ColorBrewerSchemes.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing return type on function
const col = new ColorJS(color)
col.oklab.l *= 0.95
return col.toString({ format: "hex" })
}

const darkenColorForContrast = memoize(_darkenColorForContrast)

export const getColorBrewerScheme: (
name: string
) => ColorSchemeInterface | undefined = (name: string) => {
Expand All @@ -69,7 +79,10 @@ export const getColorBrewerScheme: (

const colorSetsArray: Color[][] = []
Object.keys(colorSets).forEach(
(numColors) => (colorSetsArray[+numColors] = colorSets[numColors])
(numColors) =>
(colorSetsArray[+numColors] = colorSets[numColors].map(
darkenColorForContrast
))
)
return {
name,
Expand Down

0 comments on commit 1eb97af

Please sign in to comment.