1 // https://d3js.org/d3-shape/ v2.1.0 Copyright 2021 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';
9 return function constant() {
15 var atan2 = Math.atan2;
28 return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
32 return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
35 function arcInnerRadius(d) {
39 function arcOuterRadius(d) {
43 function arcStartAngle(d) {
47 function arcEndAngle(d) {
51 function arcPadAngle(d) {
52 return d && d.padAngle; // Note: optional!
55 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
56 var x10 = x1 - x0, y10 = y1 - y0,
57 x32 = x3 - x2, y32 = y3 - y2,
58 t = y32 * x10 - x32 * y10;
59 if (t * t < epsilon) return;
60 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
61 return [x0 + t * x10, y0 + t * y10];
64 // Compute perpendicular offset line of length rc.
65 // http://mathworld.wolfram.com/Circle-LineIntersection.html
66 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
69 lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
76 x00 = (x11 + x10) / 2,
77 y00 = (y11 + y10) / 2,
80 d2 = dx * dx + dy * dy,
82 D = x11 * y10 - x10 * y11,
83 d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
84 cx0 = (D * dy - dx * d) / d2,
85 cy0 = (-D * dx - dy * d) / d2,
86 cx1 = (D * dy + dx * d) / d2,
87 cy1 = (-D * dx + dy * d) / d2,
93 // Pick the closer of the two intersection points.
94 // TODO Is there a faster way to determine which intersection to use?
95 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
102 x11: cx0 * (r1 / r - 1),
103 y11: cy0 * (r1 / r - 1)
108 var innerRadius = arcInnerRadius,
109 outerRadius = arcOuterRadius,
110 cornerRadius = constant(0),
112 startAngle = arcStartAngle,
113 endAngle = arcEndAngle,
114 padAngle = arcPadAngle,
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,
127 if (!context) context = buffer = d3Path.path();
129 // Ensure that the outer radius is always larger than the inner radius.
130 if (r1 < r0) r = r1, r1 = r0, r0 = r;
133 if (!(r1 > epsilon)) context.moveTo(0, 0);
135 // Or is it a circle or annulus?
136 else if (da > tau - epsilon) {
137 context.moveTo(r1 * cos(a0), r1 * sin(a0));
138 context.arc(0, 0, r1, a0, a1, !cw);
140 context.moveTo(r0 * cos(a1), r0 * sin(a1));
141 context.arc(0, 0, r0, a1, a0, cw);
145 // Or is it a circular or annular sector?
153 ap = padAngle.apply(this, arguments) / 2,
154 rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
155 rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
161 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
163 var p0 = asin(rp / r0 * sin(ap)),
164 p1 = asin(rp / r1 * sin(ap));
165 if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
166 else da0 = 0, a00 = a10 = (a0 + a1) / 2;
167 if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
168 else da1 = 0, a01 = a11 = (a0 + a1) / 2;
171 var x01 = r1 * cos(a01),
176 // Apply rounded corners?
178 var x11 = r1 * cos(a11),
184 // Restrict the corner radius according to the sector angle.
185 if (da < pi && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
186 var ax = x01 - oc[0],
190 kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
191 lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
192 rc0 = min(rc, (r0 - lc) / (kc - 1));
193 rc1 = min(rc, (r1 - lc) / (kc + 1));
197 // Is the sector collapsed to a line?
198 if (!(da1 > epsilon)) context.moveTo(x01, y01);
200 // Does the sector’s outer ring have rounded corners?
201 else if (rc1 > epsilon) {
202 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
203 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
205 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
207 // Have the corners merged?
208 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
210 // Otherwise, draw the two corners and the ring.
212 context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
213 context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
214 context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
218 // Or is the outer ring just a circular arc?
219 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
221 // Is there no inner ring, and it’s a circular sector?
222 // Or perhaps it’s an annular sector collapsed due to padding?
223 if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
225 // Does the sector’s inner ring (or point) have rounded corners?
226 else if (rc0 > epsilon) {
227 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
228 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
230 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
232 // Have the corners merged?
233 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
235 // Otherwise, draw the two corners and the ring.
237 context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
238 context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
239 context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
243 // Or is the inner ring just a circular arc?
244 else context.arc(0, 0, r0, a10, a00, cw);
249 if (buffer) return context = null, buffer + "" || null;
252 arc.centroid = function() {
253 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
254 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
255 return [cos(a) * r, sin(a) * r];
258 arc.innerRadius = function(_) {
259 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant(+_), arc) : innerRadius;
262 arc.outerRadius = function(_) {
263 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant(+_), arc) : outerRadius;
266 arc.cornerRadius = function(_) {
267 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant(+_), arc) : cornerRadius;
270 arc.padRadius = function(_) {
271 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant(+_), arc) : padRadius;
274 arc.startAngle = function(_) {
275 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), arc) : startAngle;
278 arc.endAngle = function(_) {
279 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), arc) : endAngle;
282 arc.padAngle = function(_) {
283 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), arc) : padAngle;
286 arc.context = function(_) {
287 return arguments.length ? ((context = _ == null ? null : _), arc) : context;
293 var slice = Array.prototype.slice;
296 return typeof x === "object" && "length" in x
297 ? x // Array, TypedArray, NodeList, array-like
298 : Array.from(x); // Map, Set, iterable, string, or anything else
301 function Linear(context) {
302 this._context = context;
306 areaStart: function() {
309 areaEnd: function() {
312 lineStart: function() {
315 lineEnd: function() {
316 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
317 this._line = 1 - this._line;
319 point: function(x, y) {
321 switch (this._point) {
322 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
323 case 1: this._point = 2; // proceed
324 default: this._context.lineTo(x, y); break;
329 function curveLinear(context) {
330 return new Linear(context);
341 function line(x$1, y$1) {
342 var defined = constant(true),
347 x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant(x$1);
348 y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant(y$1);
350 function line(data) {
352 n = (data = array(data)).length,
357 if (context == null) output = curve(buffer = d3Path.path());
359 for (i = 0; i <= n; ++i) {
360 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
361 if (defined0 = !defined0) output.lineStart();
362 else output.lineEnd();
364 if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
367 if (buffer) return output = null, buffer + "" || null;
370 line.x = function(_) {
371 return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant(+_), line) : x$1;
374 line.y = function(_) {
375 return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant(+_), line) : y$1;
378 line.defined = function(_) {
379 return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined;
382 line.curve = function(_) {
383 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
386 line.context = function(_) {
387 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
393 function area(x0, y0, y1) {
395 defined = constant(true),
400 x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant(+x0);
401 y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant(0) : constant(+y0);
402 y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant(+y1);
404 function area(data) {
408 n = (data = array(data)).length,
415 if (context == null) output = curve(buffer = d3Path.path());
417 for (i = 0; i <= n; ++i) {
418 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
419 if (defined0 = !defined0) {
426 for (k = i - 1; k >= j; --k) {
427 output.point(x0z[k], y0z[k]);
434 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
435 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
439 if (buffer) return output = null, buffer + "" || null;
442 function arealine() {
443 return line().defined(defined).curve(curve).context(context);
446 area.x = function(_) {
447 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant(+_), x1 = null, area) : x0;
450 area.x0 = function(_) {
451 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant(+_), area) : x0;
454 area.x1 = function(_) {
455 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant(+_), area) : x1;
458 area.y = function(_) {
459 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant(+_), y1 = null, area) : y0;
462 area.y0 = function(_) {
463 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant(+_), area) : y0;
466 area.y1 = function(_) {
467 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant(+_), area) : y1;
471 area.lineY0 = function() {
472 return arealine().x(x0).y(y0);
475 area.lineY1 = function() {
476 return arealine().x(x0).y(y1);
479 area.lineX1 = function() {
480 return arealine().x(x1).y(y0);
483 area.defined = function(_) {
484 return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), area) : defined;
487 area.curve = function(_) {
488 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
491 area.context = function(_) {
492 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
498 function descending$1(a, b) {
499 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
502 function identity(d) {
507 var value = identity,
508 sortValues = descending$1,
510 startAngle = constant(0),
511 endAngle = constant(tau),
512 padAngle = constant(0);
516 n = (data = array(data)).length,
520 index = new Array(n),
522 a0 = +startAngle.apply(this, arguments),
523 da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
525 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
526 pa = p * (da < 0 ? -1 : 1),
529 for (i = 0; i < n; ++i) {
530 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
535 // Optionally sort the arcs by previously-computed values or by data.
536 if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
537 else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
539 // Compute the arcs! They are stored in the original data's order.
540 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
541 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
554 pie.value = function(_) {
555 return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), pie) : value;
558 pie.sortValues = function(_) {
559 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
562 pie.sort = function(_) {
563 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
566 pie.startAngle = function(_) {
567 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), pie) : startAngle;
570 pie.endAngle = function(_) {
571 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), pie) : endAngle;
574 pie.padAngle = function(_) {
575 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), pie) : padAngle;
581 var curveRadialLinear = curveRadial$1(curveLinear);
583 function Radial(curve) {
588 areaStart: function() {
589 this._curve.areaStart();
591 areaEnd: function() {
592 this._curve.areaEnd();
594 lineStart: function() {
595 this._curve.lineStart();
597 lineEnd: function() {
598 this._curve.lineEnd();
600 point: function(a, r) {
601 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
605 function curveRadial$1(curve) {
607 function radial(context) {
608 return new Radial(curve(context));
611 radial._curve = curve;
616 function lineRadial(l) {
619 l.angle = l.x, delete l.x;
620 l.radius = l.y, delete l.y;
622 l.curve = function(_) {
623 return arguments.length ? c(curveRadial$1(_)) : c()._curve;
629 function lineRadial$1() {
630 return lineRadial(line().curve(curveRadialLinear));
633 function areaRadial() {
634 var a = area().curve(curveRadialLinear),
641 a.angle = a.x, delete a.x;
642 a.startAngle = a.x0, delete a.x0;
643 a.endAngle = a.x1, delete a.x1;
644 a.radius = a.y, delete a.y;
645 a.innerRadius = a.y0, delete a.y0;
646 a.outerRadius = a.y1, delete a.y1;
647 a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
648 a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
649 a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
650 a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
652 a.curve = function(_) {
653 return arguments.length ? c(curveRadial$1(_)) : c()._curve;
659 function pointRadial(x, y) {
660 return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
663 function linkSource(d) {
667 function linkTarget(d) {
671 function link(curve) {
672 var source = linkSource,
679 var buffer, argv = slice.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
680 if (!context) context = buffer = d3Path.path();
681 curve(context, +x$1.apply(this, (argv[0] = s, argv)), +y$1.apply(this, argv), +x$1.apply(this, (argv[0] = t, argv)), +y$1.apply(this, argv));
682 if (buffer) return context = null, buffer + "" || null;
685 link.source = function(_) {
686 return arguments.length ? (source = _, link) : source;
689 link.target = function(_) {
690 return arguments.length ? (target = _, link) : target;
693 link.x = function(_) {
694 return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant(+_), link) : x$1;
697 link.y = function(_) {
698 return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant(+_), link) : y$1;
701 link.context = function(_) {
702 return arguments.length ? ((context = _ == null ? null : _), link) : context;
708 function curveHorizontal(context, x0, y0, x1, y1) {
709 context.moveTo(x0, y0);
710 context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
713 function curveVertical(context, x0, y0, x1, y1) {
714 context.moveTo(x0, y0);
715 context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
718 function curveRadial(context, x0, y0, x1, y1) {
719 var p0 = pointRadial(x0, y0),
720 p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
721 p2 = pointRadial(x1, y0),
722 p3 = pointRadial(x1, y1);
723 context.moveTo(p0[0], p0[1]);
724 context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
727 function linkHorizontal() {
728 return link(curveHorizontal);
731 function linkVertical() {
732 return link(curveVertical);
735 function linkRadial() {
736 var l = link(curveRadial);
737 l.angle = l.x, delete l.x;
738 l.radius = l.y, delete l.y;
743 draw: function(context, size) {
744 var r = Math.sqrt(size / pi);
745 context.moveTo(r, 0);
746 context.arc(0, 0, r, 0, tau);
751 draw: function(context, size) {
752 var r = Math.sqrt(size / 5) / 2;
753 context.moveTo(-3 * r, -r);
754 context.lineTo(-r, -r);
755 context.lineTo(-r, -3 * r);
756 context.lineTo(r, -3 * r);
757 context.lineTo(r, -r);
758 context.lineTo(3 * r, -r);
759 context.lineTo(3 * r, r);
760 context.lineTo(r, r);
761 context.lineTo(r, 3 * r);
762 context.lineTo(-r, 3 * r);
763 context.lineTo(-r, r);
764 context.lineTo(-3 * r, r);
769 var tan30 = Math.sqrt(1 / 3),
773 draw: function(context, size) {
774 var y = Math.sqrt(size / tan30_2),
776 context.moveTo(0, -y);
777 context.lineTo(x, 0);
778 context.lineTo(0, y);
779 context.lineTo(-x, 0);
784 var ka = 0.89081309152928522810,
785 kr = Math.sin(pi / 10) / Math.sin(7 * pi / 10),
786 kx = Math.sin(tau / 10) * kr,
787 ky = -Math.cos(tau / 10) * kr;
790 draw: function(context, size) {
791 var r = Math.sqrt(size * ka),
794 context.moveTo(0, -r);
795 context.lineTo(x, y);
796 for (var i = 1; i < 5; ++i) {
800 context.lineTo(s * r, -c * r);
801 context.lineTo(c * x - s * y, s * x + c * y);
808 draw: function(context, size) {
809 var w = Math.sqrt(size),
811 context.rect(x, x, w, w);
815 var sqrt3 = Math.sqrt(3);
818 draw: function(context, size) {
819 var y = -Math.sqrt(size / (sqrt3 * 3));
820 context.moveTo(0, y * 2);
821 context.lineTo(-sqrt3 * y, -y);
822 context.lineTo(sqrt3 * y, -y);
828 s = Math.sqrt(3) / 2,
829 k = 1 / Math.sqrt(12),
833 draw: function(context, size) {
834 var r = Math.sqrt(size / a),
841 context.moveTo(x0, y0);
842 context.lineTo(x1, y1);
843 context.lineTo(x2, y2);
844 context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
845 context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
846 context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
847 context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
848 context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
849 context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
864 function symbol(type, size) {
866 type = typeof type === "function" ? type : constant(type || circle);
867 size = typeof size === "function" ? size : constant(size === undefined ? 64 : +size);
871 if (!context) context = buffer = d3Path.path();
872 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
873 if (buffer) return context = null, buffer + "" || null;
876 symbol.type = function(_) {
877 return arguments.length ? (type = typeof _ === "function" ? _ : constant(_), symbol) : type;
880 symbol.size = function(_) {
881 return arguments.length ? (size = typeof _ === "function" ? _ : constant(+_), symbol) : size;
884 symbol.context = function(_) {
885 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
893 function point$3(that, x, y) {
894 that._context.bezierCurveTo(
895 (2 * that._x0 + that._x1) / 3,
896 (2 * that._y0 + that._y1) / 3,
897 (that._x0 + 2 * that._x1) / 3,
898 (that._y0 + 2 * that._y1) / 3,
899 (that._x0 + 4 * that._x1 + x) / 6,
900 (that._y0 + 4 * that._y1 + y) / 6
904 function Basis(context) {
905 this._context = context;
909 areaStart: function() {
912 areaEnd: function() {
915 lineStart: function() {
916 this._x0 = this._x1 =
917 this._y0 = this._y1 = NaN;
920 lineEnd: function() {
921 switch (this._point) {
922 case 3: point$3(this, this._x1, this._y1); // proceed
923 case 2: this._context.lineTo(this._x1, this._y1); break;
925 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
926 this._line = 1 - this._line;
928 point: function(x, 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); // proceed
934 default: point$3(this, x, y); break;
936 this._x0 = this._x1, this._x1 = x;
937 this._y0 = this._y1, this._y1 = y;
941 function basis(context) {
942 return new Basis(context);
945 function BasisClosed(context) {
946 this._context = context;
949 BasisClosed.prototype = {
952 lineStart: function() {
953 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
954 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
957 lineEnd: function() {
958 switch (this._point) {
960 this._context.moveTo(this._x2, this._y2);
961 this._context.closePath();
965 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
966 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
967 this._context.closePath();
971 this.point(this._x2, this._y2);
972 this.point(this._x3, this._y3);
973 this.point(this._x4, this._y4);
978 point: function(x, y) {
980 switch (this._point) {
981 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
982 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
983 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;
984 default: point$3(this, x, y); break;
986 this._x0 = this._x1, this._x1 = x;
987 this._y0 = this._y1, this._y1 = y;
991 function basisClosed(context) {
992 return new BasisClosed(context);
995 function BasisOpen(context) {
996 this._context = context;
999 BasisOpen.prototype = {
1000 areaStart: function() {
1003 areaEnd: function() {
1006 lineStart: function() {
1007 this._x0 = this._x1 =
1008 this._y0 = this._y1 = NaN;
1011 lineEnd: function() {
1012 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
1013 this._line = 1 - this._line;
1015 point: function(x, y) {
1017 switch (this._point) {
1018 case 0: this._point = 1; break;
1019 case 1: this._point = 2; break;
1020 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;
1021 case 3: this._point = 4; // proceed
1022 default: point$3(this, x, y); break;
1024 this._x0 = this._x1, this._x1 = x;
1025 this._y0 = this._y1, this._y1 = y;
1029 function basisOpen(context) {
1030 return new BasisOpen(context);
1034 constructor(context, x) {
1035 this._context = context;
1048 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
1049 this._line = 1 - this._line;
1053 switch (this._point) {
1056 if (this._line) this._context.lineTo(x, y);
1057 else this._context.moveTo(x, y);
1060 case 1: this._point = 2; // proceed
1062 if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
1063 else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
1067 this._x0 = x, this._y0 = y;
1071 function bumpX(context) {
1072 return new Bump(context, true);
1075 function bumpY(context) {
1076 return new Bump(context, false);
1079 function Bundle(context, beta) {
1080 this._basis = new Basis(context);
1084 Bundle.prototype = {
1085 lineStart: function() {
1088 this._basis.lineStart();
1090 lineEnd: function() {
1106 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
1107 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
1112 this._x = this._y = null;
1113 this._basis.lineEnd();
1115 point: function(x, y) {
1121 var bundle = (function custom(beta) {
1123 function bundle(context) {
1124 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
1127 bundle.beta = function(beta) {
1128 return custom(+beta);
1134 function point$2(that, x, y) {
1135 that._context.bezierCurveTo(
1136 that._x1 + that._k * (that._x2 - that._x0),
1137 that._y1 + that._k * (that._y2 - that._y0),
1138 that._x2 + that._k * (that._x1 - x),
1139 that._y2 + that._k * (that._y1 - y),
1145 function Cardinal(context, tension) {
1146 this._context = context;
1147 this._k = (1 - tension) / 6;
1150 Cardinal.prototype = {
1151 areaStart: function() {
1154 areaEnd: function() {
1157 lineStart: function() {
1158 this._x0 = this._x1 = this._x2 =
1159 this._y0 = this._y1 = this._y2 = NaN;
1162 lineEnd: function() {
1163 switch (this._point) {
1164 case 2: this._context.lineTo(this._x2, this._y2); break;
1165 case 3: point$2(this, this._x1, this._y1); break;
1167 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
1168 this._line = 1 - this._line;
1170 point: function(x, y) {
1172 switch (this._point) {
1173 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
1174 case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
1175 case 2: this._point = 3; // proceed
1176 default: point$2(this, x, y); break;
1178 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
1179 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
1183 var cardinal = (function custom(tension) {
1185 function cardinal(context) {
1186 return new Cardinal(context, tension);
1189 cardinal.tension = function(tension) {
1190 return custom(+tension);
1196 function CardinalClosed(context, tension) {
1197 this._context = context;
1198 this._k = (1 - tension) / 6;
1201 CardinalClosed.prototype = {
1204 lineStart: function() {
1205 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
1206 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
1209 lineEnd: function() {
1210 switch (this._point) {
1212 this._context.moveTo(this._x3, this._y3);
1213 this._context.closePath();
1217 this._context.lineTo(this._x3, this._y3);
1218 this._context.closePath();
1222 this.point(this._x3, this._y3);
1223 this.point(this._x4, this._y4);
1224 this.point(this._x5, this._y5);
1229 point: function(x, y) {
1231 switch (this._point) {
1232 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
1233 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
1234 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
1235 default: point$2(this, x, y); break;
1237 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
1238 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
1242 var cardinalClosed = (function custom(tension) {
1244 function cardinal(context) {
1245 return new CardinalClosed(context, tension);
1248 cardinal.tension = function(tension) {
1249 return custom(+tension);
1255 function CardinalOpen(context, tension) {
1256 this._context = context;
1257 this._k = (1 - tension) / 6;
1260 CardinalOpen.prototype = {
1261 areaStart: function() {
1264 areaEnd: function() {
1267 lineStart: function() {
1268 this._x0 = this._x1 = this._x2 =
1269 this._y0 = this._y1 = this._y2 = NaN;
1272 lineEnd: function() {
1273 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
1274 this._line = 1 - this._line;
1276 point: function(x, y) {
1278 switch (this._point) {
1279 case 0: this._point = 1; break;
1280 case 1: this._point = 2; break;
1281 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
1282 case 3: this._point = 4; // proceed
1283 default: point$2(this, x, y); break;
1285 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
1286 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
1290 var cardinalOpen = (function custom(tension) {
1292 function cardinal(context) {
1293 return new CardinalOpen(context, tension);
1296 cardinal.tension = function(tension) {
1297 return custom(+tension);
1303 function point$1(that, x, y) {
1309 if (that._l01_a > epsilon) {
1310 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
1311 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
1312 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
1313 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
1316 if (that._l23_a > epsilon) {
1317 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
1318 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
1319 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
1320 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
1323 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
1326 function CatmullRom(context, alpha) {
1327 this._context = context;
1328 this._alpha = alpha;
1331 CatmullRom.prototype = {
1332 areaStart: function() {
1335 areaEnd: function() {
1338 lineStart: function() {
1339 this._x0 = this._x1 = this._x2 =
1340 this._y0 = this._y1 = this._y2 = NaN;
1341 this._l01_a = this._l12_a = this._l23_a =
1342 this._l01_2a = this._l12_2a = this._l23_2a =
1345 lineEnd: function() {
1346 switch (this._point) {
1347 case 2: this._context.lineTo(this._x2, this._y2); break;
1348 case 3: this.point(this._x2, this._y2); break;
1350 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
1351 this._line = 1 - this._line;
1353 point: function(x, y) {
1357 var x23 = this._x2 - x,
1359 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
1362 switch (this._point) {
1363 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
1364 case 1: this._point = 2; break;
1365 case 2: this._point = 3; // proceed
1366 default: point$1(this, x, y); break;
1369 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
1370 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
1371 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
1372 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
1376 var catmullRom = (function custom(alpha) {
1378 function catmullRom(context) {
1379 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
1382 catmullRom.alpha = function(alpha) {
1383 return custom(+alpha);
1389 function CatmullRomClosed(context, alpha) {
1390 this._context = context;
1391 this._alpha = alpha;
1394 CatmullRomClosed.prototype = {
1397 lineStart: function() {
1398 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
1399 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
1400 this._l01_a = this._l12_a = this._l23_a =
1401 this._l01_2a = this._l12_2a = this._l23_2a =
1404 lineEnd: function() {
1405 switch (this._point) {
1407 this._context.moveTo(this._x3, this._y3);
1408 this._context.closePath();
1412 this._context.lineTo(this._x3, this._y3);
1413 this._context.closePath();
1417 this.point(this._x3, this._y3);
1418 this.point(this._x4, this._y4);
1419 this.point(this._x5, this._y5);
1424 point: function(x, y) {
1428 var x23 = this._x2 - x,
1430 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
1433 switch (this._point) {
1434 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
1435 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
1436 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
1437 default: point$1(this, x, y); break;
1440 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
1441 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
1442 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
1443 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
1447 var catmullRomClosed = (function custom(alpha) {
1449 function catmullRom(context) {
1450 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
1453 catmullRom.alpha = function(alpha) {
1454 return custom(+alpha);
1460 function CatmullRomOpen(context, alpha) {
1461 this._context = context;
1462 this._alpha = alpha;
1465 CatmullRomOpen.prototype = {
1466 areaStart: function() {
1469 areaEnd: function() {
1472 lineStart: function() {
1473 this._x0 = this._x1 = this._x2 =
1474 this._y0 = this._y1 = this._y2 = NaN;
1475 this._l01_a = this._l12_a = this._l23_a =
1476 this._l01_2a = this._l12_2a = this._l23_2a =
1479 lineEnd: function() {
1480 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
1481 this._line = 1 - this._line;
1483 point: function(x, y) {
1487 var x23 = this._x2 - x,
1489 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
1492 switch (this._point) {
1493 case 0: this._point = 1; break;
1494 case 1: this._point = 2; break;
1495 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
1496 case 3: this._point = 4; // proceed
1497 default: point$1(this, x, y); break;
1500 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
1501 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
1502 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
1503 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
1507 var catmullRomOpen = (function custom(alpha) {
1509 function catmullRom(context) {
1510 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
1513 catmullRom.alpha = function(alpha) {
1514 return custom(+alpha);
1520 function LinearClosed(context) {
1521 this._context = context;
1524 LinearClosed.prototype = {
1527 lineStart: function() {
1530 lineEnd: function() {
1531 if (this._point) this._context.closePath();
1533 point: function(x, y) {
1535 if (this._point) this._context.lineTo(x, y);
1536 else this._point = 1, this._context.moveTo(x, y);
1540 function linearClosed(context) {
1541 return new LinearClosed(context);
1545 return x < 0 ? -1 : 1;
1548 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
1549 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
1550 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
1551 // NOV(II), P. 443, 1990.
1552 function slope3(that, x2, y2) {
1553 var h0 = that._x1 - that._x0,
1555 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
1556 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
1557 p = (s0 * h1 + s1 * h0) / (h0 + h1);
1558 return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
1561 // Calculate a one-sided slope.
1562 function slope2(that, t) {
1563 var h = that._x1 - that._x0;
1564 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
1567 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
1568 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
1569 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
1570 function point(that, t0, t1) {
1576 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
1579 function MonotoneX(context) {
1580 this._context = context;
1583 MonotoneX.prototype = {
1584 areaStart: function() {
1587 areaEnd: function() {
1590 lineStart: function() {
1591 this._x0 = this._x1 =
1592 this._y0 = this._y1 =
1596 lineEnd: function() {
1597 switch (this._point) {
1598 case 2: this._context.lineTo(this._x1, this._y1); break;
1599 case 3: point(this, this._t0, slope2(this, this._t0)); break;
1601 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
1602 this._line = 1 - this._line;
1604 point: function(x, y) {
1608 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
1609 switch (this._point) {
1610 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
1611 case 1: this._point = 2; break;
1612 case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
1613 default: point(this, this._t0, t1 = slope3(this, x, y)); break;
1616 this._x0 = this._x1, this._x1 = x;
1617 this._y0 = this._y1, this._y1 = y;
1622 function MonotoneY(context) {
1623 this._context = new ReflectContext(context);
1626 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
1627 MonotoneX.prototype.point.call(this, y, x);
1630 function ReflectContext(context) {
1631 this._context = context;
1634 ReflectContext.prototype = {
1635 moveTo: function(x, y) { this._context.moveTo(y, x); },
1636 closePath: function() { this._context.closePath(); },
1637 lineTo: function(x, y) { this._context.lineTo(y, x); },
1638 bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
1641 function monotoneX(context) {
1642 return new MonotoneX(context);
1645 function monotoneY(context) {
1646 return new MonotoneY(context);
1649 function Natural(context) {
1650 this._context = context;
1653 Natural.prototype = {
1654 areaStart: function() {
1657 areaEnd: function() {
1660 lineStart: function() {
1664 lineEnd: function() {
1670 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
1672 this._context.lineTo(x[1], y[1]);
1674 var px = controlPoints(x),
1675 py = controlPoints(y);
1676 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
1677 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
1682 if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
1683 this._line = 1 - this._line;
1684 this._x = this._y = null;
1686 point: function(x, y) {
1692 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
1693 function controlPoints(x) {
1700 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
1701 for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
1702 a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
1703 for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
1704 a[n - 1] = r[n - 1] / b[n - 1];
1705 for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
1706 b[n - 1] = (x[n] + a[n - 1]) / 2;
1707 for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
1711 function natural(context) {
1712 return new Natural(context);
1715 function Step(context, t) {
1716 this._context = context;
1721 areaStart: function() {
1724 areaEnd: function() {
1727 lineStart: function() {
1728 this._x = this._y = NaN;
1731 lineEnd: function() {
1732 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
1733 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
1734 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
1736 point: function(x, y) {
1738 switch (this._point) {
1739 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
1740 case 1: this._point = 2; // proceed
1743 this._context.lineTo(this._x, y);
1744 this._context.lineTo(x, y);
1746 var x1 = this._x * (1 - this._t) + x * this._t;
1747 this._context.lineTo(x1, this._y);
1748 this._context.lineTo(x1, y);
1753 this._x = x, this._y = y;
1757 function step(context) {
1758 return new Step(context, 0.5);
1761 function stepBefore(context) {
1762 return new Step(context, 0);
1765 function stepAfter(context) {
1766 return new Step(context, 1);
1769 function none$1(series, order) {
1770 if (!((n = series.length) > 1)) return;
1771 for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
1772 s0 = s1, s1 = series[order[i]];
1773 for (j = 0; j < m; ++j) {
1774 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
1779 function none(series) {
1780 var n = series.length, o = new Array(n);
1781 while (--n >= 0) o[n] = n;
1785 function stackValue(d, key) {
1789 function stackSeries(key) {
1796 var keys = constant([]),
1801 function stack(data) {
1802 var sz = Array.from(keys.apply(this, arguments), stackSeries),
1803 i, n = sz.length, j = -1,
1806 for (const d of data) {
1807 for (i = 0, ++j; i < n; ++i) {
1808 (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
1812 for (i = 0, oz = array(order(sz)); i < n; ++i) {
1813 sz[oz[i]].index = i;
1820 stack.keys = function(_) {
1821 return arguments.length ? (keys = typeof _ === "function" ? _ : constant(Array.from(_)), stack) : keys;
1824 stack.value = function(_) {
1825 return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), stack) : value;
1828 stack.order = function(_) {
1829 return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant(Array.from(_)), stack) : order;
1832 stack.offset = function(_) {
1833 return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
1839 function expand(series, order) {
1840 if (!((n = series.length) > 0)) return;
1841 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
1842 for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
1843 if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
1845 none$1(series, order);
1848 function diverging(series, order) {
1849 if (!((n = series.length) > 0)) return;
1850 for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
1851 for (yp = yn = 0, i = 0; i < n; ++i) {
1852 if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
1853 d[0] = yp, d[1] = yp += dy;
1854 } else if (dy < 0) {
1855 d[1] = yn, d[0] = yn += dy;
1857 d[0] = 0, d[1] = dy;
1863 function silhouette(series, order) {
1864 if (!((n = series.length) > 0)) return;
1865 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
1866 for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
1867 s0[j][1] += s0[j][0] = -y / 2;
1869 none$1(series, order);
1872 function wiggle(series, order) {
1873 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
1874 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
1875 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
1876 var si = series[order[i]],
1877 sij0 = si[j][1] || 0,
1878 sij1 = si[j - 1][1] || 0,
1879 s3 = (sij0 - sij1) / 2;
1880 for (var k = 0; k < i; ++k) {
1881 var sk = series[order[k]],
1882 skj0 = sk[j][1] || 0,
1883 skj1 = sk[j - 1][1] || 0;
1886 s1 += sij0, s2 += s3 * sij0;
1888 s0[j - 1][1] += s0[j - 1][0] = y;
1889 if (s1) y -= s2 / s1;
1891 s0[j - 1][1] += s0[j - 1][0] = y;
1892 none$1(series, order);
1895 function appearance(series) {
1896 var peaks = series.map(peak);
1897 return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
1900 function peak(series) {
1901 var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
1902 while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
1906 function ascending(series) {
1907 var sums = series.map(sum);
1908 return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
1911 function sum(series) {
1912 var s = 0, i = -1, n = series.length, v;
1913 while (++i < n) if (v = +series[i][1]) s += v;
1917 function descending(series) {
1918 return ascending(series).reverse();
1921 function insideOut(series) {
1922 var n = series.length,
1925 sums = series.map(sum),
1926 order = appearance(series),
1932 for (i = 0; i < n; ++i) {
1943 return bottoms.reverse().concat(tops);
1946 function reverse(series) {
1947 return none(series).reverse();
1951 exports.area = area;
1952 exports.areaRadial = areaRadial;
1953 exports.curveBasis = basis;
1954 exports.curveBasisClosed = basisClosed;
1955 exports.curveBasisOpen = basisOpen;
1956 exports.curveBumpX = bumpX;
1957 exports.curveBumpY = bumpY;
1958 exports.curveBundle = bundle;
1959 exports.curveCardinal = cardinal;
1960 exports.curveCardinalClosed = cardinalClosed;
1961 exports.curveCardinalOpen = cardinalOpen;
1962 exports.curveCatmullRom = catmullRom;
1963 exports.curveCatmullRomClosed = catmullRomClosed;
1964 exports.curveCatmullRomOpen = catmullRomOpen;
1965 exports.curveLinear = curveLinear;
1966 exports.curveLinearClosed = linearClosed;
1967 exports.curveMonotoneX = monotoneX;
1968 exports.curveMonotoneY = monotoneY;
1969 exports.curveNatural = natural;
1970 exports.curveStep = step;
1971 exports.curveStepAfter = stepAfter;
1972 exports.curveStepBefore = stepBefore;
1973 exports.line = line;
1974 exports.lineRadial = lineRadial$1;
1975 exports.linkHorizontal = linkHorizontal;
1976 exports.linkRadial = linkRadial;
1977 exports.linkVertical = linkVertical;
1979 exports.pointRadial = pointRadial;
1980 exports.radialArea = areaRadial;
1981 exports.radialLine = lineRadial$1;
1982 exports.stack = stack;
1983 exports.stackOffsetDiverging = diverging;
1984 exports.stackOffsetExpand = expand;
1985 exports.stackOffsetNone = none$1;
1986 exports.stackOffsetSilhouette = silhouette;
1987 exports.stackOffsetWiggle = wiggle;
1988 exports.stackOrderAppearance = appearance;
1989 exports.stackOrderAscending = ascending;
1990 exports.stackOrderDescending = descending;
1991 exports.stackOrderInsideOut = insideOut;
1992 exports.stackOrderNone = none;
1993 exports.stackOrderReverse = reverse;
1994 exports.symbol = symbol;
1995 exports.symbolCircle = circle;
1996 exports.symbolCross = cross;
1997 exports.symbolDiamond = diamond;
1998 exports.symbolSquare = square;
1999 exports.symbolStar = star;
2000 exports.symbolTriangle = triangle;
2001 exports.symbolWye = wye;
2002 exports.symbols = symbols;
2004 Object.defineProperty(exports, '__esModule', { value: true });