Published unlisted
Edited
May 20, 2020
Insert cell
Insert cell
x0 = d3.scaleLinear().domain([70, 210])
Insert cell
x0.ticks(2)
Insert cell
d3.tickIncrement(...x0.domain(), 2)
Insert cell
x1 = x0.copy().nice(2)
Insert cell
x1.domain()
Insert cell
x1.ticks(2)
Insert cell
d3.tickIncrement(...x1.domain(), 2)
Insert cell
x2 = x0.copy().domain([50, 250])
Insert cell
x2.ticks(3)
Insert cell
x2.ticks(2)
Insert cell
x3 = x0.copy().nice(2).nice(2)
Insert cell
x3.domain()
Insert cell
x3.ticks(2)
Insert cell
nice(70, 210, 2)
Insert cell
function nice(start, stop, count) {
let prestep;
while (true) {
const step = tickIncrement(start, stop, count);
if (step === prestep) {
return step;
} else if (step > 0) {
start = Math.floor(start / step) * step;
stop = Math.ceil(stop / step) * step;
} else if (step < 0) {
start = Math.ceil(start * step) / step;
stop = Math.floor(stop * step) / step;
} else {
return NaN;
}
prestep = step;
}
}
Insert cell
tickIncrement = d3.tickIncrement
Insert cell
d3 = require("d3-scale@3", "d3-array@2")
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