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

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