Skip to content

Missing comma on interpolate function #2541

Closed

Description

@morocarlo

the function d3_interpolateTransform does not add comma between all the transform.

A possibile solution is (i haven't tested it in a large environment):

function add_comma(s){
    if (s.length > 0) return ',';
    else return '';
  }

  function d3_interpolateTransform(a, b) {
    var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
    if (ta[0] != tb[0] || ta[1] != tb[1]) {
      s.push("translate(", null, ",", null, ")");
      q.push({
        i: 1,
        x: d3_interpolateNumber(ta[0], tb[0])
      }, {
        i: 3,
        x: d3_interpolateNumber(ta[1], tb[1])
      });
    } else if (tb[0] || tb[1]) {
      s.push("translate(" + tb + ")");
    } else {
      s.push("");
    }
    if (ra != rb) {
      if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;    
      q.push({
        i: s.push(s.pop() + add_comma(s) + "rotate(", null, ")") - 2,
        x: d3_interpolateNumber(ra, rb)
      });
    } else if (rb) {
      s.push(s.pop() + add_comma(s) + "rotate(" + rb + ")");
    }
    if (wa != wb) {
      q.push({
        i: s.push(s.pop() + add_comma(s) + "skewX(", null, ")") - 2,
        x: d3_interpolateNumber(wa, wb)
      });
    } else if (wb) {
      s.push(s.pop() + add_comma(s) + "skewX(" + wb + ")");
    }
    if (ka[0] != kb[0] || ka[1] != kb[1]) {
      n = s.push(s.pop() + add_comma(s) + "scale(", null, ",", null, ")");
      q.push({
        i: n - 4,
        x: d3_interpolateNumber(ka[0], kb[0])
      }, {
        i: n - 2,
        x: d3_interpolateNumber(ka[1], kb[1])
      });
    } else if (kb[0] != 1 || kb[1] != 1) {
      s.push(s.pop() + add_comma(s) + "scale(" + kb + ")");
    }
    n = q.length;
    return function(t) {
      var i = -1, o;
      while (++i < n) s[(o = q[i]).i] = o.x(t);
      return s.join("");
    };
  }

Activity

  1. added
    bug
    on Oct 21, 2015
  2. added this to the 3.5.x milestone on Oct 21, 2015
  3. mbostock commented on Oct 21, 2015

    @mbostock
    Member

    Good catch. It seems that browsers don’t care whether you include the separating whitespace or comma, but the spec seems to require it.

  4. modified the milestones: 3.5.7, 3.5.x on Oct 22, 2015
  5. added a commit that references this issue on Oct 23, 2015
    c83c9bd
  6. mbostock commented on Oct 23, 2015

    @mbostock
    Member

    Fix staged in #2591 for 3.5.7.

  7. mbostock commented on Feb 26, 2016

    @mbostock
    Member

    This fixed #1472.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions