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

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