source: node_modules/d3-interpolate/dist/d3-interpolate.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 15.3 KB
Line 
1// https://d3js.org/d3-interpolate/ v3.0.1 Copyright 2010-2021 Mike Bostock
2(function (global, factory) {
3typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-color')) :
4typeof define === 'function' && define.amd ? define(['exports', 'd3-color'], factory) :
5(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
6}(this, (function (exports, d3Color) { 'use strict';
7
8function basis(t1, v0, v1, v2, v3) {
9 var t2 = t1 * t1, t3 = t2 * t1;
10 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
11 + (4 - 6 * t2 + 3 * t3) * v1
12 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
13 + t3 * v3) / 6;
14}
15
16function basis$1(values) {
17 var n = values.length - 1;
18 return function(t) {
19 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
20 v1 = values[i],
21 v2 = values[i + 1],
22 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
23 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
24 return basis((t - i / n) * n, v0, v1, v2, v3);
25 };
26}
27
28function basisClosed(values) {
29 var n = values.length;
30 return function(t) {
31 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
32 v0 = values[(i + n - 1) % n],
33 v1 = values[i % n],
34 v2 = values[(i + 1) % n],
35 v3 = values[(i + 2) % n];
36 return basis((t - i / n) * n, v0, v1, v2, v3);
37 };
38}
39
40var constant = x => () => x;
41
42function linear(a, d) {
43 return function(t) {
44 return a + t * d;
45 };
46}
47
48function exponential(a, b, y) {
49 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
50 return Math.pow(a + t * b, y);
51 };
52}
53
54function hue$1(a, b) {
55 var d = b - a;
56 return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant(isNaN(a) ? b : a);
57}
58
59function gamma(y) {
60 return (y = +y) === 1 ? nogamma : function(a, b) {
61 return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);
62 };
63}
64
65function nogamma(a, b) {
66 var d = b - a;
67 return d ? linear(a, d) : constant(isNaN(a) ? b : a);
68}
69
70var rgb = (function rgbGamma(y) {
71 var color = gamma(y);
72
73 function rgb(start, end) {
74 var r = color((start = d3Color.rgb(start)).r, (end = d3Color.rgb(end)).r),
75 g = color(start.g, end.g),
76 b = color(start.b, end.b),
77 opacity = nogamma(start.opacity, end.opacity);
78 return function(t) {
79 start.r = r(t);
80 start.g = g(t);
81 start.b = b(t);
82 start.opacity = opacity(t);
83 return start + "";
84 };
85 }
86
87 rgb.gamma = rgbGamma;
88
89 return rgb;
90})(1);
91
92function rgbSpline(spline) {
93 return function(colors) {
94 var n = colors.length,
95 r = new Array(n),
96 g = new Array(n),
97 b = new Array(n),
98 i, color;
99 for (i = 0; i < n; ++i) {
100 color = d3Color.rgb(colors[i]);
101 r[i] = color.r || 0;
102 g[i] = color.g || 0;
103 b[i] = color.b || 0;
104 }
105 r = spline(r);
106 g = spline(g);
107 b = spline(b);
108 color.opacity = 1;
109 return function(t) {
110 color.r = r(t);
111 color.g = g(t);
112 color.b = b(t);
113 return color + "";
114 };
115 };
116}
117
118var rgbBasis = rgbSpline(basis$1);
119var rgbBasisClosed = rgbSpline(basisClosed);
120
121function numberArray(a, b) {
122 if (!b) b = [];
123 var n = a ? Math.min(b.length, a.length) : 0,
124 c = b.slice(),
125 i;
126 return function(t) {
127 for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
128 return c;
129 };
130}
131
132function isNumberArray(x) {
133 return ArrayBuffer.isView(x) && !(x instanceof DataView);
134}
135
136function array(a, b) {
137 return (isNumberArray(b) ? numberArray : genericArray)(a, b);
138}
139
140function genericArray(a, b) {
141 var nb = b ? b.length : 0,
142 na = a ? Math.min(nb, a.length) : 0,
143 x = new Array(na),
144 c = new Array(nb),
145 i;
146
147 for (i = 0; i < na; ++i) x[i] = value(a[i], b[i]);
148 for (; i < nb; ++i) c[i] = b[i];
149
150 return function(t) {
151 for (i = 0; i < na; ++i) c[i] = x[i](t);
152 return c;
153 };
154}
155
156function date(a, b) {
157 var d = new Date;
158 return a = +a, b = +b, function(t) {
159 return d.setTime(a * (1 - t) + b * t), d;
160 };
161}
162
163function number(a, b) {
164 return a = +a, b = +b, function(t) {
165 return a * (1 - t) + b * t;
166 };
167}
168
169function object(a, b) {
170 var i = {},
171 c = {},
172 k;
173
174 if (a === null || typeof a !== "object") a = {};
175 if (b === null || typeof b !== "object") b = {};
176
177 for (k in b) {
178 if (k in a) {
179 i[k] = value(a[k], b[k]);
180 } else {
181 c[k] = b[k];
182 }
183 }
184
185 return function(t) {
186 for (k in i) c[k] = i[k](t);
187 return c;
188 };
189}
190
191var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
192 reB = new RegExp(reA.source, "g");
193
194function zero(b) {
195 return function() {
196 return b;
197 };
198}
199
200function one(b) {
201 return function(t) {
202 return b(t) + "";
203 };
204}
205
206function string(a, b) {
207 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
208 am, // current match in a
209 bm, // current match in b
210 bs, // string preceding current number in b, if any
211 i = -1, // index in s
212 s = [], // string constants and placeholders
213 q = []; // number interpolators
214
215 // Coerce inputs to strings.
216 a = a + "", b = b + "";
217
218 // Interpolate pairs of numbers in a & b.
219 while ((am = reA.exec(a))
220 && (bm = reB.exec(b))) {
221 if ((bs = bm.index) > bi) { // a string precedes the next number in b
222 bs = b.slice(bi, bs);
223 if (s[i]) s[i] += bs; // coalesce with previous string
224 else s[++i] = bs;
225 }
226 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
227 if (s[i]) s[i] += bm; // coalesce with previous string
228 else s[++i] = bm;
229 } else { // interpolate non-matching numbers
230 s[++i] = null;
231 q.push({i: i, x: number(am, bm)});
232 }
233 bi = reB.lastIndex;
234 }
235
236 // Add remains of b.
237 if (bi < b.length) {
238 bs = b.slice(bi);
239 if (s[i]) s[i] += bs; // coalesce with previous string
240 else s[++i] = bs;
241 }
242
243 // Special optimization for only a single match.
244 // Otherwise, interpolate each of the numbers and rejoin the string.
245 return s.length < 2 ? (q[0]
246 ? one(q[0].x)
247 : zero(b))
248 : (b = q.length, function(t) {
249 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
250 return s.join("");
251 });
252}
253
254function value(a, b) {
255 var t = typeof b, c;
256 return b == null || t === "boolean" ? constant(b)
257 : (t === "number" ? number
258 : t === "string" ? ((c = d3Color.color(b)) ? (b = c, rgb) : string)
259 : b instanceof d3Color.color ? rgb
260 : b instanceof Date ? date
261 : isNumberArray(b) ? numberArray
262 : Array.isArray(b) ? genericArray
263 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
264 : number)(a, b);
265}
266
267function discrete(range) {
268 var n = range.length;
269 return function(t) {
270 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
271 };
272}
273
274function hue(a, b) {
275 var i = hue$1(+a, +b);
276 return function(t) {
277 var x = i(t);
278 return x - 360 * Math.floor(x / 360);
279 };
280}
281
282function round(a, b) {
283 return a = +a, b = +b, function(t) {
284 return Math.round(a * (1 - t) + b * t);
285 };
286}
287
288var degrees = 180 / Math.PI;
289
290var identity = {
291 translateX: 0,
292 translateY: 0,
293 rotate: 0,
294 skewX: 0,
295 scaleX: 1,
296 scaleY: 1
297};
298
299function decompose(a, b, c, d, e, f) {
300 var scaleX, scaleY, skewX;
301 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
302 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
303 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
304 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
305 return {
306 translateX: e,
307 translateY: f,
308 rotate: Math.atan2(b, a) * degrees,
309 skewX: Math.atan(skewX) * degrees,
310 scaleX: scaleX,
311 scaleY: scaleY
312 };
313}
314
315var svgNode;
316
317/* eslint-disable no-undef */
318function parseCss(value) {
319 const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
320 return m.isIdentity ? identity : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
321}
322
323function parseSvg(value) {
324 if (value == null) return identity;
325 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
326 svgNode.setAttribute("transform", value);
327 if (!(value = svgNode.transform.baseVal.consolidate())) return identity;
328 value = value.matrix;
329 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
330}
331
332function interpolateTransform(parse, pxComma, pxParen, degParen) {
333
334 function pop(s) {
335 return s.length ? s.pop() + " " : "";
336 }
337
338 function translate(xa, ya, xb, yb, s, q) {
339 if (xa !== xb || ya !== yb) {
340 var i = s.push("translate(", null, pxComma, null, pxParen);
341 q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});
342 } else if (xb || yb) {
343 s.push("translate(" + xb + pxComma + yb + pxParen);
344 }
345 }
346
347 function rotate(a, b, s, q) {
348 if (a !== b) {
349 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
350 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: number(a, b)});
351 } else if (b) {
352 s.push(pop(s) + "rotate(" + b + degParen);
353 }
354 }
355
356 function skewX(a, b, s, q) {
357 if (a !== b) {
358 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: number(a, b)});
359 } else if (b) {
360 s.push(pop(s) + "skewX(" + b + degParen);
361 }
362 }
363
364 function scale(xa, ya, xb, yb, s, q) {
365 if (xa !== xb || ya !== yb) {
366 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
367 q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});
368 } else if (xb !== 1 || yb !== 1) {
369 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
370 }
371 }
372
373 return function(a, b) {
374 var s = [], // string constants and placeholders
375 q = []; // number interpolators
376 a = parse(a), b = parse(b);
377 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
378 rotate(a.rotate, b.rotate, s, q);
379 skewX(a.skewX, b.skewX, s, q);
380 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
381 a = b = null; // gc
382 return function(t) {
383 var i = -1, n = q.length, o;
384 while (++i < n) s[(o = q[i]).i] = o.x(t);
385 return s.join("");
386 };
387 };
388}
389
390var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
391var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
392
393var epsilon2 = 1e-12;
394
395function cosh(x) {
396 return ((x = Math.exp(x)) + 1 / x) / 2;
397}
398
399function sinh(x) {
400 return ((x = Math.exp(x)) - 1 / x) / 2;
401}
402
403function tanh(x) {
404 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
405}
406
407var zoom = (function zoomRho(rho, rho2, rho4) {
408
409 // p0 = [ux0, uy0, w0]
410 // p1 = [ux1, uy1, w1]
411 function zoom(p0, p1) {
412 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
413 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
414 dx = ux1 - ux0,
415 dy = uy1 - uy0,
416 d2 = dx * dx + dy * dy,
417 i,
418 S;
419
420 // Special case for u0 ≅ u1.
421 if (d2 < epsilon2) {
422 S = Math.log(w1 / w0) / rho;
423 i = function(t) {
424 return [
425 ux0 + t * dx,
426 uy0 + t * dy,
427 w0 * Math.exp(rho * t * S)
428 ];
429 };
430 }
431
432 // General case.
433 else {
434 var d1 = Math.sqrt(d2),
435 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
436 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
437 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
438 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
439 S = (r1 - r0) / rho;
440 i = function(t) {
441 var s = t * S,
442 coshr0 = cosh(r0),
443 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
444 return [
445 ux0 + u * dx,
446 uy0 + u * dy,
447 w0 * coshr0 / cosh(rho * s + r0)
448 ];
449 };
450 }
451
452 i.duration = S * 1000 * rho / Math.SQRT2;
453
454 return i;
455 }
456
457 zoom.rho = function(_) {
458 var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
459 return zoomRho(_1, _2, _4);
460 };
461
462 return zoom;
463})(Math.SQRT2, 2, 4);
464
465function hsl(hue) {
466 return function(start, end) {
467 var h = hue((start = d3Color.hsl(start)).h, (end = d3Color.hsl(end)).h),
468 s = nogamma(start.s, end.s),
469 l = nogamma(start.l, end.l),
470 opacity = nogamma(start.opacity, end.opacity);
471 return function(t) {
472 start.h = h(t);
473 start.s = s(t);
474 start.l = l(t);
475 start.opacity = opacity(t);
476 return start + "";
477 };
478 }
479}
480
481var hsl$1 = hsl(hue$1);
482var hslLong = hsl(nogamma);
483
484function lab(start, end) {
485 var l = nogamma((start = d3Color.lab(start)).l, (end = d3Color.lab(end)).l),
486 a = nogamma(start.a, end.a),
487 b = nogamma(start.b, end.b),
488 opacity = nogamma(start.opacity, end.opacity);
489 return function(t) {
490 start.l = l(t);
491 start.a = a(t);
492 start.b = b(t);
493 start.opacity = opacity(t);
494 return start + "";
495 };
496}
497
498function hcl(hue) {
499 return function(start, end) {
500 var h = hue((start = d3Color.hcl(start)).h, (end = d3Color.hcl(end)).h),
501 c = nogamma(start.c, end.c),
502 l = nogamma(start.l, end.l),
503 opacity = nogamma(start.opacity, end.opacity);
504 return function(t) {
505 start.h = h(t);
506 start.c = c(t);
507 start.l = l(t);
508 start.opacity = opacity(t);
509 return start + "";
510 };
511 }
512}
513
514var hcl$1 = hcl(hue$1);
515var hclLong = hcl(nogamma);
516
517function cubehelix(hue) {
518 return (function cubehelixGamma(y) {
519 y = +y;
520
521 function cubehelix(start, end) {
522 var h = hue((start = d3Color.cubehelix(start)).h, (end = d3Color.cubehelix(end)).h),
523 s = nogamma(start.s, end.s),
524 l = nogamma(start.l, end.l),
525 opacity = nogamma(start.opacity, end.opacity);
526 return function(t) {
527 start.h = h(t);
528 start.s = s(t);
529 start.l = l(Math.pow(t, y));
530 start.opacity = opacity(t);
531 return start + "";
532 };
533 }
534
535 cubehelix.gamma = cubehelixGamma;
536
537 return cubehelix;
538 })(1);
539}
540
541var cubehelix$1 = cubehelix(hue$1);
542var cubehelixLong = cubehelix(nogamma);
543
544function piecewise(interpolate, values) {
545 if (values === undefined) values = interpolate, interpolate = value;
546 var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
547 while (i < n) I[i] = interpolate(v, v = values[++i]);
548 return function(t) {
549 var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
550 return I[i](t - i);
551 };
552}
553
554function quantize(interpolator, n) {
555 var samples = new Array(n);
556 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
557 return samples;
558}
559
560exports.interpolate = value;
561exports.interpolateArray = array;
562exports.interpolateBasis = basis$1;
563exports.interpolateBasisClosed = basisClosed;
564exports.interpolateCubehelix = cubehelix$1;
565exports.interpolateCubehelixLong = cubehelixLong;
566exports.interpolateDate = date;
567exports.interpolateDiscrete = discrete;
568exports.interpolateHcl = hcl$1;
569exports.interpolateHclLong = hclLong;
570exports.interpolateHsl = hsl$1;
571exports.interpolateHslLong = hslLong;
572exports.interpolateHue = hue;
573exports.interpolateLab = lab;
574exports.interpolateNumber = number;
575exports.interpolateNumberArray = numberArray;
576exports.interpolateObject = object;
577exports.interpolateRgb = rgb;
578exports.interpolateRgbBasis = rgbBasis;
579exports.interpolateRgbBasisClosed = rgbBasisClosed;
580exports.interpolateRound = round;
581exports.interpolateString = string;
582exports.interpolateTransformCss = interpolateTransformCss;
583exports.interpolateTransformSvg = interpolateTransformSvg;
584exports.interpolateZoom = zoom;
585exports.piecewise = piecewise;
586exports.quantize = quantize;
587
588Object.defineProperty(exports, '__esModule', { value: true });
589
590})));
Note: See TracBrowser for help on using the repository browser.