d3.bisectCenter?
mbostock opened this issue · 2 comments
mbostock commented
It’d be nice to have something that returned the closest datum to the specified value. I’m often doing something like this:
bisect = {
const bisectDate = d3.bisector(d => d.date).left;
return (data, date) => {
const i = bisectDate(data, date, 1);
const a = data[i - 1], b = data[i];
return date - a.date > b.date - date ? b : a;
};
}
It’d be nicer to say
bisect = d3.bisector(d => d.date).center
(Obviously, this would only work for quantitative values; ordinal values aren’t sufficient.)
mbostock commented
Here’s another example: