Public
Edited
Oct 24, 2023
14 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ramp(t => d3.interpolateDiscrete(roma)(t))
Insert cell
ramp(t => d3.interpolateDiscrete(roma)(t), 10)
Insert cell
Insert cell
Insert cell
ramp(oleron)
Insert cell
Insert cell
grayish = d3.interpolate(oleron(0.4999), oleron(0.50001))(0.5)
Insert cell
Insert cell
{
const bag_of_things = ["String", 2, ["Array"], { name: "Object" }],
interpolator = d3.interpolateDiscrete(bag_of_things);
return interpolator(Math.random());
}
Insert cell
Insert cell
{
const colors = ["red", "blue", "green"],
interpolator = d3.interpolateDiscrete(colors),
random = d3.randomBates(3);
return interpolator(random());
}
Insert cell
Insert cell
interpolator = d3.interpolateDiscrete(["red", "blue", "green"])
Insert cell
interpolator(NaN)
Insert cell
interpolator(undefined)
Insert cell
[interpolator(-1), interpolator(2)] // clamping
Insert cell
interpolator("0.5") // casts a string as number
Insert cell
interpolator(null) // null is taken as 0
Insert cell
Insert cell
// https://observablehq.com/@mbostock/color-ramp
function ramp(color, n = 512) {
const canvas = DOM.canvas(n, 1);
const context = canvas.getContext("2d");
canvas.style.margin = "0 -14px";
canvas.style.width = "calc(100% + 28px)";
canvas.style.height = "40px";
canvas.style.imageRendering = "pixelated";
for (let i = 0; i < n; ++i) {
context.fillStyle = color(i / (n - 1));
context.fillRect(i, 0, 1, 1);
}
return canvas;
}
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