You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1935 lines
51 KiB

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