Node-Red configuration
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

d3-shape.js 56KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. // https://d3js.org/d3-shape/ v3.2.0 Copyright 2010-2022 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-path')) :
  4. typeof define === 'function' && define.amd ? define(['exports', 'd3-path'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
  6. })(this, (function (exports, d3Path) { 'use strict';
  7. function constant(x) {
  8. return function constant() {
  9. return x;
  10. };
  11. }
  12. const abs = Math.abs;
  13. const atan2 = Math.atan2;
  14. const cos = Math.cos;
  15. const max = Math.max;
  16. const min = Math.min;
  17. const sin = Math.sin;
  18. const sqrt = Math.sqrt;
  19. const epsilon = 1e-12;
  20. const pi = Math.PI;
  21. const halfPi = pi / 2;
  22. const tau = 2 * pi;
  23. function acos(x) {
  24. return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
  25. }
  26. function asin(x) {
  27. return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
  28. }
  29. function withPath(shape) {
  30. let digits = 3;
  31. shape.digits = function(_) {
  32. if (!arguments.length) return digits;
  33. if (_ == null) {
  34. digits = null;
  35. } else {
  36. const d = Math.floor(_);
  37. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  38. digits = d;
  39. }
  40. return shape;
  41. };
  42. return () => new d3Path.Path(digits);
  43. }
  44. function arcInnerRadius(d) {
  45. return d.innerRadius;
  46. }
  47. function arcOuterRadius(d) {
  48. return d.outerRadius;
  49. }
  50. function arcStartAngle(d) {
  51. return d.startAngle;
  52. }
  53. function arcEndAngle(d) {
  54. return d.endAngle;
  55. }
  56. function arcPadAngle(d) {
  57. return d && d.padAngle; // Note: optional!
  58. }
  59. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  60. var x10 = x1 - x0, y10 = y1 - y0,
  61. x32 = x3 - x2, y32 = y3 - y2,
  62. t = y32 * x10 - x32 * y10;
  63. if (t * t < epsilon) return;
  64. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  65. return [x0 + t * x10, y0 + t * y10];
  66. }
  67. // Compute perpendicular offset line of length rc.
  68. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  69. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  70. var x01 = x0 - x1,
  71. y01 = y0 - y1,
  72. lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
  73. ox = lo * y01,
  74. oy = -lo * x01,
  75. x11 = x0 + ox,
  76. y11 = y0 + oy,
  77. x10 = x1 + ox,
  78. y10 = y1 + oy,
  79. x00 = (x11 + x10) / 2,
  80. y00 = (y11 + y10) / 2,
  81. dx = x10 - x11,
  82. dy = y10 - y11,
  83. d2 = dx * dx + dy * dy,
  84. r = r1 - rc,
  85. D = x11 * y10 - x10 * y11,
  86. d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
  87. cx0 = (D * dy - dx * d) / d2,
  88. cy0 = (-D * dx - dy * d) / d2,
  89. cx1 = (D * dy + dx * d) / d2,
  90. cy1 = (-D * dx + dy * d) / d2,
  91. dx0 = cx0 - x00,
  92. dy0 = cy0 - y00,
  93. dx1 = cx1 - x00,
  94. dy1 = cy1 - y00;
  95. // Pick the closer of the two intersection points.
  96. // TODO Is there a faster way to determine which intersection to use?
  97. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  98. return {
  99. cx: cx0,
  100. cy: cy0,
  101. x01: -ox,
  102. y01: -oy,
  103. x11: cx0 * (r1 / r - 1),
  104. y11: cy0 * (r1 / r - 1)
  105. };
  106. }
  107. function arc() {
  108. var innerRadius = arcInnerRadius,
  109. outerRadius = arcOuterRadius,
  110. cornerRadius = constant(0),
  111. padRadius = null,
  112. startAngle = arcStartAngle,
  113. endAngle = arcEndAngle,
  114. padAngle = arcPadAngle,
  115. context = null,
  116. path = withPath(arc);
  117. function arc() {
  118. var buffer,
  119. r,
  120. r0 = +innerRadius.apply(this, arguments),
  121. r1 = +outerRadius.apply(this, arguments),
  122. a0 = startAngle.apply(this, arguments) - halfPi,
  123. a1 = endAngle.apply(this, arguments) - halfPi,
  124. da = abs(a1 - a0),
  125. cw = a1 > a0;
  126. if (!context) context = buffer = path();
  127. // Ensure that the outer radius is always larger than the inner radius.
  128. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  129. // Is it a point?
  130. if (!(r1 > epsilon)) context.moveTo(0, 0);
  131. // Or is it a circle or annulus?
  132. else if (da > tau - epsilon) {
  133. context.moveTo(r1 * cos(a0), r1 * sin(a0));
  134. context.arc(0, 0, r1, a0, a1, !cw);
  135. if (r0 > epsilon) {
  136. context.moveTo(r0 * cos(a1), r0 * sin(a1));
  137. context.arc(0, 0, r0, a1, a0, cw);
  138. }
  139. }
  140. // Or is it a circular or annular sector?
  141. else {
  142. var a01 = a0,
  143. a11 = a1,
  144. a00 = a0,
  145. a10 = a1,
  146. da0 = da,
  147. da1 = da,
  148. ap = padAngle.apply(this, arguments) / 2,
  149. rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
  150. rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  151. rc0 = rc,
  152. rc1 = rc,
  153. t0,
  154. t1;
  155. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  156. if (rp > epsilon) {
  157. var p0 = asin(rp / r0 * sin(ap)),
  158. p1 = asin(rp / r1 * sin(ap));
  159. if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  160. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  161. if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  162. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  163. }
  164. var x01 = r1 * cos(a01),
  165. y01 = r1 * sin(a01),
  166. x10 = r0 * cos(a10),
  167. y10 = r0 * sin(a10);
  168. // Apply rounded corners?
  169. if (rc > epsilon) {
  170. var x11 = r1 * cos(a11),
  171. y11 = r1 * sin(a11),
  172. x00 = r0 * cos(a00),
  173. y00 = r0 * sin(a00),
  174. oc;
  175. // Restrict the corner radius according to the sector angle. If this
  176. // intersection fails, it’s probably because the arc is too small, so
  177. // disable the corner radius entirely.
  178. if (da < pi) {
  179. if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
  180. var ax = x01 - oc[0],
  181. ay = y01 - oc[1],
  182. bx = x11 - oc[0],
  183. by = y11 - oc[1],
  184. kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
  185. lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  186. rc0 = min(rc, (r0 - lc) / (kc - 1));
  187. rc1 = min(rc, (r1 - lc) / (kc + 1));
  188. } else {
  189. rc0 = rc1 = 0;
  190. }
  191. }
  192. }
  193. // Is the sector collapsed to a line?
  194. if (!(da1 > epsilon)) context.moveTo(x01, y01);
  195. // Does the sector’s outer ring have rounded corners?
  196. else if (rc1 > epsilon) {
  197. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  198. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  199. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  200. // Have the corners merged?
  201. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  202. // Otherwise, draw the two corners and the ring.
  203. else {
  204. context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  205. context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  206. context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  207. }
  208. }
  209. // Or is the outer ring just a circular arc?
  210. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  211. // Is there no inner ring, and it’s a circular sector?
  212. // Or perhaps it’s an annular sector collapsed due to padding?
  213. if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
  214. // Does the sector’s inner ring (or point) have rounded corners?
  215. else if (rc0 > epsilon) {
  216. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  217. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  218. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  219. // Have the corners merged?
  220. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  221. // Otherwise, draw the two corners and the ring.
  222. else {
  223. context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  224. context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  225. context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  226. }
  227. }
  228. // Or is the inner ring just a circular arc?
  229. else context.arc(0, 0, r0, a10, a00, cw);
  230. }
  231. context.closePath();
  232. if (buffer) return context = null, buffer + "" || null;
  233. }
  234. arc.centroid = function() {
  235. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  236. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
  237. return [cos(a) * r, sin(a) * r];
  238. };
  239. arc.innerRadius = function(_) {
  240. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant(+_), arc) : innerRadius;
  241. };
  242. arc.outerRadius = function(_) {
  243. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant(+_), arc) : outerRadius;
  244. };
  245. arc.cornerRadius = function(_) {
  246. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant(+_), arc) : cornerRadius;
  247. };
  248. arc.padRadius = function(_) {
  249. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant(+_), arc) : padRadius;
  250. };
  251. arc.startAngle = function(_) {
  252. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), arc) : startAngle;
  253. };
  254. arc.endAngle = function(_) {
  255. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), arc) : endAngle;
  256. };
  257. arc.padAngle = function(_) {
  258. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), arc) : padAngle;
  259. };
  260. arc.context = function(_) {
  261. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  262. };
  263. return arc;
  264. }
  265. var slice = Array.prototype.slice;
  266. function array(x) {
  267. return typeof x === "object" && "length" in x
  268. ? x // Array, TypedArray, NodeList, array-like
  269. : Array.from(x); // Map, Set, iterable, string, or anything else
  270. }
  271. function Linear(context) {
  272. this._context = context;
  273. }
  274. Linear.prototype = {
  275. areaStart: function() {
  276. this._line = 0;
  277. },
  278. areaEnd: function() {
  279. this._line = NaN;
  280. },
  281. lineStart: function() {
  282. this._point = 0;
  283. },
  284. lineEnd: function() {
  285. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  286. this._line = 1 - this._line;
  287. },
  288. point: function(x, y) {
  289. x = +x, y = +y;
  290. switch (this._point) {
  291. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  292. case 1: this._point = 2; // falls through
  293. default: this._context.lineTo(x, y); break;
  294. }
  295. }
  296. };
  297. function curveLinear(context) {
  298. return new Linear(context);
  299. }
  300. function x(p) {
  301. return p[0];
  302. }
  303. function y(p) {
  304. return p[1];
  305. }
  306. function line(x$1, y$1) {
  307. var defined = constant(true),
  308. context = null,
  309. curve = curveLinear,
  310. output = null,
  311. path = withPath(line);
  312. x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant(x$1);
  313. y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant(y$1);
  314. function line(data) {
  315. var i,
  316. n = (data = array(data)).length,
  317. d,
  318. defined0 = false,
  319. buffer;
  320. if (context == null) output = curve(buffer = path());
  321. for (i = 0; i <= n; ++i) {
  322. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  323. if (defined0 = !defined0) output.lineStart();
  324. else output.lineEnd();
  325. }
  326. if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
  327. }
  328. if (buffer) return output = null, buffer + "" || null;
  329. }
  330. line.x = function(_) {
  331. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant(+_), line) : x$1;
  332. };
  333. line.y = function(_) {
  334. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant(+_), line) : y$1;
  335. };
  336. line.defined = function(_) {
  337. return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined;
  338. };
  339. line.curve = function(_) {
  340. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  341. };
  342. line.context = function(_) {
  343. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  344. };
  345. return line;
  346. }
  347. function area(x0, y0, y1) {
  348. var x1 = null,
  349. defined = constant(true),
  350. context = null,
  351. curve = curveLinear,
  352. output = null,
  353. path = withPath(area);
  354. x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant(+x0);
  355. y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant(0) : constant(+y0);
  356. y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant(+y1);
  357. function area(data) {
  358. var i,
  359. j,
  360. k,
  361. n = (data = array(data)).length,
  362. d,
  363. defined0 = false,
  364. buffer,
  365. x0z = new Array(n),
  366. y0z = new Array(n);
  367. if (context == null) output = curve(buffer = path());
  368. for (i = 0; i <= n; ++i) {
  369. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  370. if (defined0 = !defined0) {
  371. j = i;
  372. output.areaStart();
  373. output.lineStart();
  374. } else {
  375. output.lineEnd();
  376. output.lineStart();
  377. for (k = i - 1; k >= j; --k) {
  378. output.point(x0z[k], y0z[k]);
  379. }
  380. output.lineEnd();
  381. output.areaEnd();
  382. }
  383. }
  384. if (defined0) {
  385. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  386. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  387. }
  388. }
  389. if (buffer) return output = null, buffer + "" || null;
  390. }
  391. function arealine() {
  392. return line().defined(defined).curve(curve).context(context);
  393. }
  394. area.x = function(_) {
  395. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant(+_), x1 = null, area) : x0;
  396. };
  397. area.x0 = function(_) {
  398. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant(+_), area) : x0;
  399. };
  400. area.x1 = function(_) {
  401. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant(+_), area) : x1;
  402. };
  403. area.y = function(_) {
  404. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant(+_), y1 = null, area) : y0;
  405. };
  406. area.y0 = function(_) {
  407. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant(+_), area) : y0;
  408. };
  409. area.y1 = function(_) {
  410. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant(+_), area) : y1;
  411. };
  412. area.lineX0 =
  413. area.lineY0 = function() {
  414. return arealine().x(x0).y(y0);
  415. };
  416. area.lineY1 = function() {
  417. return arealine().x(x0).y(y1);
  418. };
  419. area.lineX1 = function() {
  420. return arealine().x(x1).y(y0);
  421. };
  422. area.defined = function(_) {
  423. return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), area) : defined;
  424. };
  425. area.curve = function(_) {
  426. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  427. };
  428. area.context = function(_) {
  429. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  430. };
  431. return area;
  432. }
  433. function descending$1(a, b) {
  434. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  435. }
  436. function identity(d) {
  437. return d;
  438. }
  439. function pie() {
  440. var value = identity,
  441. sortValues = descending$1,
  442. sort = null,
  443. startAngle = constant(0),
  444. endAngle = constant(tau),
  445. padAngle = constant(0);
  446. function pie(data) {
  447. var i,
  448. n = (data = array(data)).length,
  449. j,
  450. k,
  451. sum = 0,
  452. index = new Array(n),
  453. arcs = new Array(n),
  454. a0 = +startAngle.apply(this, arguments),
  455. da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
  456. a1,
  457. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  458. pa = p * (da < 0 ? -1 : 1),
  459. v;
  460. for (i = 0; i < n; ++i) {
  461. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  462. sum += v;
  463. }
  464. }
  465. // Optionally sort the arcs by previously-computed values or by data.
  466. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  467. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  468. // Compute the arcs! They are stored in the original data's order.
  469. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  470. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  471. data: data[j],
  472. index: i,
  473. value: v,
  474. startAngle: a0,
  475. endAngle: a1,
  476. padAngle: p
  477. };
  478. }
  479. return arcs;
  480. }
  481. pie.value = function(_) {
  482. return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), pie) : value;
  483. };
  484. pie.sortValues = function(_) {
  485. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  486. };
  487. pie.sort = function(_) {
  488. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  489. };
  490. pie.startAngle = function(_) {
  491. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), pie) : startAngle;
  492. };
  493. pie.endAngle = function(_) {
  494. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), pie) : endAngle;
  495. };
  496. pie.padAngle = function(_) {
  497. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), pie) : padAngle;
  498. };
  499. return pie;
  500. }
  501. var curveRadialLinear = curveRadial(curveLinear);
  502. function Radial(curve) {
  503. this._curve = curve;
  504. }
  505. Radial.prototype = {
  506. areaStart: function() {
  507. this._curve.areaStart();
  508. },
  509. areaEnd: function() {
  510. this._curve.areaEnd();
  511. },
  512. lineStart: function() {
  513. this._curve.lineStart();
  514. },
  515. lineEnd: function() {
  516. this._curve.lineEnd();
  517. },
  518. point: function(a, r) {
  519. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  520. }
  521. };
  522. function curveRadial(curve) {
  523. function radial(context) {
  524. return new Radial(curve(context));
  525. }
  526. radial._curve = curve;
  527. return radial;
  528. }
  529. function lineRadial(l) {
  530. var c = l.curve;
  531. l.angle = l.x, delete l.x;
  532. l.radius = l.y, delete l.y;
  533. l.curve = function(_) {
  534. return arguments.length ? c(curveRadial(_)) : c()._curve;
  535. };
  536. return l;
  537. }
  538. function lineRadial$1() {
  539. return lineRadial(line().curve(curveRadialLinear));
  540. }
  541. function areaRadial() {
  542. var a = area().curve(curveRadialLinear),
  543. c = a.curve,
  544. x0 = a.lineX0,
  545. x1 = a.lineX1,
  546. y0 = a.lineY0,
  547. y1 = a.lineY1;
  548. a.angle = a.x, delete a.x;
  549. a.startAngle = a.x0, delete a.x0;
  550. a.endAngle = a.x1, delete a.x1;
  551. a.radius = a.y, delete a.y;
  552. a.innerRadius = a.y0, delete a.y0;
  553. a.outerRadius = a.y1, delete a.y1;
  554. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  555. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  556. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  557. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  558. a.curve = function(_) {
  559. return arguments.length ? c(curveRadial(_)) : c()._curve;
  560. };
  561. return a;
  562. }
  563. function pointRadial(x, y) {
  564. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  565. }
  566. class Bump {
  567. constructor(context, x) {
  568. this._context = context;
  569. this._x = x;
  570. }
  571. areaStart() {
  572. this._line = 0;
  573. }
  574. areaEnd() {
  575. this._line = NaN;
  576. }
  577. lineStart() {
  578. this._point = 0;
  579. }
  580. lineEnd() {
  581. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  582. this._line = 1 - this._line;
  583. }
  584. point(x, y) {
  585. x = +x, y = +y;
  586. switch (this._point) {
  587. case 0: {
  588. this._point = 1;
  589. if (this._line) this._context.lineTo(x, y);
  590. else this._context.moveTo(x, y);
  591. break;
  592. }
  593. case 1: this._point = 2; // falls through
  594. default: {
  595. if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
  596. else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
  597. break;
  598. }
  599. }
  600. this._x0 = x, this._y0 = y;
  601. }
  602. }
  603. class BumpRadial {
  604. constructor(context) {
  605. this._context = context;
  606. }
  607. lineStart() {
  608. this._point = 0;
  609. }
  610. lineEnd() {}
  611. point(x, y) {
  612. x = +x, y = +y;
  613. if (this._point === 0) {
  614. this._point = 1;
  615. } else {
  616. const p0 = pointRadial(this._x0, this._y0);
  617. const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
  618. const p2 = pointRadial(x, this._y0);
  619. const p3 = pointRadial(x, y);
  620. this._context.moveTo(...p0);
  621. this._context.bezierCurveTo(...p1, ...p2, ...p3);
  622. }
  623. this._x0 = x, this._y0 = y;
  624. }
  625. }
  626. function bumpX(context) {
  627. return new Bump(context, true);
  628. }
  629. function bumpY(context) {
  630. return new Bump(context, false);
  631. }
  632. function bumpRadial(context) {
  633. return new BumpRadial(context);
  634. }
  635. function linkSource(d) {
  636. return d.source;
  637. }
  638. function linkTarget(d) {
  639. return d.target;
  640. }
  641. function link(curve) {
  642. let source = linkSource,
  643. target = linkTarget,
  644. x$1 = x,
  645. y$1 = y,
  646. context = null,
  647. output = null,
  648. path = withPath(link);
  649. function link() {
  650. let buffer;
  651. const argv = slice.call(arguments);
  652. const s = source.apply(this, argv);
  653. const t = target.apply(this, argv);
  654. if (context == null) output = curve(buffer = path());
  655. output.lineStart();
  656. argv[0] = s, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  657. argv[0] = t, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  658. output.lineEnd();
  659. if (buffer) return output = null, buffer + "" || null;
  660. }
  661. link.source = function(_) {
  662. return arguments.length ? (source = _, link) : source;
  663. };
  664. link.target = function(_) {
  665. return arguments.length ? (target = _, link) : target;
  666. };
  667. link.x = function(_) {
  668. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant(+_), link) : x$1;
  669. };
  670. link.y = function(_) {
  671. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant(+_), link) : y$1;
  672. };
  673. link.context = function(_) {
  674. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
  675. };
  676. return link;
  677. }
  678. function linkHorizontal() {
  679. return link(bumpX);
  680. }
  681. function linkVertical() {
  682. return link(bumpY);
  683. }
  684. function linkRadial() {
  685. const l = link(bumpRadial);
  686. l.angle = l.x, delete l.x;
  687. l.radius = l.y, delete l.y;
  688. return l;
  689. }
  690. const sqrt3$2 = sqrt(3);
  691. var asterisk = {
  692. draw(context, size) {
  693. const r = sqrt(size + min(size / 28, 0.75)) * 0.59436;
  694. const t = r / 2;
  695. const u = t * sqrt3$2;
  696. context.moveTo(0, r);
  697. context.lineTo(0, -r);
  698. context.moveTo(-u, -t);
  699. context.lineTo(u, t);
  700. context.moveTo(-u, t);
  701. context.lineTo(u, -t);
  702. }
  703. };
  704. var circle = {
  705. draw(context, size) {
  706. const r = sqrt(size / pi);
  707. context.moveTo(r, 0);
  708. context.arc(0, 0, r, 0, tau);
  709. }
  710. };
  711. var cross = {
  712. draw(context, size) {
  713. const r = sqrt(size / 5) / 2;
  714. context.moveTo(-3 * r, -r);
  715. context.lineTo(-r, -r);
  716. context.lineTo(-r, -3 * r);
  717. context.lineTo(r, -3 * r);
  718. context.lineTo(r, -r);
  719. context.lineTo(3 * r, -r);
  720. context.lineTo(3 * r, r);
  721. context.lineTo(r, r);
  722. context.lineTo(r, 3 * r);
  723. context.lineTo(-r, 3 * r);
  724. context.lineTo(-r, r);
  725. context.lineTo(-3 * r, r);
  726. context.closePath();
  727. }
  728. };
  729. const tan30 = sqrt(1 / 3);
  730. const tan30_2 = tan30 * 2;
  731. var diamond = {
  732. draw(context, size) {
  733. const y = sqrt(size / tan30_2);
  734. const x = y * tan30;
  735. context.moveTo(0, -y);
  736. context.lineTo(x, 0);
  737. context.lineTo(0, y);
  738. context.lineTo(-x, 0);
  739. context.closePath();
  740. }
  741. };
  742. var diamond2 = {
  743. draw(context, size) {
  744. const r = sqrt(size) * 0.62625;
  745. context.moveTo(0, -r);
  746. context.lineTo(r, 0);
  747. context.lineTo(0, r);
  748. context.lineTo(-r, 0);
  749. context.closePath();
  750. }
  751. };
  752. var plus = {
  753. draw(context, size) {
  754. const r = sqrt(size - min(size / 7, 2)) * 0.87559;
  755. context.moveTo(-r, 0);
  756. context.lineTo(r, 0);
  757. context.moveTo(0, r);
  758. context.lineTo(0, -r);
  759. }
  760. };
  761. var square = {
  762. draw(context, size) {
  763. const w = sqrt(size);
  764. const x = -w / 2;
  765. context.rect(x, x, w, w);
  766. }
  767. };
  768. var square2 = {
  769. draw(context, size) {
  770. const r = sqrt(size) * 0.4431;
  771. context.moveTo(r, r);
  772. context.lineTo(r, -r);
  773. context.lineTo(-r, -r);
  774. context.lineTo(-r, r);
  775. context.closePath();
  776. }
  777. };
  778. const ka = 0.89081309152928522810;
  779. const kr = sin(pi / 10) / sin(7 * pi / 10);
  780. const kx = sin(tau / 10) * kr;
  781. const ky = -cos(tau / 10) * kr;
  782. var star = {
  783. draw(context, size) {
  784. const r = sqrt(size * ka);
  785. const x = kx * r;
  786. const y = ky * r;
  787. context.moveTo(0, -r);
  788. context.lineTo(x, y);
  789. for (let i = 1; i < 5; ++i) {
  790. const a = tau * i / 5;
  791. const c = cos(a);
  792. const s = sin(a);
  793. context.lineTo(s * r, -c * r);
  794. context.lineTo(c * x - s * y, s * x + c * y);
  795. }
  796. context.closePath();
  797. }
  798. };
  799. const sqrt3$1 = sqrt(3);
  800. var triangle = {
  801. draw(context, size) {
  802. const y = -sqrt(size / (sqrt3$1 * 3));
  803. context.moveTo(0, y * 2);
  804. context.lineTo(-sqrt3$1 * y, -y);
  805. context.lineTo(sqrt3$1 * y, -y);
  806. context.closePath();
  807. }
  808. };
  809. const sqrt3 = sqrt(3);
  810. var triangle2 = {
  811. draw(context, size) {
  812. const s = sqrt(size) * 0.6824;
  813. const t = s / 2;
  814. const u = (s * sqrt3) / 2; // cos(Math.PI / 6)
  815. context.moveTo(0, -s);
  816. context.lineTo(u, t);
  817. context.lineTo(-u, t);
  818. context.closePath();
  819. }
  820. };
  821. const c = -0.5;
  822. const s = sqrt(3) / 2;
  823. const k = 1 / sqrt(12);
  824. const a = (k / 2 + 1) * 3;
  825. var wye = {
  826. draw(context, size) {
  827. const r = sqrt(size / a);
  828. const x0 = r / 2, y0 = r * k;
  829. const x1 = x0, y1 = r * k + r;
  830. const x2 = -x1, y2 = y1;
  831. context.moveTo(x0, y0);
  832. context.lineTo(x1, y1);
  833. context.lineTo(x2, y2);
  834. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  835. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  836. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  837. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  838. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  839. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  840. context.closePath();
  841. }
  842. };
  843. var times = {
  844. draw(context, size) {
  845. const r = sqrt(size - min(size / 6, 1.7)) * 0.6189;
  846. context.moveTo(-r, -r);
  847. context.lineTo(r, r);
  848. context.moveTo(-r, r);
  849. context.lineTo(r, -r);
  850. }
  851. };
  852. // These symbols are designed to be filled.
  853. const symbolsFill = [
  854. circle,
  855. cross,
  856. diamond,
  857. square,
  858. star,
  859. triangle,
  860. wye
  861. ];
  862. // These symbols are designed to be stroked (with a width of 1.5px and round caps).
  863. const symbolsStroke = [
  864. circle,
  865. plus,
  866. times,
  867. triangle2,
  868. asterisk,
  869. square2,
  870. diamond2
  871. ];
  872. function Symbol(type, size) {
  873. let context = null,
  874. path = withPath(symbol);
  875. type = typeof type === "function" ? type : constant(type || circle);
  876. size = typeof size === "function" ? size : constant(size === undefined ? 64 : +size);
  877. function symbol() {
  878. let buffer;
  879. if (!context) context = buffer = path();
  880. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  881. if (buffer) return context = null, buffer + "" || null;
  882. }
  883. symbol.type = function(_) {
  884. return arguments.length ? (type = typeof _ === "function" ? _ : constant(_), symbol) : type;
  885. };
  886. symbol.size = function(_) {
  887. return arguments.length ? (size = typeof _ === "function" ? _ : constant(+_), symbol) : size;
  888. };
  889. symbol.context = function(_) {
  890. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  891. };
  892. return symbol;
  893. }
  894. function noop() {}
  895. function point$3(that, x, y) {
  896. that._context.bezierCurveTo(
  897. (2 * that._x0 + that._x1) / 3,
  898. (2 * that._y0 + that._y1) / 3,
  899. (that._x0 + 2 * that._x1) / 3,
  900. (that._y0 + 2 * that._y1) / 3,
  901. (that._x0 + 4 * that._x1 + x) / 6,
  902. (that._y0 + 4 * that._y1 + y) / 6
  903. );
  904. }
  905. function Basis(context) {
  906. this._context = context;
  907. }
  908. Basis.prototype = {
  909. areaStart: function() {
  910. this._line = 0;
  911. },
  912. areaEnd: function() {
  913. this._line = NaN;
  914. },
  915. lineStart: function() {
  916. this._x0 = this._x1 =
  917. this._y0 = this._y1 = NaN;
  918. this._point = 0;
  919. },
  920. lineEnd: function() {
  921. switch (this._point) {
  922. case 3: point$3(this, this._x1, this._y1); // falls through
  923. case 2: this._context.lineTo(this._x1, this._y1); break;
  924. }
  925. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  926. this._line = 1 - this._line;
  927. },
  928. point: function(x, y) {
  929. x = +x, y = +y;
  930. switch (this._point) {
  931. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  932. case 1: this._point = 2; break;
  933. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
  934. default: point$3(this, x, y); break;
  935. }
  936. this._x0 = this._x1, this._x1 = x;
  937. this._y0 = this._y1, this._y1 = y;
  938. }
  939. };
  940. function basis(context) {
  941. return new Basis(context);
  942. }
  943. function BasisClosed(context) {
  944. this._context = context;
  945. }
  946. BasisClosed.prototype = {
  947. areaStart: noop,
  948. areaEnd: noop,
  949. lineStart: function() {
  950. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  951. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  952. this._point = 0;
  953. },
  954. lineEnd: function() {
  955. switch (this._point) {
  956. case 1: {
  957. this._context.moveTo(this._x2, this._y2);
  958. this._context.closePath();
  959. break;
  960. }
  961. case 2: {
  962. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  963. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  964. this._context.closePath();
  965. break;
  966. }
  967. case 3: {
  968. this.point(this._x2, this._y2);
  969. this.point(this._x3, this._y3);
  970. this.point(this._x4, this._y4);
  971. break;
  972. }
  973. }
  974. },
  975. point: function(x, y) {
  976. x = +x, y = +y;
  977. switch (this._point) {
  978. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  979. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  980. case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
  981. default: point$3(this, x, y); break;
  982. }
  983. this._x0 = this._x1, this._x1 = x;
  984. this._y0 = this._y1, this._y1 = y;
  985. }
  986. };
  987. function basisClosed(context) {
  988. return new BasisClosed(context);
  989. }
  990. function BasisOpen(context) {
  991. this._context = context;
  992. }
  993. BasisOpen.prototype = {
  994. areaStart: function() {
  995. this._line = 0;
  996. },
  997. areaEnd: function() {
  998. this._line = NaN;
  999. },
  1000. lineStart: function() {
  1001. this._x0 = this._x1 =
  1002. this._y0 = this._y1 = NaN;
  1003. this._point = 0;
  1004. },
  1005. lineEnd: function() {
  1006. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  1007. this._line = 1 - this._line;
  1008. },
  1009. point: function(x, y) {
  1010. x = +x, y = +y;
  1011. switch (this._point) {
  1012. case 0: this._point = 1; break;
  1013. case 1: this._point = 2; break;
  1014. case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
  1015. case 3: this._point = 4; // falls through
  1016. default: point$3(this, x, y); break;
  1017. }
  1018. this._x0 = this._x1, this._x1 = x;
  1019. this._y0 = this._y1, this._y1 = y;
  1020. }
  1021. };
  1022. function basisOpen(context) {
  1023. return new BasisOpen(context);
  1024. }
  1025. function Bundle(context, beta) {
  1026. this._basis = new Basis(context);
  1027. this._beta = beta;
  1028. }
  1029. Bundle.prototype = {
  1030. lineStart: function() {
  1031. this._x = [];
  1032. this._y = [];
  1033. this._basis.lineStart();
  1034. },
  1035. lineEnd: function() {
  1036. var x = this._x,
  1037. y = this._y,
  1038. j = x.length - 1;
  1039. if (j > 0) {
  1040. var x0 = x[0],
  1041. y0 = y[0],
  1042. dx = x[j] - x0,
  1043. dy = y[j] - y0,
  1044. i = -1,
  1045. t;
  1046. while (++i <= j) {
  1047. t = i / j;
  1048. this._basis.point(
  1049. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  1050. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  1051. );
  1052. }
  1053. }
  1054. this._x = this._y = null;
  1055. this._basis.lineEnd();
  1056. },
  1057. point: function(x, y) {
  1058. this._x.push(+x);
  1059. this._y.push(+y);
  1060. }
  1061. };
  1062. var bundle = (function custom(beta) {
  1063. function bundle(context) {
  1064. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  1065. }
  1066. bundle.beta = function(beta) {
  1067. return custom(+beta);
  1068. };
  1069. return bundle;
  1070. })(0.85);
  1071. function point$2(that, x, y) {
  1072. that._context.bezierCurveTo(
  1073. that._x1 + that._k * (that._x2 - that._x0),
  1074. that._y1 + that._k * (that._y2 - that._y0),
  1075. that._x2 + that._k * (that._x1 - x),
  1076. that._y2 + that._k * (that._y1 - y),
  1077. that._x2,
  1078. that._y2
  1079. );
  1080. }
  1081. function Cardinal(context, tension) {
  1082. this._context = context;
  1083. this._k = (1 - tension) / 6;
  1084. }
  1085. Cardinal.prototype = {
  1086. areaStart: function() {
  1087. this._line = 0;
  1088. },
  1089. areaEnd: function() {
  1090. this._line = NaN;
  1091. },
  1092. lineStart: function() {
  1093. this._x0 = this._x1 = this._x2 =
  1094. this._y0 = this._y1 = this._y2 = NaN;
  1095. this._point = 0;
  1096. },
  1097. lineEnd: function() {
  1098. switch (this._point) {
  1099. case 2: this._context.lineTo(this._x2, this._y2); break;
  1100. case 3: point$2(this, this._x1, this._y1); break;
  1101. }
  1102. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  1103. this._line = 1 - this._line;
  1104. },
  1105. point: function(x, y) {
  1106. x = +x, y = +y;
  1107. switch (this._point) {
  1108. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  1109. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  1110. case 2: this._point = 3; // falls through
  1111. default: point$2(this, x, y); break;
  1112. }
  1113. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  1114. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  1115. }
  1116. };
  1117. var cardinal = (function custom(tension) {
  1118. function cardinal(context) {
  1119. return new Cardinal(context, tension);
  1120. }
  1121. cardinal.tension = function(tension) {
  1122. return custom(+tension);
  1123. };
  1124. return cardinal;
  1125. })(0);
  1126. function CardinalClosed(context, tension) {
  1127. this._context = context;
  1128. this._k = (1 - tension) / 6;
  1129. }
  1130. CardinalClosed.prototype = {
  1131. areaStart: noop,
  1132. areaEnd: noop,
  1133. lineStart: function() {
  1134. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  1135. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  1136. this._point = 0;
  1137. },
  1138. lineEnd: function() {
  1139. switch (this._point) {
  1140. case 1: {
  1141. this._context.moveTo(this._x3, this._y3);
  1142. this._context.closePath();
  1143. break;
  1144. }
  1145. case 2: {
  1146. this._context.lineTo(this._x3, this._y3);
  1147. this._context.closePath();
  1148. break;
  1149. }
  1150. case 3: {
  1151. this.point(this._x3, this._y3);
  1152. this.point(this._x4, this._y4);
  1153. this.point(this._x5, this._y5);
  1154. break;
  1155. }
  1156. }
  1157. },
  1158. point: function(x, y) {
  1159. x = +x, y = +y;
  1160. switch (this._point) {
  1161. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  1162. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  1163. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  1164. default: point$2(this, x, y); break;
  1165. }
  1166. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  1167. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  1168. }
  1169. };
  1170. var cardinalClosed = (function custom(tension) {
  1171. function cardinal(context) {
  1172. return new CardinalClosed(context, tension);
  1173. }
  1174. cardinal.tension = function(tension) {
  1175. return custom(+tension);
  1176. };
  1177. return cardinal;
  1178. })(0);
  1179. function CardinalOpen(context, tension) {
  1180. this._context = context;
  1181. this._k = (1 - tension) / 6;
  1182. }
  1183. CardinalOpen.prototype = {
  1184. areaStart: function() {
  1185. this._line = 0;
  1186. },
  1187. areaEnd: function() {
  1188. this._line = NaN;
  1189. },
  1190. lineStart: function() {
  1191. this._x0 = this._x1 = this._x2 =
  1192. this._y0 = this._y1 = this._y2 = NaN;
  1193. this._point = 0;
  1194. },
  1195. lineEnd: function() {
  1196. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  1197. this._line = 1 - this._line;
  1198. },
  1199. point: function(x, y) {
  1200. x = +x, y = +y;
  1201. switch (this._point) {
  1202. case 0: this._point = 1; break;
  1203. case 1: this._point = 2; break;
  1204. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  1205. case 3: this._point = 4; // falls through
  1206. default: point$2(this, x, y); break;
  1207. }
  1208. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  1209. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  1210. }
  1211. };
  1212. var cardinalOpen = (function custom(tension) {
  1213. function cardinal(context) {
  1214. return new CardinalOpen(context, tension);
  1215. }
  1216. cardinal.tension = function(tension) {
  1217. return custom(+tension);
  1218. };
  1219. return cardinal;
  1220. })(0);
  1221. function point$1(that, x, y) {
  1222. var x1 = that._x1,
  1223. y1 = that._y1,
  1224. x2 = that._x2,
  1225. y2 = that._y2;
  1226. if (that._l01_a > epsilon) {
  1227. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  1228. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  1229. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  1230. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  1231. }
  1232. if (that._l23_a > epsilon) {
  1233. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  1234. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  1235. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  1236. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  1237. }
  1238. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  1239. }
  1240. function CatmullRom(context, alpha) {
  1241. this._context = context;
  1242. this._alpha = alpha;
  1243. }
  1244. CatmullRom.prototype = {
  1245. areaStart: function() {
  1246. this._line = 0;
  1247. },
  1248. areaEnd: function() {
  1249. this._line = NaN;
  1250. },
  1251. lineStart: function() {
  1252. this._x0 = this._x1 = this._x2 =
  1253. this._y0 = this._y1 = this._y2 = NaN;
  1254. this._l01_a = this._l12_a = this._l23_a =
  1255. this._l01_2a = this._l12_2a = this._l23_2a =
  1256. this._point = 0;
  1257. },
  1258. lineEnd: function() {
  1259. switch (this._point) {
  1260. case 2: this._context.lineTo(this._x2, this._y2); break;
  1261. case 3: this.point(this._x2, this._y2); break;
  1262. }
  1263. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  1264. this._line = 1 - this._line;
  1265. },
  1266. point: function(x, y) {
  1267. x = +x, y = +y;
  1268. if (this._point) {
  1269. var x23 = this._x2 - x,
  1270. y23 = this._y2 - y;
  1271. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  1272. }
  1273. switch (this._point) {
  1274. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  1275. case 1: this._point = 2; break;
  1276. case 2: this._point = 3; // falls through
  1277. default: point$1(this, x, y); break;
  1278. }
  1279. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  1280. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  1281. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  1282. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  1283. }
  1284. };
  1285. var catmullRom = (function custom(alpha) {
  1286. function catmullRom(context) {
  1287. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  1288. }
  1289. catmullRom.alpha = function(alpha) {
  1290. return custom(+alpha);
  1291. };
  1292. return catmullRom;
  1293. })(0.5);
  1294. function CatmullRomClosed(context, alpha) {
  1295. this._context = context;
  1296. this._alpha = alpha;
  1297. }
  1298. CatmullRomClosed.prototype = {
  1299. areaStart: noop,
  1300. areaEnd: noop,
  1301. lineStart: function() {
  1302. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  1303. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  1304. this._l01_a = this._l12_a = this._l23_a =
  1305. this._l01_2a = this._l12_2a = this._l23_2a =
  1306. this._point = 0;
  1307. },
  1308. lineEnd: function() {
  1309. switch (this._point) {
  1310. case 1: {
  1311. this._context.moveTo(this._x3, this._y3);
  1312. this._context.closePath();
  1313. break;
  1314. }
  1315. case 2: {
  1316. this._context.lineTo(this._x3, this._y3);
  1317. this._context.closePath();
  1318. break;
  1319. }
  1320. case 3: {
  1321. this.point(this._x3, this._y3);
  1322. this.point(this._x4, this._y4);
  1323. this.point(this._x5, this._y5);
  1324. break;
  1325. }
  1326. }
  1327. },
  1328. point: function(x, y) {
  1329. x = +x, y = +y;
  1330. if (this._point) {
  1331. var x23 = this._x2 - x,
  1332. y23 = this._y2 - y;
  1333. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  1334. }
  1335. switch (this._point) {
  1336. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  1337. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  1338. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  1339. default: point$1(this, x, y); break;
  1340. }
  1341. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  1342. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  1343. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  1344. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  1345. }
  1346. };
  1347. var catmullRomClosed = (function custom(alpha) {
  1348. function catmullRom(context) {
  1349. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  1350. }
  1351. catmullRom.alpha = function(alpha) {
  1352. return custom(+alpha);
  1353. };
  1354. return catmullRom;
  1355. })(0.5);
  1356. function CatmullRomOpen(context, alpha) {
  1357. this._context = context;
  1358. this._alpha = alpha;
  1359. }
  1360. CatmullRomOpen.prototype = {
  1361. areaStart: function() {
  1362. this._line = 0;
  1363. },
  1364. areaEnd: function() {
  1365. this._line = NaN;
  1366. },
  1367. lineStart: function() {
  1368. this._x0 = this._x1 = this._x2 =
  1369. this._y0 = this._y1 = this._y2 = NaN;
  1370. this._l01_a = this._l12_a = this._l23_a =
  1371. this._l01_2a = this._l12_2a = this._l23_2a =
  1372. this._point = 0;
  1373. },
  1374. lineEnd: function() {
  1375. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  1376. this._line = 1 - this._line;
  1377. },
  1378. point: function(x, y) {
  1379. x = +x, y = +y;
  1380. if (this._point) {
  1381. var x23 = this._x2 - x,
  1382. y23 = this._y2 - y;
  1383. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  1384. }
  1385. switch (this._point) {
  1386. case 0: this._point = 1; break;
  1387. case 1: this._point = 2; break;
  1388. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  1389. case 3: this._point = 4; // falls through
  1390. default: point$1(this, x, y); break;
  1391. }
  1392. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  1393. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  1394. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  1395. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  1396. }
  1397. };
  1398. var catmullRomOpen = (function custom(alpha) {
  1399. function catmullRom(context) {
  1400. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  1401. }
  1402. catmullRom.alpha = function(alpha) {
  1403. return custom(+alpha);
  1404. };
  1405. return catmullRom;
  1406. })(0.5);
  1407. function LinearClosed(context) {
  1408. this._context = context;
  1409. }
  1410. LinearClosed.prototype = {
  1411. areaStart: noop,
  1412. areaEnd: noop,
  1413. lineStart: function() {
  1414. this._point = 0;
  1415. },
  1416. lineEnd: function() {
  1417. if (this._point) this._context.closePath();
  1418. },
  1419. point: function(x, y) {
  1420. x = +x, y = +y;
  1421. if (this._point) this._context.lineTo(x, y);
  1422. else this._point = 1, this._context.moveTo(x, y);
  1423. }
  1424. };
  1425. function linearClosed(context) {
  1426. return new LinearClosed(context);
  1427. }
  1428. function sign(x) {
  1429. return x < 0 ? -1 : 1;
  1430. }
  1431. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  1432. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  1433. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  1434. // NOV(II), P. 443, 1990.
  1435. function slope3(that, x2, y2) {
  1436. var h0 = that._x1 - that._x0,
  1437. h1 = x2 - that._x1,
  1438. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  1439. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  1440. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  1441. return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  1442. }
  1443. // Calculate a one-sided slope.
  1444. function slope2(that, t) {
  1445. var h = that._x1 - that._x0;
  1446. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  1447. }
  1448. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  1449. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  1450. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  1451. function point(that, t0, t1) {
  1452. var x0 = that._x0,
  1453. y0 = that._y0,
  1454. x1 = that._x1,
  1455. y1 = that._y1,
  1456. dx = (x1 - x0) / 3;
  1457. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  1458. }
  1459. function MonotoneX(context) {
  1460. this._context = context;
  1461. }
  1462. MonotoneX.prototype = {
  1463. areaStart: function() {
  1464. this._line = 0;
  1465. },
  1466. areaEnd: function() {
  1467. this._line = NaN;
  1468. },
  1469. lineStart: function() {
  1470. this._x0 = this._x1 =
  1471. this._y0 = this._y1 =
  1472. this._t0 = NaN;
  1473. this._point = 0;
  1474. },
  1475. lineEnd: function() {
  1476. switch (this._point) {
  1477. case 2: this._context.lineTo(this._x1, this._y1); break;
  1478. case 3: point(this, this._t0, slope2(this, this._t0)); break;
  1479. }
  1480. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  1481. this._line = 1 - this._line;
  1482. },
  1483. point: function(x, y) {
  1484. var t1 = NaN;
  1485. x = +x, y = +y;
  1486. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  1487. switch (this._point) {
  1488. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  1489. case 1: this._point = 2; break;
  1490. case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  1491. default: point(this, this._t0, t1 = slope3(this, x, y)); break;
  1492. }
  1493. this._x0 = this._x1, this._x1 = x;
  1494. this._y0 = this._y1, this._y1 = y;
  1495. this._t0 = t1;
  1496. }
  1497. };
  1498. function MonotoneY(context) {
  1499. this._context = new ReflectContext(context);
  1500. }
  1501. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  1502. MonotoneX.prototype.point.call(this, y, x);
  1503. };
  1504. function ReflectContext(context) {
  1505. this._context = context;
  1506. }
  1507. ReflectContext.prototype = {
  1508. moveTo: function(x, y) { this._context.moveTo(y, x); },
  1509. closePath: function() { this._context.closePath(); },
  1510. lineTo: function(x, y) { this._context.lineTo(y, x); },
  1511. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  1512. };
  1513. function monotoneX(context) {
  1514. return new MonotoneX(context);
  1515. }
  1516. function monotoneY(context) {
  1517. return new MonotoneY(context);
  1518. }
  1519. function Natural(context) {
  1520. this._context = context;
  1521. }
  1522. Natural.prototype = {
  1523. areaStart: function() {
  1524. this._line = 0;
  1525. },
  1526. areaEnd: function() {
  1527. this._line = NaN;
  1528. },
  1529. lineStart: function() {
  1530. this._x = [];
  1531. this._y = [];
  1532. },
  1533. lineEnd: function() {
  1534. var x = this._x,
  1535. y = this._y,
  1536. n = x.length;
  1537. if (n) {
  1538. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  1539. if (n === 2) {
  1540. this._context.lineTo(x[1], y[1]);
  1541. } else {
  1542. var px = controlPoints(x),
  1543. py = controlPoints(y);
  1544. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  1545. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  1546. }
  1547. }
  1548. }
  1549. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  1550. this._line = 1 - this._line;
  1551. this._x = this._y = null;
  1552. },
  1553. point: function(x, y) {
  1554. this._x.push(+x);
  1555. this._y.push(+y);
  1556. }
  1557. };
  1558. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  1559. function controlPoints(x) {
  1560. var i,
  1561. n = x.length - 1,
  1562. m,
  1563. a = new Array(n),
  1564. b = new Array(n),
  1565. r = new Array(n);
  1566. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  1567. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  1568. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  1569. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  1570. a[n - 1] = r[n - 1] / b[n - 1];
  1571. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  1572. b[n - 1] = (x[n] + a[n - 1]) / 2;
  1573. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  1574. return [a, b];
  1575. }
  1576. function natural(context) {
  1577. return new Natural(context);
  1578. }
  1579. function Step(context, t) {
  1580. this._context = context;
  1581. this._t = t;
  1582. }
  1583. Step.prototype = {
  1584. areaStart: function() {
  1585. this._line = 0;
  1586. },
  1587. areaEnd: function() {
  1588. this._line = NaN;
  1589. },
  1590. lineStart: function() {
  1591. this._x = this._y = NaN;
  1592. this._point = 0;
  1593. },
  1594. lineEnd: function() {
  1595. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  1596. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  1597. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  1598. },
  1599. point: function(x, y) {
  1600. x = +x, y = +y;
  1601. switch (this._point) {
  1602. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  1603. case 1: this._point = 2; // falls through
  1604. default: {
  1605. if (this._t <= 0) {
  1606. this._context.lineTo(this._x, y);
  1607. this._context.lineTo(x, y);
  1608. } else {
  1609. var x1 = this._x * (1 - this._t) + x * this._t;
  1610. this._context.lineTo(x1, this._y);
  1611. this._context.lineTo(x1, y);
  1612. }
  1613. break;
  1614. }
  1615. }
  1616. this._x = x, this._y = y;
  1617. }
  1618. };
  1619. function step(context) {
  1620. return new Step(context, 0.5);
  1621. }
  1622. function stepBefore(context) {
  1623. return new Step(context, 0);
  1624. }
  1625. function stepAfter(context) {
  1626. return new Step(context, 1);
  1627. }
  1628. function none$1(series, order) {
  1629. if (!((n = series.length) > 1)) return;
  1630. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  1631. s0 = s1, s1 = series[order[i]];
  1632. for (j = 0; j < m; ++j) {
  1633. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  1634. }
  1635. }
  1636. }
  1637. function none(series) {
  1638. var n = series.length, o = new Array(n);
  1639. while (--n >= 0) o[n] = n;
  1640. return o;
  1641. }
  1642. function stackValue(d, key) {
  1643. return d[key];
  1644. }
  1645. function stackSeries(key) {
  1646. const series = [];
  1647. series.key = key;
  1648. return series;
  1649. }
  1650. function stack() {
  1651. var keys = constant([]),
  1652. order = none,
  1653. offset = none$1,
  1654. value = stackValue;
  1655. function stack(data) {
  1656. var sz = Array.from(keys.apply(this, arguments), stackSeries),
  1657. i, n = sz.length, j = -1,
  1658. oz;
  1659. for (const d of data) {
  1660. for (i = 0, ++j; i < n; ++i) {
  1661. (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
  1662. }
  1663. }
  1664. for (i = 0, oz = array(order(sz)); i < n; ++i) {
  1665. sz[oz[i]].index = i;
  1666. }
  1667. offset(sz, oz);
  1668. return sz;
  1669. }
  1670. stack.keys = function(_) {
  1671. return arguments.length ? (keys = typeof _ === "function" ? _ : constant(Array.from(_)), stack) : keys;
  1672. };
  1673. stack.value = function(_) {
  1674. return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), stack) : value;
  1675. };
  1676. stack.order = function(_) {
  1677. return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant(Array.from(_)), stack) : order;
  1678. };
  1679. stack.offset = function(_) {
  1680. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  1681. };
  1682. return stack;
  1683. }
  1684. function expand(series, order) {
  1685. if (!((n = series.length) > 0)) return;
  1686. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  1687. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  1688. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  1689. }
  1690. none$1(series, order);
  1691. }
  1692. function diverging(series, order) {
  1693. if (!((n = series.length) > 0)) return;
  1694. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  1695. for (yp = yn = 0, i = 0; i < n; ++i) {
  1696. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  1697. d[0] = yp, d[1] = yp += dy;
  1698. } else if (dy < 0) {
  1699. d[1] = yn, d[0] = yn += dy;
  1700. } else {
  1701. d[0] = 0, d[1] = dy;
  1702. }
  1703. }
  1704. }
  1705. }
  1706. function silhouette(series, order) {
  1707. if (!((n = series.length) > 0)) return;
  1708. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  1709. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  1710. s0[j][1] += s0[j][0] = -y / 2;
  1711. }
  1712. none$1(series, order);
  1713. }
  1714. function wiggle(series, order) {
  1715. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  1716. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  1717. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  1718. var si = series[order[i]],
  1719. sij0 = si[j][1] || 0,
  1720. sij1 = si[j - 1][1] || 0,
  1721. s3 = (sij0 - sij1) / 2;
  1722. for (var k = 0; k < i; ++k) {
  1723. var sk = series[order[k]],
  1724. skj0 = sk[j][1] || 0,
  1725. skj1 = sk[j - 1][1] || 0;
  1726. s3 += skj0 - skj1;
  1727. }
  1728. s1 += sij0, s2 += s3 * sij0;
  1729. }
  1730. s0[j - 1][1] += s0[j - 1][0] = y;
  1731. if (s1) y -= s2 / s1;
  1732. }
  1733. s0[j - 1][1] += s0[j - 1][0] = y;
  1734. none$1(series, order);
  1735. }
  1736. function appearance(series) {
  1737. var peaks = series.map(peak);
  1738. return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  1739. }
  1740. function peak(series) {
  1741. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  1742. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  1743. return j;
  1744. }
  1745. function ascending(series) {
  1746. var sums = series.map(sum);
  1747. return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
  1748. }
  1749. function sum(series) {
  1750. var s = 0, i = -1, n = series.length, v;
  1751. while (++i < n) if (v = +series[i][1]) s += v;
  1752. return s;
  1753. }
  1754. function descending(series) {
  1755. return ascending(series).reverse();
  1756. }
  1757. function insideOut(series) {
  1758. var n = series.length,
  1759. i,
  1760. j,
  1761. sums = series.map(sum),
  1762. order = appearance(series),
  1763. top = 0,
  1764. bottom = 0,
  1765. tops = [],
  1766. bottoms = [];
  1767. for (i = 0; i < n; ++i) {
  1768. j = order[i];
  1769. if (top < bottom) {
  1770. top += sums[j];
  1771. tops.push(j);
  1772. } else {
  1773. bottom += sums[j];
  1774. bottoms.push(j);
  1775. }
  1776. }
  1777. return bottoms.reverse().concat(tops);
  1778. }
  1779. function reverse(series) {
  1780. return none(series).reverse();
  1781. }
  1782. exports.arc = arc;
  1783. exports.area = area;
  1784. exports.areaRadial = areaRadial;
  1785. exports.curveBasis = basis;
  1786. exports.curveBasisClosed = basisClosed;
  1787. exports.curveBasisOpen = basisOpen;
  1788. exports.curveBumpX = bumpX;
  1789. exports.curveBumpY = bumpY;
  1790. exports.curveBundle = bundle;
  1791. exports.curveCardinal = cardinal;
  1792. exports.curveCardinalClosed = cardinalClosed;
  1793. exports.curveCardinalOpen = cardinalOpen;
  1794. exports.curveCatmullRom = catmullRom;
  1795. exports.curveCatmullRomClosed = catmullRomClosed;
  1796. exports.curveCatmullRomOpen = catmullRomOpen;
  1797. exports.curveLinear = curveLinear;
  1798. exports.curveLinearClosed = linearClosed;
  1799. exports.curveMonotoneX = monotoneX;
  1800. exports.curveMonotoneY = monotoneY;
  1801. exports.curveNatural = natural;
  1802. exports.curveStep = step;
  1803. exports.curveStepAfter = stepAfter;
  1804. exports.curveStepBefore = stepBefore;
  1805. exports.line = line;
  1806. exports.lineRadial = lineRadial$1;
  1807. exports.link = link;
  1808. exports.linkHorizontal = linkHorizontal;
  1809. exports.linkRadial = linkRadial;
  1810. exports.linkVertical = linkVertical;
  1811. exports.pie = pie;
  1812. exports.pointRadial = pointRadial;
  1813. exports.radialArea = areaRadial;
  1814. exports.radialLine = lineRadial$1;
  1815. exports.stack = stack;
  1816. exports.stackOffsetDiverging = diverging;
  1817. exports.stackOffsetExpand = expand;
  1818. exports.stackOffsetNone = none$1;
  1819. exports.stackOffsetSilhouette = silhouette;
  1820. exports.stackOffsetWiggle = wiggle;
  1821. exports.stackOrderAppearance = appearance;
  1822. exports.stackOrderAscending = ascending;
  1823. exports.stackOrderDescending = descending;
  1824. exports.stackOrderInsideOut = insideOut;
  1825. exports.stackOrderNone = none;
  1826. exports.stackOrderReverse = reverse;
  1827. exports.symbol = Symbol;
  1828. exports.symbolAsterisk = asterisk;
  1829. exports.symbolCircle = circle;
  1830. exports.symbolCross = cross;
  1831. exports.symbolDiamond = diamond;
  1832. exports.symbolDiamond2 = diamond2;
  1833. exports.symbolPlus = plus;
  1834. exports.symbolSquare = square;
  1835. exports.symbolSquare2 = square2;
  1836. exports.symbolStar = star;
  1837. exports.symbolTimes = times;
  1838. exports.symbolTriangle = triangle;
  1839. exports.symbolTriangle2 = triangle2;
  1840. exports.symbolWye = wye;
  1841. exports.symbolX = times;
  1842. exports.symbols = symbolsFill;
  1843. exports.symbolsFill = symbolsFill;
  1844. exports.symbolsStroke = symbolsStroke;
  1845. }));