Public
Edited
Jan 3, 2024
Importers
Insert cell
Insert cell
Insert cell
Insert cell
scaleMember = (scale) => (value) => {
const color = scale.apply(value);
return html`<span style="border-bottom: solid ${color} 3px">${value}</span>`;
}
Insert cell
cylinders = scaleMember(carsPlot.scale("color"))
Insert cell
${cylinders(4)} ${cylinders(6)} ${cylinders(8)}
Insert cell
highlight = (color) => (string) => {
return htl.html`<span style="color: white; font-weight: 900;background-color:${color}; padding-left: 4px; padding-right: 4px;border-radius: 4px;">${string}</span>`;
}
Insert cell
redHighlight = highlight("red")
Insert cell
redHighlight(5)
Insert cell
import { textcolor } from "@observablehq/text-color-annotations-in-markdown"
Insert cell
Insert cell
Insert cell
rgbGamutInOklab = {
const ranges = culori.modeOklab.ranges;
const lRange = d3.range(...ranges.l, 0.02);
const aRange = d3.range(...ranges.a, 0.01);
const bRange = d3.range(...ranges.b, 0.01);

const acc = [];

for (const a of aRange) {
for (const b of bRange) {
for (const l of lRange) {
const oklab = { mode: "oklab", l, a, b };

if (!culori.displayable(oklab)) {
continue;
}

if (Math.random() < 0.9) {
continue;
}

const hex = culori.formatHex(oklab);

acc.push({ hex, ...oklab });
}
}
}
return acc;
}
Insert cell
Insert cell
Insert cell
Insert cell
umapProgress = (estimatedEpochs) => htl.html`<label>
Epoch ${epoch} / ${
targetEpochs ?? estimatedEpochs
}: <progress value="${epoch}" max="${
targetEpochs ?? estimatedEpochs
}">${epoch} / ${targetEpochs}</progress>
</label>`
Insert cell
umapProgress(500) // 500 because I know this task takes 500 epochs to complete
Insert cell
UMAP = (await require("umap-js@1.3.3/lib/umap-js.min.js")).UMAP
Insert cell
Insert cell
Insert cell
async function zipWithUmap(data, lens, { nComponents, nEpochs } = {}) {
const umap = new UMAP({
nComponents,
nEpochs
});
mutable targetEpochs = nEpochs;
const embeddings = await umap.fitAsync(
data.map((d) => lens(d)),
(epochNumber) => {
mutable epoch = epochNumber;
}
);

mutable targetEpochs = mutable epoch;
return embeddings.map((umapEmbedding, i) => ({
umapEmbedding,
...data[i]
}));
}
Insert cell
penguinsWithUmap = zipWithUmap(
penguins,
(d) => [
d.culmen_length_mm,
d.culmen_depth_mm,
d.flipper_length_mm,
d.body_mass_g
],
{ nNeighbors: 30, minDist: 0.5 }
)
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more