Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Beige: Darken ColorBrewer colors for more contrast #3892

Draft
wants to merge 2 commits into
base: beige
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"classnames": "^2.5.1",
"codemirror": "5",
"colorbrewer": "^1.3.0",
"colorjs.io": "^0.5.2",
"cookie-parser": "^1.4.4",
"d3": "^6.1.1",
"dayjs": "^1.11.11",
Expand Down
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 @@
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 @@
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 @@

const colorSetsArray: Color[][] = []
Object.keys(colorSets).forEach(
(numColors) => (colorSetsArray[+numColors] = colorSets[numColors])
(numColors) =>
(colorSetsArray[+numColors] = colorSets[numColors].map(
darkenColorForContrast
))
)
return {
name,
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8412,6 +8412,13 @@ __metadata:
languageName: node
linkType: hard

"colorjs.io@npm:^0.5.2":
version: 0.5.2
resolution: "colorjs.io@npm:0.5.2"
checksum: 10/a6f6345865b177d19481008cb299c46ec9ff1fd206f472cd9ef69ddbca65832c81237b19fdcd24f3f9540c3e6343a22eb486cd800f5eab9815ce7c98c16a0f0e
languageName: node
linkType: hard

"columnify@npm:1.6.0":
version: 1.6.0
resolution: "columnify@npm:1.6.0"
Expand Down Expand Up @@ -11881,6 +11888,7 @@ __metadata:
classnames: "npm:^2.5.1"
codemirror: "npm:5"
colorbrewer: "npm:^1.3.0"
colorjs.io: "npm:^0.5.2"
cookie-parser: "npm:^1.4.4"
cypress: "npm:9.3.1"
d3: "npm:^6.1.1"
Expand Down
Loading