Public
Edited
Oct 24, 2023
1 fork
6 stars
Insert cell
Insert cell
Insert cell
{
const interpolator = d3.interpolate(
[0, "0.5 mile", [12]],
[10, "28 miles", [36]]
);
return interpolator(0.5);
}
Insert cell
Insert cell
{
const interpolator = d3.interpolate(
{ time: 0, distance: "0.5 mile", details: { cost: 12 } },
{ time: 10, distance: "28 miles", details: { cost: 36 } }
);
return interpolator(0.5);
}
Insert cell
Insert cell
{
const interpolator = d3.interpolate(
{ time: 0, details: { precision: 0 } }, // 👍 only time and details.precision will be interpolated
{
time: 10,
distance: "28 miles",
details: { cost: 36, precision: "3 feet" }
}
);
return interpolator(0.5);
}
Insert cell
Insert cell
Insert cell
{
const interpolator = d3.interpolate([0, 0], [1, -1]);

const a = interpolator(0), // 🌶 a and b are the same array, their values are shared (1,-1)
b = interpolator(1),
c = Array.from(interpolator(0)), // 👍 c is a copy of the returned array (0,0), will not be mutated
d = Array.from(interpolator(1));

return { a, b, c, d };
}
Insert cell
Insert cell
{
const interpolator = d3.interpolate({ a: 0 }, { a: 1 });

const a = interpolator(0), // 🌶 a and b are the same object, so their values are shared {a: 1}
b = interpolator(1),
c = Object.assign({}, interpolator(0)), // 👍 c is a shallow copy of the returned object, will not be mutated
d = Object.assign({}, interpolator(1));

return { a, b, c, d };
}
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3-interpolate@3")
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