Node-Red configuration
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

d3-scale.js 30KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. // https://d3js.org/d3-scale/ v4.0.2 Copyright 2010-2021 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-interpolate'), require('d3-format'), require('d3-time'), require('d3-time-format')) :
  4. typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-interpolate', 'd3-format', 'd3-time', 'd3-time-format'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3, global.d3, global.d3, global.d3, global.d3));
  6. })(this, (function (exports, d3Array, d3Interpolate, d3Format, d3Time, d3TimeFormat) { 'use strict';
  7. function initRange(domain, range) {
  8. switch (arguments.length) {
  9. case 0: break;
  10. case 1: this.range(domain); break;
  11. default: this.range(range).domain(domain); break;
  12. }
  13. return this;
  14. }
  15. function initInterpolator(domain, interpolator) {
  16. switch (arguments.length) {
  17. case 0: break;
  18. case 1: {
  19. if (typeof domain === "function") this.interpolator(domain);
  20. else this.range(domain);
  21. break;
  22. }
  23. default: {
  24. this.domain(domain);
  25. if (typeof interpolator === "function") this.interpolator(interpolator);
  26. else this.range(interpolator);
  27. break;
  28. }
  29. }
  30. return this;
  31. }
  32. const implicit = Symbol("implicit");
  33. function ordinal() {
  34. var index = new d3Array.InternMap(),
  35. domain = [],
  36. range = [],
  37. unknown = implicit;
  38. function scale(d) {
  39. let i = index.get(d);
  40. if (i === undefined) {
  41. if (unknown !== implicit) return unknown;
  42. index.set(d, i = domain.push(d) - 1);
  43. }
  44. return range[i % range.length];
  45. }
  46. scale.domain = function(_) {
  47. if (!arguments.length) return domain.slice();
  48. domain = [], index = new d3Array.InternMap();
  49. for (const value of _) {
  50. if (index.has(value)) continue;
  51. index.set(value, domain.push(value) - 1);
  52. }
  53. return scale;
  54. };
  55. scale.range = function(_) {
  56. return arguments.length ? (range = Array.from(_), scale) : range.slice();
  57. };
  58. scale.unknown = function(_) {
  59. return arguments.length ? (unknown = _, scale) : unknown;
  60. };
  61. scale.copy = function() {
  62. return ordinal(domain, range).unknown(unknown);
  63. };
  64. initRange.apply(scale, arguments);
  65. return scale;
  66. }
  67. function band() {
  68. var scale = ordinal().unknown(undefined),
  69. domain = scale.domain,
  70. ordinalRange = scale.range,
  71. r0 = 0,
  72. r1 = 1,
  73. step,
  74. bandwidth,
  75. round = false,
  76. paddingInner = 0,
  77. paddingOuter = 0,
  78. align = 0.5;
  79. delete scale.unknown;
  80. function rescale() {
  81. var n = domain().length,
  82. reverse = r1 < r0,
  83. start = reverse ? r1 : r0,
  84. stop = reverse ? r0 : r1;
  85. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  86. if (round) step = Math.floor(step);
  87. start += (stop - start - step * (n - paddingInner)) * align;
  88. bandwidth = step * (1 - paddingInner);
  89. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  90. var values = d3Array.range(n).map(function(i) { return start + step * i; });
  91. return ordinalRange(reverse ? values.reverse() : values);
  92. }
  93. scale.domain = function(_) {
  94. return arguments.length ? (domain(_), rescale()) : domain();
  95. };
  96. scale.range = function(_) {
  97. return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
  98. };
  99. scale.rangeRound = function(_) {
  100. return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
  101. };
  102. scale.bandwidth = function() {
  103. return bandwidth;
  104. };
  105. scale.step = function() {
  106. return step;
  107. };
  108. scale.round = function(_) {
  109. return arguments.length ? (round = !!_, rescale()) : round;
  110. };
  111. scale.padding = function(_) {
  112. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  113. };
  114. scale.paddingInner = function(_) {
  115. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  116. };
  117. scale.paddingOuter = function(_) {
  118. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  119. };
  120. scale.align = function(_) {
  121. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  122. };
  123. scale.copy = function() {
  124. return band(domain(), [r0, r1])
  125. .round(round)
  126. .paddingInner(paddingInner)
  127. .paddingOuter(paddingOuter)
  128. .align(align);
  129. };
  130. return initRange.apply(rescale(), arguments);
  131. }
  132. function pointish(scale) {
  133. var copy = scale.copy;
  134. scale.padding = scale.paddingOuter;
  135. delete scale.paddingInner;
  136. delete scale.paddingOuter;
  137. scale.copy = function() {
  138. return pointish(copy());
  139. };
  140. return scale;
  141. }
  142. function point() {
  143. return pointish(band.apply(null, arguments).paddingInner(1));
  144. }
  145. function constants(x) {
  146. return function() {
  147. return x;
  148. };
  149. }
  150. function number$1(x) {
  151. return +x;
  152. }
  153. var unit = [0, 1];
  154. function identity$1(x) {
  155. return x;
  156. }
  157. function normalize(a, b) {
  158. return (b -= (a = +a))
  159. ? function(x) { return (x - a) / b; }
  160. : constants(isNaN(b) ? NaN : 0.5);
  161. }
  162. function clamper(a, b) {
  163. var t;
  164. if (a > b) t = a, a = b, b = t;
  165. return function(x) { return Math.max(a, Math.min(b, x)); };
  166. }
  167. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  168. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  169. function bimap(domain, range, interpolate) {
  170. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  171. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  172. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  173. return function(x) { return r0(d0(x)); };
  174. }
  175. function polymap(domain, range, interpolate) {
  176. var j = Math.min(domain.length, range.length) - 1,
  177. d = new Array(j),
  178. r = new Array(j),
  179. i = -1;
  180. // Reverse descending domains.
  181. if (domain[j] < domain[0]) {
  182. domain = domain.slice().reverse();
  183. range = range.slice().reverse();
  184. }
  185. while (++i < j) {
  186. d[i] = normalize(domain[i], domain[i + 1]);
  187. r[i] = interpolate(range[i], range[i + 1]);
  188. }
  189. return function(x) {
  190. var i = d3Array.bisect(domain, x, 1, j) - 1;
  191. return r[i](d[i](x));
  192. };
  193. }
  194. function copy$1(source, target) {
  195. return target
  196. .domain(source.domain())
  197. .range(source.range())
  198. .interpolate(source.interpolate())
  199. .clamp(source.clamp())
  200. .unknown(source.unknown());
  201. }
  202. function transformer$2() {
  203. var domain = unit,
  204. range = unit,
  205. interpolate = d3Interpolate.interpolate,
  206. transform,
  207. untransform,
  208. unknown,
  209. clamp = identity$1,
  210. piecewise,
  211. output,
  212. input;
  213. function rescale() {
  214. var n = Math.min(domain.length, range.length);
  215. if (clamp !== identity$1) clamp = clamper(domain[0], domain[n - 1]);
  216. piecewise = n > 2 ? polymap : bimap;
  217. output = input = null;
  218. return scale;
  219. }
  220. function scale(x) {
  221. return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  222. }
  223. scale.invert = function(y) {
  224. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), d3Interpolate.interpolateNumber)))(y)));
  225. };
  226. scale.domain = function(_) {
  227. return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
  228. };
  229. scale.range = function(_) {
  230. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  231. };
  232. scale.rangeRound = function(_) {
  233. return range = Array.from(_), interpolate = d3Interpolate.interpolateRound, rescale();
  234. };
  235. scale.clamp = function(_) {
  236. return arguments.length ? (clamp = _ ? true : identity$1, rescale()) : clamp !== identity$1;
  237. };
  238. scale.interpolate = function(_) {
  239. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  240. };
  241. scale.unknown = function(_) {
  242. return arguments.length ? (unknown = _, scale) : unknown;
  243. };
  244. return function(t, u) {
  245. transform = t, untransform = u;
  246. return rescale();
  247. };
  248. }
  249. function continuous() {
  250. return transformer$2()(identity$1, identity$1);
  251. }
  252. function tickFormat(start, stop, count, specifier) {
  253. var step = d3Array.tickStep(start, stop, count),
  254. precision;
  255. specifier = d3Format.formatSpecifier(specifier == null ? ",f" : specifier);
  256. switch (specifier.type) {
  257. case "s": {
  258. var value = Math.max(Math.abs(start), Math.abs(stop));
  259. if (specifier.precision == null && !isNaN(precision = d3Format.precisionPrefix(step, value))) specifier.precision = precision;
  260. return d3Format.formatPrefix(specifier, value);
  261. }
  262. case "":
  263. case "e":
  264. case "g":
  265. case "p":
  266. case "r": {
  267. if (specifier.precision == null && !isNaN(precision = d3Format.precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  268. break;
  269. }
  270. case "f":
  271. case "%": {
  272. if (specifier.precision == null && !isNaN(precision = d3Format.precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  273. break;
  274. }
  275. }
  276. return d3Format.format(specifier);
  277. }
  278. function linearish(scale) {
  279. var domain = scale.domain;
  280. scale.ticks = function(count) {
  281. var d = domain();
  282. return d3Array.ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  283. };
  284. scale.tickFormat = function(count, specifier) {
  285. var d = domain();
  286. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  287. };
  288. scale.nice = function(count) {
  289. if (count == null) count = 10;
  290. var d = domain();
  291. var i0 = 0;
  292. var i1 = d.length - 1;
  293. var start = d[i0];
  294. var stop = d[i1];
  295. var prestep;
  296. var step;
  297. var maxIter = 10;
  298. if (stop < start) {
  299. step = start, start = stop, stop = step;
  300. step = i0, i0 = i1, i1 = step;
  301. }
  302. while (maxIter-- > 0) {
  303. step = d3Array.tickIncrement(start, stop, count);
  304. if (step === prestep) {
  305. d[i0] = start;
  306. d[i1] = stop;
  307. return domain(d);
  308. } else if (step > 0) {
  309. start = Math.floor(start / step) * step;
  310. stop = Math.ceil(stop / step) * step;
  311. } else if (step < 0) {
  312. start = Math.ceil(start * step) / step;
  313. stop = Math.floor(stop * step) / step;
  314. } else {
  315. break;
  316. }
  317. prestep = step;
  318. }
  319. return scale;
  320. };
  321. return scale;
  322. }
  323. function linear() {
  324. var scale = continuous();
  325. scale.copy = function() {
  326. return copy$1(scale, linear());
  327. };
  328. initRange.apply(scale, arguments);
  329. return linearish(scale);
  330. }
  331. function identity(domain) {
  332. var unknown;
  333. function scale(x) {
  334. return x == null || isNaN(x = +x) ? unknown : x;
  335. }
  336. scale.invert = scale;
  337. scale.domain = scale.range = function(_) {
  338. return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
  339. };
  340. scale.unknown = function(_) {
  341. return arguments.length ? (unknown = _, scale) : unknown;
  342. };
  343. scale.copy = function() {
  344. return identity(domain).unknown(unknown);
  345. };
  346. domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
  347. return linearish(scale);
  348. }
  349. function nice(domain, interval) {
  350. domain = domain.slice();
  351. var i0 = 0,
  352. i1 = domain.length - 1,
  353. x0 = domain[i0],
  354. x1 = domain[i1],
  355. t;
  356. if (x1 < x0) {
  357. t = i0, i0 = i1, i1 = t;
  358. t = x0, x0 = x1, x1 = t;
  359. }
  360. domain[i0] = interval.floor(x0);
  361. domain[i1] = interval.ceil(x1);
  362. return domain;
  363. }
  364. function transformLog(x) {
  365. return Math.log(x);
  366. }
  367. function transformExp(x) {
  368. return Math.exp(x);
  369. }
  370. function transformLogn(x) {
  371. return -Math.log(-x);
  372. }
  373. function transformExpn(x) {
  374. return -Math.exp(-x);
  375. }
  376. function pow10(x) {
  377. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  378. }
  379. function powp(base) {
  380. return base === 10 ? pow10
  381. : base === Math.E ? Math.exp
  382. : x => Math.pow(base, x);
  383. }
  384. function logp(base) {
  385. return base === Math.E ? Math.log
  386. : base === 10 && Math.log10
  387. || base === 2 && Math.log2
  388. || (base = Math.log(base), x => Math.log(x) / base);
  389. }
  390. function reflect(f) {
  391. return (x, k) => -f(-x, k);
  392. }
  393. function loggish(transform) {
  394. const scale = transform(transformLog, transformExp);
  395. const domain = scale.domain;
  396. let base = 10;
  397. let logs;
  398. let pows;
  399. function rescale() {
  400. logs = logp(base), pows = powp(base);
  401. if (domain()[0] < 0) {
  402. logs = reflect(logs), pows = reflect(pows);
  403. transform(transformLogn, transformExpn);
  404. } else {
  405. transform(transformLog, transformExp);
  406. }
  407. return scale;
  408. }
  409. scale.base = function(_) {
  410. return arguments.length ? (base = +_, rescale()) : base;
  411. };
  412. scale.domain = function(_) {
  413. return arguments.length ? (domain(_), rescale()) : domain();
  414. };
  415. scale.ticks = count => {
  416. const d = domain();
  417. let u = d[0];
  418. let v = d[d.length - 1];
  419. const r = v < u;
  420. if (r) ([u, v] = [v, u]);
  421. let i = logs(u);
  422. let j = logs(v);
  423. let k;
  424. let t;
  425. const n = count == null ? 10 : +count;
  426. let z = [];
  427. if (!(base % 1) && j - i < n) {
  428. i = Math.floor(i), j = Math.ceil(j);
  429. if (u > 0) for (; i <= j; ++i) {
  430. for (k = 1; k < base; ++k) {
  431. t = i < 0 ? k / pows(-i) : k * pows(i);
  432. if (t < u) continue;
  433. if (t > v) break;
  434. z.push(t);
  435. }
  436. } else for (; i <= j; ++i) {
  437. for (k = base - 1; k >= 1; --k) {
  438. t = i > 0 ? k / pows(-i) : k * pows(i);
  439. if (t < u) continue;
  440. if (t > v) break;
  441. z.push(t);
  442. }
  443. }
  444. if (z.length * 2 < n) z = d3Array.ticks(u, v, n);
  445. } else {
  446. z = d3Array.ticks(i, j, Math.min(j - i, n)).map(pows);
  447. }
  448. return r ? z.reverse() : z;
  449. };
  450. scale.tickFormat = (count, specifier) => {
  451. if (count == null) count = 10;
  452. if (specifier == null) specifier = base === 10 ? "s" : ",";
  453. if (typeof specifier !== "function") {
  454. if (!(base % 1) && (specifier = d3Format.formatSpecifier(specifier)).precision == null) specifier.trim = true;
  455. specifier = d3Format.format(specifier);
  456. }
  457. if (count === Infinity) return specifier;
  458. const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  459. return d => {
  460. let i = d / pows(Math.round(logs(d)));
  461. if (i * base < base - 0.5) i *= base;
  462. return i <= k ? specifier(d) : "";
  463. };
  464. };
  465. scale.nice = () => {
  466. return domain(nice(domain(), {
  467. floor: x => pows(Math.floor(logs(x))),
  468. ceil: x => pows(Math.ceil(logs(x)))
  469. }));
  470. };
  471. return scale;
  472. }
  473. function log() {
  474. const scale = loggish(transformer$2()).domain([1, 10]);
  475. scale.copy = () => copy$1(scale, log()).base(scale.base());
  476. initRange.apply(scale, arguments);
  477. return scale;
  478. }
  479. function transformSymlog(c) {
  480. return function(x) {
  481. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  482. };
  483. }
  484. function transformSymexp(c) {
  485. return function(x) {
  486. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  487. };
  488. }
  489. function symlogish(transform) {
  490. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  491. scale.constant = function(_) {
  492. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  493. };
  494. return linearish(scale);
  495. }
  496. function symlog() {
  497. var scale = symlogish(transformer$2());
  498. scale.copy = function() {
  499. return copy$1(scale, symlog()).constant(scale.constant());
  500. };
  501. return initRange.apply(scale, arguments);
  502. }
  503. function transformPow(exponent) {
  504. return function(x) {
  505. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  506. };
  507. }
  508. function transformSqrt(x) {
  509. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  510. }
  511. function transformSquare(x) {
  512. return x < 0 ? -x * x : x * x;
  513. }
  514. function powish(transform) {
  515. var scale = transform(identity$1, identity$1),
  516. exponent = 1;
  517. function rescale() {
  518. return exponent === 1 ? transform(identity$1, identity$1)
  519. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  520. : transform(transformPow(exponent), transformPow(1 / exponent));
  521. }
  522. scale.exponent = function(_) {
  523. return arguments.length ? (exponent = +_, rescale()) : exponent;
  524. };
  525. return linearish(scale);
  526. }
  527. function pow() {
  528. var scale = powish(transformer$2());
  529. scale.copy = function() {
  530. return copy$1(scale, pow()).exponent(scale.exponent());
  531. };
  532. initRange.apply(scale, arguments);
  533. return scale;
  534. }
  535. function sqrt() {
  536. return pow.apply(null, arguments).exponent(0.5);
  537. }
  538. function square(x) {
  539. return Math.sign(x) * x * x;
  540. }
  541. function unsquare(x) {
  542. return Math.sign(x) * Math.sqrt(Math.abs(x));
  543. }
  544. function radial() {
  545. var squared = continuous(),
  546. range = [0, 1],
  547. round = false,
  548. unknown;
  549. function scale(x) {
  550. var y = unsquare(squared(x));
  551. return isNaN(y) ? unknown : round ? Math.round(y) : y;
  552. }
  553. scale.invert = function(y) {
  554. return squared.invert(square(y));
  555. };
  556. scale.domain = function(_) {
  557. return arguments.length ? (squared.domain(_), scale) : squared.domain();
  558. };
  559. scale.range = function(_) {
  560. return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square)), scale) : range.slice();
  561. };
  562. scale.rangeRound = function(_) {
  563. return scale.range(_).round(true);
  564. };
  565. scale.round = function(_) {
  566. return arguments.length ? (round = !!_, scale) : round;
  567. };
  568. scale.clamp = function(_) {
  569. return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
  570. };
  571. scale.unknown = function(_) {
  572. return arguments.length ? (unknown = _, scale) : unknown;
  573. };
  574. scale.copy = function() {
  575. return radial(squared.domain(), range)
  576. .round(round)
  577. .clamp(squared.clamp())
  578. .unknown(unknown);
  579. };
  580. initRange.apply(scale, arguments);
  581. return linearish(scale);
  582. }
  583. function quantile() {
  584. var domain = [],
  585. range = [],
  586. thresholds = [],
  587. unknown;
  588. function rescale() {
  589. var i = 0, n = Math.max(1, range.length);
  590. thresholds = new Array(n - 1);
  591. while (++i < n) thresholds[i - 1] = d3Array.quantileSorted(domain, i / n);
  592. return scale;
  593. }
  594. function scale(x) {
  595. return x == null || isNaN(x = +x) ? unknown : range[d3Array.bisect(thresholds, x)];
  596. }
  597. scale.invertExtent = function(y) {
  598. var i = range.indexOf(y);
  599. return i < 0 ? [NaN, NaN] : [
  600. i > 0 ? thresholds[i - 1] : domain[0],
  601. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  602. ];
  603. };
  604. scale.domain = function(_) {
  605. if (!arguments.length) return domain.slice();
  606. domain = [];
  607. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  608. domain.sort(d3Array.ascending);
  609. return rescale();
  610. };
  611. scale.range = function(_) {
  612. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  613. };
  614. scale.unknown = function(_) {
  615. return arguments.length ? (unknown = _, scale) : unknown;
  616. };
  617. scale.quantiles = function() {
  618. return thresholds.slice();
  619. };
  620. scale.copy = function() {
  621. return quantile()
  622. .domain(domain)
  623. .range(range)
  624. .unknown(unknown);
  625. };
  626. return initRange.apply(scale, arguments);
  627. }
  628. function quantize() {
  629. var x0 = 0,
  630. x1 = 1,
  631. n = 1,
  632. domain = [0.5],
  633. range = [0, 1],
  634. unknown;
  635. function scale(x) {
  636. return x != null && x <= x ? range[d3Array.bisect(domain, x, 0, n)] : unknown;
  637. }
  638. function rescale() {
  639. var i = -1;
  640. domain = new Array(n);
  641. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  642. return scale;
  643. }
  644. scale.domain = function(_) {
  645. return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
  646. };
  647. scale.range = function(_) {
  648. return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
  649. };
  650. scale.invertExtent = function(y) {
  651. var i = range.indexOf(y);
  652. return i < 0 ? [NaN, NaN]
  653. : i < 1 ? [x0, domain[0]]
  654. : i >= n ? [domain[n - 1], x1]
  655. : [domain[i - 1], domain[i]];
  656. };
  657. scale.unknown = function(_) {
  658. return arguments.length ? (unknown = _, scale) : scale;
  659. };
  660. scale.thresholds = function() {
  661. return domain.slice();
  662. };
  663. scale.copy = function() {
  664. return quantize()
  665. .domain([x0, x1])
  666. .range(range)
  667. .unknown(unknown);
  668. };
  669. return initRange.apply(linearish(scale), arguments);
  670. }
  671. function threshold() {
  672. var domain = [0.5],
  673. range = [0, 1],
  674. unknown,
  675. n = 1;
  676. function scale(x) {
  677. return x != null && x <= x ? range[d3Array.bisect(domain, x, 0, n)] : unknown;
  678. }
  679. scale.domain = function(_) {
  680. return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  681. };
  682. scale.range = function(_) {
  683. return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  684. };
  685. scale.invertExtent = function(y) {
  686. var i = range.indexOf(y);
  687. return [domain[i - 1], domain[i]];
  688. };
  689. scale.unknown = function(_) {
  690. return arguments.length ? (unknown = _, scale) : unknown;
  691. };
  692. scale.copy = function() {
  693. return threshold()
  694. .domain(domain)
  695. .range(range)
  696. .unknown(unknown);
  697. };
  698. return initRange.apply(scale, arguments);
  699. }
  700. function date(t) {
  701. return new Date(t);
  702. }
  703. function number(t) {
  704. return t instanceof Date ? +t : +new Date(+t);
  705. }
  706. function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
  707. var scale = continuous(),
  708. invert = scale.invert,
  709. domain = scale.domain;
  710. var formatMillisecond = format(".%L"),
  711. formatSecond = format(":%S"),
  712. formatMinute = format("%I:%M"),
  713. formatHour = format("%I %p"),
  714. formatDay = format("%a %d"),
  715. formatWeek = format("%b %d"),
  716. formatMonth = format("%B"),
  717. formatYear = format("%Y");
  718. function tickFormat(date) {
  719. return (second(date) < date ? formatMillisecond
  720. : minute(date) < date ? formatSecond
  721. : hour(date) < date ? formatMinute
  722. : day(date) < date ? formatHour
  723. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  724. : year(date) < date ? formatMonth
  725. : formatYear)(date);
  726. }
  727. scale.invert = function(y) {
  728. return new Date(invert(y));
  729. };
  730. scale.domain = function(_) {
  731. return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
  732. };
  733. scale.ticks = function(interval) {
  734. var d = domain();
  735. return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
  736. };
  737. scale.tickFormat = function(count, specifier) {
  738. return specifier == null ? tickFormat : format(specifier);
  739. };
  740. scale.nice = function(interval) {
  741. var d = domain();
  742. if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
  743. return interval ? domain(nice(d, interval)) : scale;
  744. };
  745. scale.copy = function() {
  746. return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
  747. };
  748. return scale;
  749. }
  750. function time() {
  751. return initRange.apply(calendar(d3Time.timeTicks, d3Time.timeTickInterval, d3Time.timeYear, d3Time.timeMonth, d3Time.timeWeek, d3Time.timeDay, d3Time.timeHour, d3Time.timeMinute, d3Time.timeSecond, d3TimeFormat.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  752. }
  753. function utcTime() {
  754. return initRange.apply(calendar(d3Time.utcTicks, d3Time.utcTickInterval, d3Time.utcYear, d3Time.utcMonth, d3Time.utcWeek, d3Time.utcDay, d3Time.utcHour, d3Time.utcMinute, d3Time.utcSecond, d3TimeFormat.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  755. }
  756. function transformer$1() {
  757. var x0 = 0,
  758. x1 = 1,
  759. t0,
  760. t1,
  761. k10,
  762. transform,
  763. interpolator = identity$1,
  764. clamp = false,
  765. unknown;
  766. function scale(x) {
  767. return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  768. }
  769. scale.domain = function(_) {
  770. return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  771. };
  772. scale.clamp = function(_) {
  773. return arguments.length ? (clamp = !!_, scale) : clamp;
  774. };
  775. scale.interpolator = function(_) {
  776. return arguments.length ? (interpolator = _, scale) : interpolator;
  777. };
  778. function range(interpolate) {
  779. return function(_) {
  780. var r0, r1;
  781. return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
  782. };
  783. }
  784. scale.range = range(d3Interpolate.interpolate);
  785. scale.rangeRound = range(d3Interpolate.interpolateRound);
  786. scale.unknown = function(_) {
  787. return arguments.length ? (unknown = _, scale) : unknown;
  788. };
  789. return function(t) {
  790. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  791. return scale;
  792. };
  793. }
  794. function copy(source, target) {
  795. return target
  796. .domain(source.domain())
  797. .interpolator(source.interpolator())
  798. .clamp(source.clamp())
  799. .unknown(source.unknown());
  800. }
  801. function sequential() {
  802. var scale = linearish(transformer$1()(identity$1));
  803. scale.copy = function() {
  804. return copy(scale, sequential());
  805. };
  806. return initInterpolator.apply(scale, arguments);
  807. }
  808. function sequentialLog() {
  809. var scale = loggish(transformer$1()).domain([1, 10]);
  810. scale.copy = function() {
  811. return copy(scale, sequentialLog()).base(scale.base());
  812. };
  813. return initInterpolator.apply(scale, arguments);
  814. }
  815. function sequentialSymlog() {
  816. var scale = symlogish(transformer$1());
  817. scale.copy = function() {
  818. return copy(scale, sequentialSymlog()).constant(scale.constant());
  819. };
  820. return initInterpolator.apply(scale, arguments);
  821. }
  822. function sequentialPow() {
  823. var scale = powish(transformer$1());
  824. scale.copy = function() {
  825. return copy(scale, sequentialPow()).exponent(scale.exponent());
  826. };
  827. return initInterpolator.apply(scale, arguments);
  828. }
  829. function sequentialSqrt() {
  830. return sequentialPow.apply(null, arguments).exponent(0.5);
  831. }
  832. function sequentialQuantile() {
  833. var domain = [],
  834. interpolator = identity$1;
  835. function scale(x) {
  836. if (x != null && !isNaN(x = +x)) return interpolator((d3Array.bisect(domain, x, 1) - 1) / (domain.length - 1));
  837. }
  838. scale.domain = function(_) {
  839. if (!arguments.length) return domain.slice();
  840. domain = [];
  841. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  842. domain.sort(d3Array.ascending);
  843. return scale;
  844. };
  845. scale.interpolator = function(_) {
  846. return arguments.length ? (interpolator = _, scale) : interpolator;
  847. };
  848. scale.range = function() {
  849. return domain.map((d, i) => interpolator(i / (domain.length - 1)));
  850. };
  851. scale.quantiles = function(n) {
  852. return Array.from({length: n + 1}, (_, i) => d3Array.quantile(domain, i / n));
  853. };
  854. scale.copy = function() {
  855. return sequentialQuantile(interpolator).domain(domain);
  856. };
  857. return initInterpolator.apply(scale, arguments);
  858. }
  859. function transformer() {
  860. var x0 = 0,
  861. x1 = 0.5,
  862. x2 = 1,
  863. s = 1,
  864. t0,
  865. t1,
  866. t2,
  867. k10,
  868. k21,
  869. interpolator = identity$1,
  870. transform,
  871. clamp = false,
  872. unknown;
  873. function scale(x) {
  874. return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
  875. }
  876. scale.domain = function(_) {
  877. return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2];
  878. };
  879. scale.clamp = function(_) {
  880. return arguments.length ? (clamp = !!_, scale) : clamp;
  881. };
  882. scale.interpolator = function(_) {
  883. return arguments.length ? (interpolator = _, scale) : interpolator;
  884. };
  885. function range(interpolate) {
  886. return function(_) {
  887. var r0, r1, r2;
  888. return arguments.length ? ([r0, r1, r2] = _, interpolator = d3Interpolate.piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
  889. };
  890. }
  891. scale.range = range(d3Interpolate.interpolate);
  892. scale.rangeRound = range(d3Interpolate.interpolateRound);
  893. scale.unknown = function(_) {
  894. return arguments.length ? (unknown = _, scale) : unknown;
  895. };
  896. return function(t) {
  897. transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1;
  898. return scale;
  899. };
  900. }
  901. function diverging() {
  902. var scale = linearish(transformer()(identity$1));
  903. scale.copy = function() {
  904. return copy(scale, diverging());
  905. };
  906. return initInterpolator.apply(scale, arguments);
  907. }
  908. function divergingLog() {
  909. var scale = loggish(transformer()).domain([0.1, 1, 10]);
  910. scale.copy = function() {
  911. return copy(scale, divergingLog()).base(scale.base());
  912. };
  913. return initInterpolator.apply(scale, arguments);
  914. }
  915. function divergingSymlog() {
  916. var scale = symlogish(transformer());
  917. scale.copy = function() {
  918. return copy(scale, divergingSymlog()).constant(scale.constant());
  919. };
  920. return initInterpolator.apply(scale, arguments);
  921. }
  922. function divergingPow() {
  923. var scale = powish(transformer());
  924. scale.copy = function() {
  925. return copy(scale, divergingPow()).exponent(scale.exponent());
  926. };
  927. return initInterpolator.apply(scale, arguments);
  928. }
  929. function divergingSqrt() {
  930. return divergingPow.apply(null, arguments).exponent(0.5);
  931. }
  932. exports.scaleBand = band;
  933. exports.scaleDiverging = diverging;
  934. exports.scaleDivergingLog = divergingLog;
  935. exports.scaleDivergingPow = divergingPow;
  936. exports.scaleDivergingSqrt = divergingSqrt;
  937. exports.scaleDivergingSymlog = divergingSymlog;
  938. exports.scaleIdentity = identity;
  939. exports.scaleImplicit = implicit;
  940. exports.scaleLinear = linear;
  941. exports.scaleLog = log;
  942. exports.scaleOrdinal = ordinal;
  943. exports.scalePoint = point;
  944. exports.scalePow = pow;
  945. exports.scaleQuantile = quantile;
  946. exports.scaleQuantize = quantize;
  947. exports.scaleRadial = radial;
  948. exports.scaleSequential = sequential;
  949. exports.scaleSequentialLog = sequentialLog;
  950. exports.scaleSequentialPow = sequentialPow;
  951. exports.scaleSequentialQuantile = sequentialQuantile;
  952. exports.scaleSequentialSqrt = sequentialSqrt;
  953. exports.scaleSequentialSymlog = sequentialSymlog;
  954. exports.scaleSqrt = sqrt;
  955. exports.scaleSymlog = symlog;
  956. exports.scaleThreshold = threshold;
  957. exports.scaleTime = time;
  958. exports.scaleUtc = utcTime;
  959. exports.tickFormat = tickFormat;
  960. Object.defineProperty(exports, '__esModule', { value: true });
  961. }));