Node-Red configuration
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

d3-interpolate.js 15KB

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