MCPcopy
hub / github.com/jipegit/OSXAuditor / d3_interpolateString

Function d3_interpolateString

d3-3.2.8/d3.js:4980–5044  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

4978 }
4979 d3.interpolateString = d3_interpolateString;
4980 function d3_interpolateString(a, b) {
4981 var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
4982 a = a + "", b = b + "";
4983 d3_interpolate_number.lastIndex = 0;
4984 for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
4985 if (m.index) s.push(b.substring(s0, s1 = m.index));
4986 q.push({
4987 i: s.length,
4988 x: m[0]
4989 });
4990 s.push(null);
4991 s0 = d3_interpolate_number.lastIndex;
4992 }
4993 if (s0 < b.length) s.push(b.substring(s0));
4994 for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
4995 o = q[i];
4996 if (o.x == m[0]) {
4997 if (o.i) {
4998 if (s[o.i + 1] == null) {
4999 s[o.i - 1] += o.x;
5000 s.splice(o.i, 1);
5001 for (j = i + 1; j < n; ++j) q[j].i--;
5002 } else {
5003 s[o.i - 1] += o.x + s[o.i + 1];
5004 s.splice(o.i, 2);
5005 for (j = i + 1; j < n; ++j) q[j].i -= 2;
5006 }
5007 } else {
5008 if (s[o.i + 1] == null) {
5009 s[o.i] = o.x;
5010 } else {
5011 s[o.i] = o.x + s[o.i + 1];
5012 s.splice(o.i + 1, 1);
5013 for (j = i + 1; j < n; ++j) q[j].i--;
5014 }
5015 }
5016 q.splice(i, 1);
5017 n--;
5018 i--;
5019 } else {
5020 o.x = d3_interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
5021 }
5022 }
5023 while (i < n) {
5024 o = q.pop();
5025 if (s[o.i + 1] == null) {
5026 s[o.i] = o.x;
5027 } else {
5028 s[o.i] = o.x + s[o.i + 1];
5029 s.splice(o.i + 1, 1);
5030 }
5031 n--;
5032 }
5033 if (s.length === 1) {
5034 return s[0] == null ? (o = q[0].x, function(t) {
5035 return o(t) + "";
5036 }) : function() {
5037 return b;

Callers

nothing calls this directly

Calls 2

d3_interpolateNumberFunction · 0.85
oFunction · 0.70

Tested by

no test coverage detected