Public
Edited
Feb 24
Paused
1 fork
Importers
36 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
webPositions = Object.entries(WEB_COLORS).map(([name, [r, g, b]]) => {
const rgb = { mode: "rgb", r: r / 255, g: g / 255, b: b / 255 };
const hex = culori.formatHex(rgb);
const { l, a, b: bp } = culori.oklab(rgb);

return {
name,
hex,
a: a + Math.sin(l * Math.PI) / SHUNT_FACTOR,
b: bp + Math.cos(l * Math.PI) / SHUNT_FACTOR,
l
};
})
Insert cell
Insert cell
abDisplayabilityCoordinates = {
const ranges = culori.modeOklab.ranges;
const lRange = [...d3.range(...ranges.l, 0.005), ranges.l];
const aRange = [...d3.range(...ranges.a, 0.005), ranges.a];
const bRange = [...d3.range(...ranges.b, 0.005), ranges.b];

const isDisplayableAtAnyLightness = (a, b) =>
lRange.some((l) => {
return culori.displayable({ mode: "oklab", l, a, b });
});

return aRange.flatMap((a) =>
bRange.map((b) => {
const displayable = isDisplayableAtAnyLightness(a, b);
return { a, b, displayable };
})
);
}
Insert cell
displayabilityMaskMark = Plot.voronoi(abDisplayabilityCoordinates, {
x: "a",
y: "b",
fill: "white",
stroke: "white",
strokeWidth: 0,
fillOpacity: (d) => (d.displayable ? 0 : 1)
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
xkcdColors = Object.fromEntries(
rgb
.split("\n")
.slice(1)
.map((line) => {
const [name, hex] = line.split("\t");
return [name, hex];
})
)
Insert cell
xkcdPositions = Object.entries(xkcdColors).map(([name, hex]) => {
const oklab = culori.oklab(culori.parseHex(hex || "#000000"));

return { name, hex, ...oklab };
})
Insert cell
Insert cell
satfaces = (await FileAttachment("satfaces.txt").text())

Insert cell
satPositions = satfaces.split("\n").map((line) => {
// Be careful here, a lot of overwriting already used variables and names.
let [r, g, b, ...name] = line.split(" ");
name = name.join(" ");

let triplet;
try {
triplet = JSON.parse(r + g + b);
} catch (error) {
triplet = [0, 0, 0];
}

[r, g, b] = triplet;
const rgb = { mode: "rgb", r: r / 255, g: g / 255, b: b / 255 };
const oklab = culori.oklab(rgb);
const hex = culori.formatHex(rgb);

return { l: oklab.l, a: oklab.a, b: oklab.b, name, hex };
})
Insert cell
hullNames = new Set(satPositions.map((p) => p.name))
Insert cell
hullNamePositions = [...hullNames].map((name) =>
xkcdPositions.find((p) => p.name === name)
)
Insert cell
hullNameAveragePositions = _(satPositions)
.groupBy((d) => d.name)
.mapValues((vs) => ({
a: _.mean(vs.map((p) => p.a)),
b: _.mean(vs.map((p) => p.b))
}))
.entries()
.map(([name, average]) => ({ name, ...average }))
.value()
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