toolkit/javascript/d3/src/scale/polylinear.js
author Nicolas Sauret <nicolas.sauret@iri.centrepompidou.fr>
Wed, 16 Apr 2014 14:59:23 +0200
changeset 50 f68ecaf5265e
parent 47 c0b4a8b5a012
permissions -rw-r--r--
add visualisation dossiers + general editing

function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  var u = [],
      i = [],
      j = 0,
      n = domain.length;

  while (++j < n) {
    u.push(uninterpolate(domain[j - 1], domain[j]));
    i.push(interpolate(range[j - 1], range[j]));
  }

  return function(x) {
    var j = d3.bisect(domain, x, 1, domain.length - 1) - 1;
    return i[j](u[j](x));
  };
}