@antv/g2 5.0.11 → 5.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -0
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/mark/index.d.ts +3 -1
- package/esm/api/mark/index.js +2 -1
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +7 -1
- package/esm/api/mark/mark.js +9 -0
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/utils.js +1 -0
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +2 -1
- package/esm/component/axis.js.map +1 -1
- package/esm/component/scrollbar.js +8 -5
- package/esm/component/scrollbar.js.map +1 -1
- package/esm/composition/facetRect.js +13 -17
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/utils/venn/circleintersection.d.ts +33 -0
- package/esm/data/utils/venn/circleintersection.js +192 -0
- package/esm/data/utils/venn/circleintersection.js.map +1 -0
- package/esm/data/utils/venn/diagram.d.ts +2 -0
- package/esm/data/utils/venn/diagram.js +44 -0
- package/esm/data/utils/venn/diagram.js.map +1 -0
- package/esm/data/utils/venn/index.d.ts +5 -0
- package/esm/data/utils/venn/index.js +6 -0
- package/esm/data/utils/venn/index.js.map +1 -0
- package/esm/data/utils/venn/layout.d.ts +27 -0
- package/esm/data/utils/venn/layout.js +607 -0
- package/esm/data/utils/venn/layout.js.map +1 -0
- package/esm/data/venn.d.ts +7 -0
- package/esm/data/venn.js +34 -0
- package/esm/data/venn.js.map +1 -0
- package/esm/interaction/brushAxisHighlight.d.ts +5 -3
- package/esm/interaction/brushAxisHighlight.js +126 -12
- package/esm/interaction/brushAxisHighlight.js.map +1 -1
- package/esm/interaction/brushHighlight.js +6 -5
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/elementHighlight.d.ts +2 -2
- package/esm/interaction/elementHighlight.js +40 -6
- package/esm/interaction/elementHighlight.js.map +1 -1
- package/esm/interaction/elementHighlightByColor.d.ts +1 -1
- package/esm/interaction/elementHighlightByX.d.ts +1 -1
- package/esm/interaction/elementSelect.d.ts +2 -2
- package/esm/interaction/elementSelect.js +42 -13
- package/esm/interaction/elementSelect.js.map +1 -1
- package/esm/interaction/elementSelectByColor.d.ts +1 -1
- package/esm/interaction/elementSelectByX.d.ts +1 -1
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/legendFilter.js +42 -13
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/legendHighlight.d.ts +1 -1
- package/esm/interaction/legendHighlight.js +53 -15
- package/esm/interaction/legendHighlight.js.map +1 -1
- package/esm/interaction/scrollbarFilter.d.ts +2 -0
- package/esm/interaction/scrollbarFilter.js +25 -0
- package/esm/interaction/scrollbarFilter.js.map +1 -0
- package/esm/interaction/sliderFilter.d.ts +1 -1
- package/esm/interaction/sliderFilter.js +75 -19
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +2 -2
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/utils.d.ts +1 -0
- package/esm/interaction/utils.js +3 -0
- package/esm/interaction/utils.js.map +1 -1
- package/esm/mark/area.js +6 -2
- package/esm/mark/area.js.map +1 -1
- package/esm/runtime/plot.js +1 -0
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +30 -3
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +12 -9
- package/esm/runtime/transform.js.map +1 -1
- package/esm/shape/index.d.ts +2 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.d.ts +8 -0
- package/esm/shape/interval/color.js +19 -8
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/interval/rect.d.ts +10 -1
- package/esm/shape/interval/rect.js.map +1 -1
- package/esm/shape/line/trail.d.ts +3 -0
- package/esm/shape/line/trail.js +74 -0
- package/esm/shape/line/trail.js.map +1 -0
- package/esm/shape/path/color.js +5 -3
- package/esm/shape/path/color.js.map +1 -1
- package/esm/spec/dataTransform.d.ts +24 -2
- package/esm/stdlib/index.js +5 -5
- package/esm/stdlib/index.js.map +1 -1
- package/esm/utils/number.d.ts +4 -0
- package/esm/utils/number.js +7 -0
- package/esm/utils/number.js.map +1 -0
- package/esm/utils/scale.d.ts +2 -1
- package/esm/utils/scale.js +30 -11
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/vector.d.ts +1 -0
- package/esm/utils/vector.js +3 -0
- package/esm/utils/vector.js.map +1 -1
- package/lib/api/mark/index.d.ts +3 -1
- package/lib/api/mark/index.js +1 -0
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +7 -1
- package/lib/api/mark/mark.js +10 -1
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/utils.js +1 -0
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +2 -1
- package/lib/component/axis.js.map +1 -1
- package/lib/component/scrollbar.js +8 -5
- package/lib/component/scrollbar.js.map +1 -1
- package/lib/composition/facetRect.js +12 -16
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/utils/venn/circleintersection.d.ts +33 -0
- package/lib/data/utils/venn/circleintersection.js +202 -0
- package/lib/data/utils/venn/circleintersection.js.map +1 -0
- package/lib/data/utils/venn/diagram.d.ts +2 -0
- package/lib/data/utils/venn/diagram.js +48 -0
- package/lib/data/utils/venn/diagram.js.map +1 -0
- package/lib/data/utils/venn/index.d.ts +5 -0
- package/lib/data/utils/venn/index.js +12 -0
- package/lib/data/utils/venn/index.js.map +1 -0
- package/lib/data/utils/venn/layout.d.ts +27 -0
- package/lib/data/utils/venn/layout.js +620 -0
- package/lib/data/utils/venn/layout.js.map +1 -0
- package/lib/data/venn.d.ts +7 -0
- package/lib/data/venn.js +38 -0
- package/lib/data/venn.js.map +1 -0
- package/lib/interaction/brushAxisHighlight.d.ts +5 -3
- package/lib/interaction/brushAxisHighlight.js +126 -12
- package/lib/interaction/brushAxisHighlight.js.map +1 -1
- package/lib/interaction/brushHighlight.js +6 -5
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/elementHighlight.d.ts +2 -2
- package/lib/interaction/elementHighlight.js +39 -5
- package/lib/interaction/elementHighlight.js.map +1 -1
- package/lib/interaction/elementHighlightByColor.d.ts +1 -1
- package/lib/interaction/elementHighlightByX.d.ts +1 -1
- package/lib/interaction/elementSelect.d.ts +2 -2
- package/lib/interaction/elementSelect.js +41 -12
- package/lib/interaction/elementSelect.js.map +1 -1
- package/lib/interaction/elementSelectByColor.d.ts +1 -1
- package/lib/interaction/elementSelectByX.d.ts +1 -1
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/legendFilter.js +42 -13
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/legendHighlight.d.ts +1 -1
- package/lib/interaction/legendHighlight.js +53 -15
- package/lib/interaction/legendHighlight.js.map +1 -1
- package/lib/interaction/scrollbarFilter.d.ts +2 -0
- package/lib/interaction/scrollbarFilter.js +29 -0
- package/lib/interaction/scrollbarFilter.js.map +1 -0
- package/lib/interaction/sliderFilter.d.ts +1 -1
- package/lib/interaction/sliderFilter.js +73 -17
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +1 -1
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/utils.d.ts +1 -0
- package/lib/interaction/utils.js +5 -1
- package/lib/interaction/utils.js.map +1 -1
- package/lib/mark/area.js +6 -2
- package/lib/mark/area.js.map +1 -1
- package/lib/runtime/plot.js +1 -0
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +29 -2
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +12 -9
- package/lib/runtime/transform.js.map +1 -1
- package/lib/shape/index.d.ts +2 -0
- package/lib/shape/index.js +4 -2
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.d.ts +8 -0
- package/lib/shape/interval/color.js +19 -8
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/interval/rect.d.ts +10 -1
- package/lib/shape/interval/rect.js.map +1 -1
- package/lib/shape/line/trail.d.ts +3 -0
- package/lib/shape/line/trail.js +78 -0
- package/lib/shape/line/trail.js.map +1 -0
- package/lib/shape/path/color.js +5 -3
- package/lib/shape/path/color.js.map +1 -1
- package/lib/spec/dataTransform.d.ts +24 -2
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -1
- package/lib/utils/number.d.ts +4 -0
- package/lib/utils/number.js +11 -0
- package/lib/utils/number.js.map +1 -0
- package/lib/utils/scale.d.ts +2 -1
- package/lib/utils/scale.js +32 -12
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/vector.d.ts +1 -0
- package/lib/utils/vector.js +5 -1
- package/lib/utils/vector.js.map +1 -1
- package/package.json +2 -1
- package/src/api/mark/index.ts +3 -0
- package/src/api/mark/mark.ts +12 -0
- package/src/api/utils.ts +1 -0
- package/src/component/axis.ts +1 -0
- package/src/component/scrollbar.ts +11 -8
- package/src/composition/facetRect.ts +14 -17
- package/src/data/index.ts +2 -0
- package/src/data/utils/venn/circleintersection.ts +235 -0
- package/src/data/utils/venn/diagram.ts +47 -0
- package/src/data/utils/venn/index.ts +5 -0
- package/src/data/utils/venn/layout.ts +769 -0
- package/src/data/venn.ts +58 -0
- package/src/interaction/brushAxisHighlight.ts +130 -11
- package/src/interaction/brushHighlight.ts +6 -4
- package/src/interaction/elementHighlight.ts +39 -3
- package/src/interaction/elementSelect.ts +48 -10
- package/src/interaction/index.ts +1 -0
- package/src/interaction/legendFilter.ts +46 -13
- package/src/interaction/legendHighlight.ts +55 -14
- package/src/interaction/scrollbarFilter.ts +32 -0
- package/src/interaction/sliderFilter.ts +108 -28
- package/src/interaction/tooltip.ts +2 -5
- package/src/interaction/utils.ts +6 -0
- package/src/mark/area.ts +5 -2
- package/src/runtime/plot.ts +1 -0
- package/src/runtime/scale.ts +44 -5
- package/src/runtime/transform.ts +18 -9
- package/src/shape/index.ts +4 -0
- package/src/shape/interval/color.ts +29 -5
- package/src/shape/interval/rect.ts +10 -1
- package/src/shape/line/trail.ts +80 -0
- package/src/shape/path/color.ts +10 -6
- package/src/spec/dataTransform.ts +25 -0
- package/src/stdlib/index.ts +6 -0
- package/src/utils/number.ts +6 -0
- package/src/utils/scale.ts +29 -10
- package/src/utils/vector.ts +4 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
const SMALL = 1e-10;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the intersection area of a bunch of circles (where each circle
|
|
5
|
+
* is an object having an x,y and radius property)
|
|
6
|
+
*/
|
|
7
|
+
export function intersectionArea(circles, stats?: any) {
|
|
8
|
+
// Get all the intersection points of the circles
|
|
9
|
+
const intersectionPoints = getIntersectionPoints(circles);
|
|
10
|
+
|
|
11
|
+
// Filter out points that aren't included in all the circles
|
|
12
|
+
const innerPoints = intersectionPoints.filter(function (p) {
|
|
13
|
+
return containedInCircles(p, circles);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
let arcArea = 0,
|
|
17
|
+
polygonArea = 0,
|
|
18
|
+
i;
|
|
19
|
+
const arcs = [];
|
|
20
|
+
// If we have intersection points that are within all the circles,
|
|
21
|
+
// then figure out the area contained by them
|
|
22
|
+
if (innerPoints.length > 1) {
|
|
23
|
+
// Sort the points by angle from the center of the polygon, which lets
|
|
24
|
+
// us just iterate over points to get the edges
|
|
25
|
+
const center = getCenter(innerPoints);
|
|
26
|
+
for (i = 0; i < innerPoints.length; ++i) {
|
|
27
|
+
const p = innerPoints[i];
|
|
28
|
+
p.angle = Math.atan2(p.x - center.x, p.y - center.y);
|
|
29
|
+
}
|
|
30
|
+
innerPoints.sort(function (a, b) {
|
|
31
|
+
return b.angle - a.angle;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Iterate over all points, get arc between the points
|
|
35
|
+
// and update the areas
|
|
36
|
+
let p2 = innerPoints[innerPoints.length - 1];
|
|
37
|
+
for (i = 0; i < innerPoints.length; ++i) {
|
|
38
|
+
const p1 = innerPoints[i];
|
|
39
|
+
|
|
40
|
+
// Polygon area updates easily ...
|
|
41
|
+
polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
|
|
42
|
+
|
|
43
|
+
// Updating the arc area is a little more involved
|
|
44
|
+
const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
45
|
+
let arc = null;
|
|
46
|
+
|
|
47
|
+
for (let j = 0; j < p1.parentIndex.length; ++j) {
|
|
48
|
+
if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {
|
|
49
|
+
// Figure out the angle halfway between the two points
|
|
50
|
+
// on the current circle
|
|
51
|
+
const circle = circles[p1.parentIndex[j]],
|
|
52
|
+
a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y),
|
|
53
|
+
a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
|
|
54
|
+
|
|
55
|
+
let angleDiff = a2 - a1;
|
|
56
|
+
if (angleDiff < 0) {
|
|
57
|
+
angleDiff += 2 * Math.PI;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// and use that angle to figure out the width of the
|
|
61
|
+
// arc
|
|
62
|
+
const a = a2 - angleDiff / 2;
|
|
63
|
+
let width = distance(midPoint, {
|
|
64
|
+
x: circle.x + circle.radius * Math.sin(a),
|
|
65
|
+
y: circle.y + circle.radius * Math.cos(a),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Clamp the width to the largest is can actually be
|
|
69
|
+
// (sometimes slightly overflows because of FP errors)
|
|
70
|
+
if (width > circle.radius * 2) {
|
|
71
|
+
width = circle.radius * 2;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Pick the circle whose arc has the smallest width
|
|
75
|
+
if (arc === null || arc.width > width) {
|
|
76
|
+
arc = { circle: circle, width: width, p1: p1, p2: p2 };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (arc !== null) {
|
|
82
|
+
arcs.push(arc);
|
|
83
|
+
arcArea += circleArea(arc.circle.radius, arc.width);
|
|
84
|
+
p2 = p1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
// No intersection points, is either disjoint - or is completely
|
|
89
|
+
// overlapped. figure out which by examining the smallest circle
|
|
90
|
+
let smallest = circles[0];
|
|
91
|
+
for (i = 1; i < circles.length; ++i) {
|
|
92
|
+
if (circles[i].radius < smallest.radius) {
|
|
93
|
+
smallest = circles[i];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Make sure the smallest circle is completely contained in all
|
|
98
|
+
// the other circles
|
|
99
|
+
let disjoint = false;
|
|
100
|
+
for (i = 0; i < circles.length; ++i) {
|
|
101
|
+
if (
|
|
102
|
+
distance(circles[i], smallest) >
|
|
103
|
+
Math.abs(smallest.radius - circles[i].radius)
|
|
104
|
+
) {
|
|
105
|
+
disjoint = true;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (disjoint) {
|
|
111
|
+
arcArea = polygonArea = 0;
|
|
112
|
+
} else {
|
|
113
|
+
arcArea = smallest.radius * smallest.radius * Math.PI;
|
|
114
|
+
arcs.push({
|
|
115
|
+
circle: smallest,
|
|
116
|
+
p1: { x: smallest.x, y: smallest.y + smallest.radius },
|
|
117
|
+
p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },
|
|
118
|
+
width: smallest.radius * 2,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
polygonArea /= 2;
|
|
124
|
+
if (stats) {
|
|
125
|
+
stats.area = arcArea + polygonArea;
|
|
126
|
+
stats.arcArea = arcArea;
|
|
127
|
+
stats.polygonArea = polygonArea;
|
|
128
|
+
stats.arcs = arcs;
|
|
129
|
+
stats.innerPoints = innerPoints;
|
|
130
|
+
stats.intersectionPoints = intersectionPoints;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return arcArea + polygonArea;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Returns whether a point is contained by all of a list of circles
|
|
138
|
+
*/
|
|
139
|
+
export function containedInCircles(point, circles) {
|
|
140
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
141
|
+
if (distance(point, circles[i]) > circles[i].radius + SMALL) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Gets all intersection points between a bunch of circles */
|
|
149
|
+
function getIntersectionPoints(circles) {
|
|
150
|
+
const ret = [];
|
|
151
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
152
|
+
for (let j = i + 1; j < circles.length; ++j) {
|
|
153
|
+
const intersect = circleCircleIntersection(circles[i], circles[j]);
|
|
154
|
+
for (let k = 0; k < intersect.length; ++k) {
|
|
155
|
+
const p: any = intersect[k];
|
|
156
|
+
p.parentIndex = [i, j];
|
|
157
|
+
ret.push(p);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return ret;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html */
|
|
165
|
+
export function circleArea(r, width) {
|
|
166
|
+
return (
|
|
167
|
+
r * r * Math.acos(1 - width / r) -
|
|
168
|
+
(r - width) * Math.sqrt(width * (2 * r - width))
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Euclidean distance between two points */
|
|
173
|
+
export function distance(p1, p2) {
|
|
174
|
+
return Math.sqrt(
|
|
175
|
+
(p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Returns the overlap area of two circles of radius r1 and r2 - that
|
|
180
|
+
have their centers separated by distance d. Simpler faster
|
|
181
|
+
circle intersection for only two circles */
|
|
182
|
+
export function circleOverlap(r1, r2, d) {
|
|
183
|
+
// no overlap
|
|
184
|
+
if (d >= r1 + r2) {
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Completely overlapped
|
|
189
|
+
if (d <= Math.abs(r1 - r2)) {
|
|
190
|
+
return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d),
|
|
194
|
+
w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
|
|
195
|
+
return circleArea(r1, w1) + circleArea(r2, w2);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Given two circles (containing a x/y/radius attributes),
|
|
199
|
+
returns the intersecting points if possible.
|
|
200
|
+
note: doesn't handle cases where there are infinitely many
|
|
201
|
+
intersection points (circles are equivalent):, or only one intersection point*/
|
|
202
|
+
export function circleCircleIntersection(p1, p2) {
|
|
203
|
+
const d = distance(p1, p2),
|
|
204
|
+
r1 = p1.radius,
|
|
205
|
+
r2 = p2.radius;
|
|
206
|
+
|
|
207
|
+
// If to far away, or self contained - can't be done
|
|
208
|
+
if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d),
|
|
213
|
+
h = Math.sqrt(r1 * r1 - a * a),
|
|
214
|
+
x0 = p1.x + (a * (p2.x - p1.x)) / d,
|
|
215
|
+
y0 = p1.y + (a * (p2.y - p1.y)) / d,
|
|
216
|
+
rx = -(p2.y - p1.y) * (h / d),
|
|
217
|
+
ry = -(p2.x - p1.x) * (h / d);
|
|
218
|
+
|
|
219
|
+
return [
|
|
220
|
+
{ x: x0 + rx, y: y0 - ry },
|
|
221
|
+
{ x: x0 - rx, y: y0 + ry },
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Returns the center of a bunch of points */
|
|
226
|
+
export function getCenter(points) {
|
|
227
|
+
const center = { x: 0, y: 0 };
|
|
228
|
+
for (let i = 0; i < points.length; ++i) {
|
|
229
|
+
center.x += points[i].x;
|
|
230
|
+
center.y += points[i].y;
|
|
231
|
+
}
|
|
232
|
+
center.x /= points.length;
|
|
233
|
+
center.y /= points.length;
|
|
234
|
+
return center;
|
|
235
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { intersectionArea } from './circleintersection';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 根据圆心(x, y) 半径 r 返回圆的绘制 path
|
|
5
|
+
* @param x 圆心点 x
|
|
6
|
+
* @param y 圆心点 y
|
|
7
|
+
* @param r 圆的半径
|
|
8
|
+
* @returns 圆的 path
|
|
9
|
+
*/
|
|
10
|
+
function circlePath(x, y, r) {
|
|
11
|
+
const ret = [];
|
|
12
|
+
// ret.push('\nM', x, y);
|
|
13
|
+
// ret.push('\nm', -r, 0);
|
|
14
|
+
// ret.push('\na', r, r, 0, 1, 0, r * 2, 0);
|
|
15
|
+
// ret.push('\na', r, r, 0, 1, 0, -r * 2, 0);
|
|
16
|
+
const x0 = x - r;
|
|
17
|
+
const y0 = y;
|
|
18
|
+
ret.push('M', x0, y0);
|
|
19
|
+
ret.push('A', r, r, 0, 1, 0, x0 + 2 * r, y0);
|
|
20
|
+
ret.push('A', r, r, 0, 1, 0, x0, y0);
|
|
21
|
+
|
|
22
|
+
return ret.join(' ');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** returns a svg path of the intersection area of a bunch of circles */
|
|
26
|
+
export function intersectionAreaPath(circles) {
|
|
27
|
+
const stats: any = {};
|
|
28
|
+
intersectionArea(circles, stats);
|
|
29
|
+
const arcs = stats.arcs;
|
|
30
|
+
|
|
31
|
+
if (arcs.length === 0) {
|
|
32
|
+
return 'M 0 0';
|
|
33
|
+
} else if (arcs.length == 1) {
|
|
34
|
+
const circle = arcs[0].circle;
|
|
35
|
+
return circlePath(circle.x, circle.y, circle.radius);
|
|
36
|
+
} else {
|
|
37
|
+
// draw path around arcs
|
|
38
|
+
const ret = ['\nM', arcs[0].p2.x, arcs[0].p2.y];
|
|
39
|
+
for (let i = 0; i < arcs.length; ++i) {
|
|
40
|
+
const arc = arcs[i],
|
|
41
|
+
r = arc.circle.radius,
|
|
42
|
+
wide = arc.width > r;
|
|
43
|
+
ret.push('\nA', r, r, 0, wide ? 1 : 0, 1, arc.p1.x, arc.p1.y);
|
|
44
|
+
}
|
|
45
|
+
return ret.join(' ');
|
|
46
|
+
}
|
|
47
|
+
}
|