Published
Edited
Jul 21, 2020
1 fork
Insert cell

Color = require("chroma-js@1.3.5")
Insert cell
import {colorPicker} from "@shaunlebron/color-picker"
Insert cell
md`# Color Constrast`
Insert cell
viewof color = colorPicker("steelblue")
Insert cell
viewof background = colorPicker("steelblue")
Insert cell
contrast = (a, b) => {
// WCAG contrast ratio
// see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
a = new Color(a);
b = new Color(b);
const l1 = a.luminance();
const l2 = b.luminance();
return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05);
}
Insert cell
result = contrast(color, background)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more