UNPKG

7.01 kBJavaScriptView Raw
1import { c as constant, p as path } from "./constant-b644328d.js";
2import { aD as halfPi, aE as epsilon, S as tau, aF as cos, aG as sin, aH as sqrt, aI as min, aJ as abs, aK as pi, aL as atan2, aM as asin, aN as acos, aO as max } from "./mermaid-4b4b971d.js";
3function arcInnerRadius(d) {
4 return d.innerRadius;
5}
6function arcOuterRadius(d) {
7 return d.outerRadius;
8}
9function arcStartAngle(d) {
10 return d.startAngle;
11}
12function arcEndAngle(d) {
13 return d.endAngle;
14}
15function arcPadAngle(d) {
16 return d && d.padAngle;
17}
18function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
19 var x10 = x1 - x0, y10 = y1 - y0, x32 = x3 - x2, y32 = y3 - y2, t = y32 * x10 - x32 * y10;
20 if (t * t < epsilon)
21 return;
22 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
23 return [x0 + t * x10, y0 + t * y10];
24}
25function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
26 var x01 = x0 - x1, y01 = y0 - y1, lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x11 = x0 + ox, y11 = y0 + oy, x10 = x1 + ox, y10 = y1 + oy, x00 = (x11 + x10) / 2, y00 = (y11 + y10) / 2, dx = x10 - x11, dy = y10 - y11, d2 = dx * dx + dy * dy, r = r1 - rc, D = x11 * y10 - x10 * y11, d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x00, dy0 = cy0 - y00, dx1 = cx1 - x00, dy1 = cy1 - y00;
27 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1)
28 cx0 = cx1, cy0 = cy1;
29 return {
30 cx: cx0,
31 cy: cy0,
32 x01: -ox,
33 y01: -oy,
34 x11: cx0 * (r1 / r - 1),
35 y11: cy0 * (r1 / r - 1)
36 };
37}
38function d3arc() {
39 var innerRadius = arcInnerRadius, outerRadius = arcOuterRadius, cornerRadius = constant(0), padRadius = null, startAngle = arcStartAngle, endAngle = arcEndAngle, padAngle = arcPadAngle, context = null;
40 function arc() {
41 var buffer, r, r0 = +innerRadius.apply(this, arguments), r1 = +outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) - halfPi, a1 = endAngle.apply(this, arguments) - halfPi, da = abs(a1 - a0), cw = a1 > a0;
42 if (!context)
43 context = buffer = path();
44 if (r1 < r0)
45 r = r1, r1 = r0, r0 = r;
46 if (!(r1 > epsilon))
47 context.moveTo(0, 0);
48 else if (da > tau - epsilon) {
49 context.moveTo(r1 * cos(a0), r1 * sin(a0));
50 context.arc(0, 0, r1, a0, a1, !cw);
51 if (r0 > epsilon) {
52 context.moveTo(r0 * cos(a1), r0 * sin(a1));
53 context.arc(0, 0, r0, a1, a0, cw);
54 }
55 } else {
56 var a01 = a0, a11 = a1, a00 = a0, a10 = a1, da0 = da, da1 = da, ap = padAngle.apply(this, arguments) / 2, rp = ap > epsilon && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)), rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)), rc0 = rc, rc1 = rc, t0, t1;
57 if (rp > epsilon) {
58 var p0 = asin(rp / r0 * sin(ap)), p1 = asin(rp / r1 * sin(ap));
59 if ((da0 -= p0 * 2) > epsilon)
60 p0 *= cw ? 1 : -1, a00 += p0, a10 -= p0;
61 else
62 da0 = 0, a00 = a10 = (a0 + a1) / 2;
63 if ((da1 -= p1 * 2) > epsilon)
64 p1 *= cw ? 1 : -1, a01 += p1, a11 -= p1;
65 else
66 da1 = 0, a01 = a11 = (a0 + a1) / 2;
67 }
68 var x01 = r1 * cos(a01), y01 = r1 * sin(a01), x10 = r0 * cos(a10), y10 = r0 * sin(a10);
69 if (rc > epsilon) {
70 var x11 = r1 * cos(a11), y11 = r1 * sin(a11), x00 = r0 * cos(a00), y00 = r0 * sin(a00), oc;
71 if (da < pi && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
72 var ax = x01 - oc[0], ay = y01 - oc[1], bx = x11 - oc[0], by = y11 - oc[1], kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2), lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
73 rc0 = min(rc, (r0 - lc) / (kc - 1));
74 rc1 = min(rc, (r1 - lc) / (kc + 1));
75 }
76 }
77 if (!(da1 > epsilon))
78 context.moveTo(x01, y01);
79 else if (rc1 > epsilon) {
80 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
81 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
82 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
83 if (rc1 < rc)
84 context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
85 else {
86 context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
87 context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
88 context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
89 }
90 } else
91 context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
92 if (!(r0 > epsilon) || !(da0 > epsilon))
93 context.lineTo(x10, y10);
94 else if (rc0 > epsilon) {
95 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
96 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
97 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
98 if (rc0 < rc)
99 context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
100 else {
101 context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
102 context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
103 context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
104 }
105 } else
106 context.arc(0, 0, r0, a10, a00, cw);
107 }
108 context.closePath();
109 if (buffer)
110 return context = null, buffer + "" || null;
111 }
112 arc.centroid = function() {
113 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
114 return [cos(a) * r, sin(a) * r];
115 };
116 arc.innerRadius = function(_) {
117 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant(+_), arc) : innerRadius;
118 };
119 arc.outerRadius = function(_) {
120 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant(+_), arc) : outerRadius;
121 };
122 arc.cornerRadius = function(_) {
123 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant(+_), arc) : cornerRadius;
124 };
125 arc.padRadius = function(_) {
126 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant(+_), arc) : padRadius;
127 };
128 arc.startAngle = function(_) {
129 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), arc) : startAngle;
130 };
131 arc.endAngle = function(_) {
132 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), arc) : endAngle;
133 };
134 arc.padAngle = function(_) {
135 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), arc) : padAngle;
136 };
137 arc.context = function(_) {
138 return arguments.length ? (context = _ == null ? null : _, arc) : context;
139 };
140 return arc;
141}
142export {
143 d3arc as d
144};