Repository navigation
Closed
Description
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
mbostock commentedon Oct 21, 2015
Good catch. It seems that browsers don’t care whether you include the separating whitespace or comma, but the spec seems to require it.
Comma-separated transforms. Fixes #2541.
mbostock commentedon Oct 23, 2015
Fix staged in #2591 for 3.5.7.
mbostock commentedon Feb 26, 2016
This fixed #1472.