Public
Edited
Oct 24, 2023
5 stars
Insert cell
Insert cell
date = d3.interpolateDate(new Date("1970-01-01"), new Date("1971-01-01"))
Insert cell
date(0.5)
Insert cell
Insert cell
a = ({temperature: 16, date: new Date("2019-06-10 10:00:00")})
Insert cell
b = ({temperature: 23, date: new Date("2019-06-13 10:00:00")})
Insert cell
interpolator = d3.interpolate(a, b)
Insert cell
interpolator(0.3)
Insert cell
Insert cell
scale = d3.scaleSqrt().range([new Date("2019-06-10 10:00:00"), new Date("2019-06-11 10:00:00")])
Insert cell
scale(0.4)
Insert cell
Insert cell
{
const broken = d3.interpolate("date: 1970-01-01", "date: 1971-01-01"); // 🕷
return broken(0.163);
}
Insert cell
{
const fixed = d3.interpolate(new Date("1970-01-01"), new Date("1971-01-01")); // 👍
const val = fixed(0.163).toISOString().slice(0, 10);
return `date: ${val}`;
}
Insert cell
Insert cell
{
const scale = d3.interpolate(new Date("2000-01-01"), new Date("2019-01-01"));
const a = scale(0); // 🌶 a and b are the same object, so their values are identical in the result (2019…)
const b = scale(1);
const c = new Date(scale(0)); // 👍 c is a copy (2000…), and so will not be mutated by the next call
const d = new Date(scale(1));
return {a, b, c, d};
}
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