d3/d3-array

d3.extentDiverging?

mbostock opened this issue · 2 comments

It’d be nice to have a variant of d3.extent that returns a three-element array with zero in the middle for use with d3.scaleDiverging.

function extentDiverging() {
  const [x0, x1] = extent.apply(this, arguments);
  return [Math.min(0, x0), 0, Math.max(0, x1)];
}
Fil commented

It was a bit odd that the pivot for extentDiverging would be 0, while it is 0.5 for the default domain of scaleDiverging.

Also, this might be served better by a more intelligent scaleDiverging.domain based on domain.length:

ie d3.scaleDiverging().domain([x0, x1], pivot=0) would be similar to .domain([max(pivot,x0), pivot, min(pivot,x1)])

see d3/d3-scale#215 for a proposal

Not planning on doing this.