MCPcopy Create free account
hub / github.com/breck7/scroll / interpolateTransform

Function interpolateTransform

external/.d3.js:3803–3859  ·  view source on GitHub ↗
(parse, pxComma, pxParen, degParen)

Source from the content-addressed store, hash-verified

3801}
3802
3803function interpolateTransform(parse, pxComma, pxParen, degParen) {
3804
3805 function pop(s) {
3806 return s.length ? s.pop() + " " : "";
3807 }
3808
3809 function translate(xa, ya, xb, yb, s, q) {
3810 if (xa !== xb || ya !== yb) {
3811 var i = s.push("translate(", null, pxComma, null, pxParen);
3812 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
3813 } else if (xb || yb) {
3814 s.push("translate(" + xb + pxComma + yb + pxParen);
3815 }
3816 }
3817
3818 function rotate(a, b, s, q) {
3819 if (a !== b) {
3820 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
3821 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
3822 } else if (b) {
3823 s.push(pop(s) + "rotate(" + b + degParen);
3824 }
3825 }
3826
3827 function skewX(a, b, s, q) {
3828 if (a !== b) {
3829 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
3830 } else if (b) {
3831 s.push(pop(s) + "skewX(" + b + degParen);
3832 }
3833 }
3834
3835 function scale(xa, ya, xb, yb, s, q) {
3836 if (xa !== xb || ya !== yb) {
3837 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
3838 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
3839 } else if (xb !== 1 || yb !== 1) {
3840 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
3841 }
3842 }
3843
3844 return function(a, b) {
3845 var s = [], // string constants and placeholders
3846 q = []; // number interpolators
3847 a = parse(a), b = parse(b);
3848 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
3849 rotate(a.rotate, b.rotate, s, q);
3850 skewX(a.skewX, b.skewX, s, q);
3851 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
3852 a = b = null; // gc
3853 return function(t) {
3854 var i = -1, n = q.length, o;
3855 while (++i < n) s[(o = q[i]).i] = o.x(t);
3856 return s.join("");
3857 };
3858 };
3859}
3860

Callers 1

.d3.jsFile · 0.85

Calls 6

parseFunction · 0.85
translateFunction · 0.85
rotateFunction · 0.85
skewXFunction · 0.85
scaleFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected