@antv/g2plot 2.3.31 → 2.3.35
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 +1270 -0
- package/{README.zh-CN.md → README.en-US.md} +33 -42
- package/README.md +43 -32
- package/dist/g2plot.min.js +3 -18
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/common.d.ts +1 -0
- package/esm/adaptor/common.js +1 -0
- package/esm/adaptor/common.js.map +1 -1
- package/esm/adaptor/pattern.d.ts +10 -0
- package/esm/adaptor/pattern.js +54 -0
- package/esm/adaptor/pattern.js.map +1 -0
- package/esm/core/plot.d.ts +11 -1
- package/esm/core/plot.js +42 -1
- package/esm/core/plot.js.map +1 -1
- package/esm/index.d.ts +5 -1
- package/esm/index.js +5 -1
- package/esm/index.js.map +1 -1
- package/esm/plots/area/adaptor.js +2 -2
- package/esm/plots/area/adaptor.js.map +1 -1
- package/esm/plots/circle-packing/adaptor.js +4 -4
- package/esm/plots/circle-packing/adaptor.js.map +1 -1
- package/esm/plots/circle-packing/utils.d.ts +0 -5
- package/esm/plots/circle-packing/utils.js +1 -20
- package/esm/plots/circle-packing/utils.js.map +1 -1
- package/esm/plots/column/adaptor.js +3 -2
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/dual-axes/adaptor.js +6 -4
- package/esm/plots/dual-axes/adaptor.js.map +1 -1
- package/esm/plots/dual-axes/types.d.ts +2 -1
- package/esm/plots/dual-axes/types.js.map +1 -1
- package/esm/plots/dual-axes/util/geometry.js +3 -2
- package/esm/plots/dual-axes/util/geometry.js.map +1 -1
- package/esm/plots/dual-axes/util/legend.js +4 -1
- package/esm/plots/dual-axes/util/legend.js.map +1 -1
- package/esm/plots/funnel/geometries/basic.js +2 -7
- package/esm/plots/funnel/geometries/basic.js.map +1 -1
- package/esm/plots/heatmap/adaptor.js +2 -2
- package/esm/plots/heatmap/adaptor.js.map +1 -1
- package/esm/plots/heatmap/types.d.ts +4 -2
- package/esm/plots/heatmap/types.js.map +1 -1
- package/esm/plots/histogram/adaptor.js +2 -1
- package/esm/plots/histogram/adaptor.js.map +1 -1
- package/esm/plots/liquid/adaptor.js +2 -2
- package/esm/plots/liquid/adaptor.js.map +1 -1
- package/esm/plots/pie/adaptor.js +2 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/plots/radial-bar/adaptor.js +2 -1
- package/esm/plots/radial-bar/adaptor.js.map +1 -1
- package/esm/plots/rose/adaptor.js +2 -2
- package/esm/plots/rose/adaptor.js.map +1 -1
- package/esm/plots/sunburst/adaptor.js +2 -2
- package/esm/plots/sunburst/adaptor.js.map +1 -1
- package/esm/plots/tiny-area/adaptor.js +2 -2
- package/esm/plots/tiny-area/adaptor.js.map +1 -1
- package/esm/plots/tiny-column/adaptor.js +2 -2
- package/esm/plots/tiny-column/adaptor.js.map +1 -1
- package/esm/plots/treemap/adaptor.js +2 -1
- package/esm/plots/treemap/adaptor.js.map +1 -1
- package/esm/plots/venn/adaptor.d.ts +23 -0
- package/esm/plots/venn/adaptor.js +177 -0
- package/esm/plots/venn/adaptor.js.map +1 -0
- package/esm/plots/venn/constant.d.ts +7 -0
- package/esm/plots/venn/constant.js +33 -0
- package/esm/plots/venn/constant.js.map +1 -0
- package/esm/plots/venn/index.d.ts +24 -0
- package/esm/plots/venn/index.js +47 -0
- package/esm/plots/venn/index.js.map +1 -0
- package/esm/plots/venn/interaction/action.d.ts +18 -0
- package/esm/plots/venn/interaction/action.js +77 -0
- package/esm/plots/venn/interaction/action.js.map +1 -0
- package/esm/plots/venn/interaction/index.d.ts +1 -0
- package/esm/plots/venn/interaction/index.js +15 -0
- package/esm/plots/venn/interaction/index.js.map +1 -0
- package/esm/plots/venn/label.d.ts +1 -0
- package/esm/plots/venn/label.js +31 -0
- package/esm/plots/venn/label.js.map +1 -0
- package/esm/plots/venn/layout/circleintersection.d.ts +29 -0
- package/esm/plots/venn/layout/circleintersection.js +186 -0
- package/esm/plots/venn/layout/circleintersection.js.map +1 -0
- package/esm/plots/venn/layout/diagram.d.ts +17 -0
- package/esm/plots/venn/layout/diagram.js +193 -0
- package/esm/plots/venn/layout/diagram.js.map +1 -0
- package/esm/plots/venn/layout/layout.d.ts +27 -0
- package/esm/plots/venn/layout/layout.js +593 -0
- package/esm/plots/venn/layout/layout.js.map +1 -0
- package/esm/plots/venn/shape.d.ts +1 -0
- package/esm/plots/venn/shape.js +42 -0
- package/esm/plots/venn/shape.js.map +1 -0
- package/esm/plots/venn/types.d.ts +27 -0
- package/esm/plots/venn/types.js +2 -0
- package/esm/plots/venn/types.js.map +1 -0
- package/esm/plots/venn/utils.d.ts +28 -0
- package/esm/plots/venn/utils.js +93 -0
- package/esm/plots/venn/utils.js.map +1 -0
- package/esm/types/annotation.d.ts +5 -1
- package/esm/types/annotation.js.map +1 -1
- package/esm/types/attr.d.ts +4 -1
- package/esm/types/attr.js.map +1 -1
- package/esm/types/common.d.ts +3 -1
- package/esm/types/common.js.map +1 -1
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/types/pattern.d.ts +47 -0
- package/esm/types/pattern.js +1 -0
- package/esm/types/pattern.js.map +1 -0
- package/esm/utils/color/blend.d.ts +20 -0
- package/esm/utils/color/blend.js +92 -0
- package/esm/utils/color/blend.js.map +1 -0
- package/esm/utils/padding.d.ts +5 -0
- package/esm/utils/padding.js +19 -0
- package/esm/utils/padding.js.map +1 -1
- package/esm/utils/pattern/dot.d.ts +32 -0
- package/esm/utils/pattern/dot.js +69 -0
- package/esm/utils/pattern/dot.js.map +1 -0
- package/esm/utils/pattern/index.d.ts +17 -0
- package/esm/utils/pattern/index.js +27 -0
- package/esm/utils/pattern/index.js.map +1 -0
- package/esm/utils/pattern/line.d.ts +25 -0
- package/esm/utils/pattern/line.js +56 -0
- package/esm/utils/pattern/line.js.map +1 -0
- package/esm/utils/pattern/square.d.ts +28 -0
- package/esm/utils/pattern/square.js +61 -0
- package/esm/utils/pattern/square.js.map +1 -0
- package/esm/utils/pattern/util.d.ts +50 -0
- package/esm/utils/pattern/util.js +90 -0
- package/esm/utils/pattern/util.js.map +1 -0
- package/lib/adaptor/common.d.ts +1 -0
- package/lib/adaptor/common.js +2 -0
- package/lib/adaptor/common.js.map +1 -1
- package/lib/adaptor/pattern.d.ts +10 -0
- package/lib/adaptor/pattern.js +58 -0
- package/lib/adaptor/pattern.js.map +1 -0
- package/lib/core/plot.d.ts +11 -1
- package/lib/core/plot.js +41 -0
- package/lib/core/plot.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/plots/area/adaptor.js +1 -1
- package/lib/plots/area/adaptor.js.map +1 -1
- package/lib/plots/circle-packing/adaptor.js +2 -2
- package/lib/plots/circle-packing/adaptor.js.map +1 -1
- package/lib/plots/circle-packing/utils.d.ts +0 -5
- package/lib/plots/circle-packing/utils.js +2 -22
- package/lib/plots/circle-packing/utils.js.map +1 -1
- package/lib/plots/column/adaptor.js +3 -2
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/dual-axes/adaptor.js +6 -4
- package/lib/plots/dual-axes/adaptor.js.map +1 -1
- package/lib/plots/dual-axes/types.d.ts +2 -1
- package/lib/plots/dual-axes/types.js.map +1 -1
- package/lib/plots/dual-axes/util/geometry.js +2 -1
- package/lib/plots/dual-axes/util/geometry.js.map +1 -1
- package/lib/plots/dual-axes/util/legend.js +4 -1
- package/lib/plots/dual-axes/util/legend.js.map +1 -1
- package/lib/plots/funnel/geometries/basic.js +1 -6
- package/lib/plots/funnel/geometries/basic.js.map +1 -1
- package/lib/plots/heatmap/adaptor.js +1 -1
- package/lib/plots/heatmap/adaptor.js.map +1 -1
- package/lib/plots/heatmap/types.d.ts +4 -2
- package/lib/plots/heatmap/types.js.map +1 -1
- package/lib/plots/histogram/adaptor.js +2 -1
- package/lib/plots/histogram/adaptor.js.map +1 -1
- package/lib/plots/liquid/adaptor.js +1 -1
- package/lib/plots/liquid/adaptor.js.map +1 -1
- package/lib/plots/pie/adaptor.js +2 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/plots/radial-bar/adaptor.js +2 -1
- package/lib/plots/radial-bar/adaptor.js.map +1 -1
- package/lib/plots/rose/adaptor.js +1 -1
- package/lib/plots/rose/adaptor.js.map +1 -1
- package/lib/plots/sunburst/adaptor.js +1 -1
- package/lib/plots/sunburst/adaptor.js.map +1 -1
- package/lib/plots/tiny-area/adaptor.js +1 -1
- package/lib/plots/tiny-area/adaptor.js.map +1 -1
- package/lib/plots/tiny-column/adaptor.js +1 -1
- package/lib/plots/tiny-column/adaptor.js.map +1 -1
- package/lib/plots/treemap/adaptor.js +2 -1
- package/lib/plots/treemap/adaptor.js.map +1 -1
- package/lib/plots/venn/adaptor.d.ts +23 -0
- package/lib/plots/venn/adaptor.js +183 -0
- package/lib/plots/venn/adaptor.js.map +1 -0
- package/lib/plots/venn/constant.d.ts +7 -0
- package/lib/plots/venn/constant.js +36 -0
- package/lib/plots/venn/constant.js.map +1 -0
- package/lib/plots/venn/index.d.ts +24 -0
- package/lib/plots/venn/index.js +50 -0
- package/lib/plots/venn/index.js.map +1 -0
- package/lib/plots/venn/interaction/action.d.ts +18 -0
- package/lib/plots/venn/interaction/action.js +80 -0
- package/lib/plots/venn/interaction/action.js.map +1 -0
- package/lib/plots/venn/interaction/index.d.ts +1 -0
- package/lib/plots/venn/interaction/index.js +17 -0
- package/lib/plots/venn/interaction/index.js.map +1 -0
- package/lib/plots/venn/label.d.ts +1 -0
- package/lib/plots/venn/label.js +33 -0
- package/lib/plots/venn/label.js.map +1 -0
- package/lib/plots/venn/layout/circleintersection.d.ts +29 -0
- package/lib/plots/venn/layout/circleintersection.js +196 -0
- package/lib/plots/venn/layout/circleintersection.js.map +1 -0
- package/lib/plots/venn/layout/diagram.d.ts +17 -0
- package/lib/plots/venn/layout/diagram.js +201 -0
- package/lib/plots/venn/layout/diagram.js.map +1 -0
- package/lib/plots/venn/layout/layout.d.ts +27 -0
- package/lib/plots/venn/layout/layout.js +606 -0
- package/lib/plots/venn/layout/layout.js.map +1 -0
- package/lib/plots/venn/shape.d.ts +1 -0
- package/lib/plots/venn/shape.js +44 -0
- package/lib/plots/venn/shape.js.map +1 -0
- package/lib/plots/venn/types.d.ts +27 -0
- package/lib/plots/venn/types.js +4 -0
- package/lib/plots/venn/types.js.map +1 -0
- package/lib/plots/venn/utils.d.ts +28 -0
- package/lib/plots/venn/utils.js +98 -0
- package/lib/plots/venn/utils.js.map +1 -0
- package/lib/types/annotation.d.ts +5 -1
- package/lib/types/annotation.js.map +1 -1
- package/lib/types/attr.d.ts +4 -1
- package/lib/types/attr.js.map +1 -1
- package/lib/types/common.d.ts +3 -1
- package/lib/types/common.js.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/pattern.d.ts +47 -0
- package/lib/types/pattern.js +3 -0
- package/lib/types/pattern.js.map +1 -0
- package/lib/utils/color/blend.d.ts +20 -0
- package/lib/utils/color/blend.js +98 -0
- package/lib/utils/color/blend.js.map +1 -0
- package/lib/utils/padding.d.ts +5 -0
- package/lib/utils/padding.js +21 -1
- package/lib/utils/padding.js.map +1 -1
- package/lib/utils/pattern/dot.d.ts +32 -0
- package/lib/utils/pattern/dot.js +74 -0
- package/lib/utils/pattern/dot.js.map +1 -0
- package/lib/utils/pattern/index.d.ts +17 -0
- package/lib/utils/pattern/index.js +31 -0
- package/lib/utils/pattern/index.js.map +1 -0
- package/lib/utils/pattern/line.d.ts +25 -0
- package/lib/utils/pattern/line.js +61 -0
- package/lib/utils/pattern/line.js.map +1 -0
- package/lib/utils/pattern/square.d.ts +28 -0
- package/lib/utils/pattern/square.js +66 -0
- package/lib/utils/pattern/square.js.map +1 -0
- package/lib/utils/pattern/util.d.ts +50 -0
- package/lib/utils/pattern/util.js +99 -0
- package/lib/utils/pattern/util.js.map +1 -0
- package/package.json +10 -8
- package/src/adaptor/common.ts +2 -0
- package/src/adaptor/pattern.ts +66 -0
- package/src/core/plot.ts +43 -1
- package/src/index.ts +8 -1
- package/src/plots/area/adaptor.ts +3 -2
- package/src/plots/circle-packing/adaptor.ts +12 -3
- package/src/plots/circle-packing/utils.ts +1 -21
- package/src/plots/column/adaptor.ts +3 -1
- package/src/plots/dual-axes/adaptor.ts +6 -4
- package/src/plots/dual-axes/types.ts +11 -1
- package/src/plots/dual-axes/util/geometry.ts +3 -2
- package/src/plots/dual-axes/util/legend.ts +4 -1
- package/src/plots/funnel/geometries/basic.ts +2 -10
- package/src/plots/heatmap/adaptor.ts +12 -1
- package/src/plots/heatmap/types.ts +6 -2
- package/src/plots/histogram/adaptor.ts +13 -1
- package/src/plots/liquid/adaptor.ts +2 -2
- package/src/plots/pie/adaptor.ts +2 -0
- package/src/plots/radial-bar/adaptor.ts +2 -0
- package/src/plots/rose/adaptor.ts +2 -1
- package/src/plots/sunburst/adaptor.ts +2 -1
- package/src/plots/tiny-area/adaptor.ts +2 -2
- package/src/plots/tiny-column/adaptor.ts +2 -2
- package/src/plots/treemap/adaptor.ts +13 -1
- package/src/plots/venn/adaptor.ts +227 -0
- package/src/plots/venn/constant.ts +35 -0
- package/src/plots/venn/index.ts +47 -0
- package/src/plots/venn/interaction/action.ts +67 -0
- package/src/plots/venn/interaction/index.ts +17 -0
- package/src/plots/venn/label.ts +26 -0
- package/src/plots/venn/layout/circleintersection.ts +223 -0
- package/src/plots/venn/layout/diagram.ts +219 -0
- package/src/plots/venn/layout/layout.ts +734 -0
- package/src/plots/venn/shape.ts +53 -0
- package/src/plots/venn/types.ts +25 -0
- package/src/plots/venn/utils.ts +100 -0
- package/src/types/annotation.ts +3 -1
- package/src/types/attr.ts +7 -1
- package/src/types/common.ts +3 -1
- package/src/types/index.ts +1 -0
- package/src/types/pattern.ts +50 -0
- package/src/utils/color/blend.ts +103 -0
- package/src/utils/padding.ts +20 -0
- package/src/utils/pattern/dot.ts +86 -0
- package/src/utils/pattern/index.ts +45 -0
- package/src/utils/pattern/line.ts +70 -0
- package/src/utils/pattern/square.ts +78 -0
- package/src/utils/pattern/util.ts +104 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
var SMALL = 1e-10;
|
|
2
|
+
/** Returns the intersection area of a bunch of circles (where each circle
|
|
3
|
+
is an object having an x,y and radius property) */
|
|
4
|
+
export function intersectionArea(circles, stats) {
|
|
5
|
+
// get all the intersection points of the circles
|
|
6
|
+
var intersectionPoints = getIntersectionPoints(circles);
|
|
7
|
+
// filter out points that aren't included in all the circles
|
|
8
|
+
var innerPoints = intersectionPoints.filter(function (p) {
|
|
9
|
+
return containedInCircles(p, circles);
|
|
10
|
+
});
|
|
11
|
+
var arcArea = 0, polygonArea = 0, i;
|
|
12
|
+
var arcs = [];
|
|
13
|
+
// if we have intersection points that are within all the circles,
|
|
14
|
+
// then figure out the area contained by them
|
|
15
|
+
if (innerPoints.length > 1) {
|
|
16
|
+
// sort the points by angle from the center of the polygon, which lets
|
|
17
|
+
// us just iterate over points to get the edges
|
|
18
|
+
var center = getCenter(innerPoints);
|
|
19
|
+
for (i = 0; i < innerPoints.length; ++i) {
|
|
20
|
+
var p = innerPoints[i];
|
|
21
|
+
p.angle = Math.atan2(p.x - center.x, p.y - center.y);
|
|
22
|
+
}
|
|
23
|
+
innerPoints.sort(function (a, b) {
|
|
24
|
+
return b.angle - a.angle;
|
|
25
|
+
});
|
|
26
|
+
// iterate over all points, get arc between the points
|
|
27
|
+
// and update the areas
|
|
28
|
+
var p2 = innerPoints[innerPoints.length - 1];
|
|
29
|
+
for (i = 0; i < innerPoints.length; ++i) {
|
|
30
|
+
var p1 = innerPoints[i];
|
|
31
|
+
// polygon area updates easily ...
|
|
32
|
+
polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
|
|
33
|
+
// updating the arc area is a little more involved
|
|
34
|
+
var midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
35
|
+
var arc = null;
|
|
36
|
+
for (var j = 0; j < p1.parentIndex.length; ++j) {
|
|
37
|
+
if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {
|
|
38
|
+
// figure out the angle halfway between the two points
|
|
39
|
+
// on the current circle
|
|
40
|
+
var circle = circles[p1.parentIndex[j]], a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y), a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
|
|
41
|
+
var angleDiff = a2 - a1;
|
|
42
|
+
if (angleDiff < 0) {
|
|
43
|
+
angleDiff += 2 * Math.PI;
|
|
44
|
+
}
|
|
45
|
+
// and use that angle to figure out the width of the
|
|
46
|
+
// arc
|
|
47
|
+
var a = a2 - angleDiff / 2;
|
|
48
|
+
var width = distance(midPoint, {
|
|
49
|
+
x: circle.x + circle.radius * Math.sin(a),
|
|
50
|
+
y: circle.y + circle.radius * Math.cos(a),
|
|
51
|
+
});
|
|
52
|
+
// clamp the width to the largest is can actually be
|
|
53
|
+
// (sometimes slightly overflows because of FP errors)
|
|
54
|
+
if (width > circle.radius * 2) {
|
|
55
|
+
width = circle.radius * 2;
|
|
56
|
+
}
|
|
57
|
+
// pick the circle whose arc has the smallest width
|
|
58
|
+
if (arc === null || arc.width > width) {
|
|
59
|
+
arc = { circle: circle, width: width, p1: p1, p2: p2 };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (arc !== null) {
|
|
64
|
+
arcs.push(arc);
|
|
65
|
+
arcArea += circleArea(arc.circle.radius, arc.width);
|
|
66
|
+
p2 = p1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// no intersection points, is either disjoint - or is completely
|
|
72
|
+
// overlapped. figure out which by examining the smallest circle
|
|
73
|
+
var smallest = circles[0];
|
|
74
|
+
for (i = 1; i < circles.length; ++i) {
|
|
75
|
+
if (circles[i].radius < smallest.radius) {
|
|
76
|
+
smallest = circles[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// make sure the smallest circle is completely contained in all
|
|
80
|
+
// the other circles
|
|
81
|
+
var disjoint = false;
|
|
82
|
+
for (i = 0; i < circles.length; ++i) {
|
|
83
|
+
if (distance(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
|
|
84
|
+
disjoint = true;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (disjoint) {
|
|
89
|
+
arcArea = polygonArea = 0;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
arcArea = smallest.radius * smallest.radius * Math.PI;
|
|
93
|
+
arcs.push({
|
|
94
|
+
circle: smallest,
|
|
95
|
+
p1: { x: smallest.x, y: smallest.y + smallest.radius },
|
|
96
|
+
p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },
|
|
97
|
+
width: smallest.radius * 2,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
polygonArea /= 2;
|
|
102
|
+
if (stats) {
|
|
103
|
+
stats.area = arcArea + polygonArea;
|
|
104
|
+
stats.arcArea = arcArea;
|
|
105
|
+
stats.polygonArea = polygonArea;
|
|
106
|
+
stats.arcs = arcs;
|
|
107
|
+
stats.innerPoints = innerPoints;
|
|
108
|
+
stats.intersectionPoints = intersectionPoints;
|
|
109
|
+
}
|
|
110
|
+
return arcArea + polygonArea;
|
|
111
|
+
}
|
|
112
|
+
/** returns whether a point is contained by all of a list of circles */
|
|
113
|
+
export function containedInCircles(point, circles) {
|
|
114
|
+
for (var i = 0; i < circles.length; ++i) {
|
|
115
|
+
if (distance(point, circles[i]) > circles[i].radius + SMALL) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
/** Gets all intersection points between a bunch of circles */
|
|
122
|
+
function getIntersectionPoints(circles) {
|
|
123
|
+
var ret = [];
|
|
124
|
+
for (var i = 0; i < circles.length; ++i) {
|
|
125
|
+
for (var j = i + 1; j < circles.length; ++j) {
|
|
126
|
+
var intersect = circleCircleIntersection(circles[i], circles[j]);
|
|
127
|
+
for (var k = 0; k < intersect.length; ++k) {
|
|
128
|
+
var p = intersect[k];
|
|
129
|
+
p.parentIndex = [i, j];
|
|
130
|
+
ret.push(p);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return ret;
|
|
135
|
+
}
|
|
136
|
+
/** Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html */
|
|
137
|
+
export function circleArea(r, width) {
|
|
138
|
+
return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
|
|
139
|
+
}
|
|
140
|
+
/** euclidean distance between two points */
|
|
141
|
+
export function distance(p1, p2) {
|
|
142
|
+
return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
|
|
143
|
+
}
|
|
144
|
+
/** Returns the overlap area of two circles of radius r1 and r2 - that
|
|
145
|
+
have their centers separated by distance d. Simpler faster
|
|
146
|
+
circle intersection for only two circles */
|
|
147
|
+
export function circleOverlap(r1, r2, d) {
|
|
148
|
+
// no overlap
|
|
149
|
+
if (d >= r1 + r2) {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
// completely overlapped
|
|
153
|
+
if (d <= Math.abs(r1 - r2)) {
|
|
154
|
+
return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
|
|
155
|
+
}
|
|
156
|
+
var w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d), w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
|
|
157
|
+
return circleArea(r1, w1) + circleArea(r2, w2);
|
|
158
|
+
}
|
|
159
|
+
/** Given two circles (containing a x/y/radius attributes),
|
|
160
|
+
returns the intersecting points if possible.
|
|
161
|
+
note: doesn't handle cases where there are infinitely many
|
|
162
|
+
intersection points (circles are equivalent):, or only one intersection point*/
|
|
163
|
+
export function circleCircleIntersection(p1, p2) {
|
|
164
|
+
var d = distance(p1, p2), r1 = p1.radius, r2 = p2.radius;
|
|
165
|
+
// if to far away, or self contained - can't be done
|
|
166
|
+
if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
var a = (r1 * r1 - r2 * r2 + d * d) / (2 * d), h = Math.sqrt(r1 * r1 - a * a), x0 = p1.x + (a * (p2.x - p1.x)) / d, y0 = p1.y + (a * (p2.y - p1.y)) / d, rx = -(p2.y - p1.y) * (h / d), ry = -(p2.x - p1.x) * (h / d);
|
|
170
|
+
return [
|
|
171
|
+
{ x: x0 + rx, y: y0 - ry },
|
|
172
|
+
{ x: x0 - rx, y: y0 + ry },
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
/** Returns the center of a bunch of points */
|
|
176
|
+
export function getCenter(points) {
|
|
177
|
+
var center = { x: 0, y: 0 };
|
|
178
|
+
for (var i = 0; i < points.length; ++i) {
|
|
179
|
+
center.x += points[i].x;
|
|
180
|
+
center.y += points[i].y;
|
|
181
|
+
}
|
|
182
|
+
center.x /= points.length;
|
|
183
|
+
center.y /= points.length;
|
|
184
|
+
return center;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=circleintersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circleintersection.js","sourceRoot":"","sources":["../../../../src/plots/venn/layout/circleintersection.ts"],"names":[],"mappings":"AAAA,IAAM,KAAK,GAAG,KAAK,CAAC;AAEpB;mDACmD;AACnD,MAAM,UAAU,gBAAgB,CAAC,OAAO,EAAE,KAAW;IACnD,iDAAiD;IACjD,IAAM,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAE1D,4DAA4D;IAC5D,IAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC;QACvD,OAAO,kBAAkB,CAAC,CAAC,EAAE,OAA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AAE,EAAE,GAAG,EAAE,EAAE;KAC3B,CAAC;AACJ,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,SAAS,CAAC,MAAM;IAC9B,IAAM,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACtC,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACzB;IACD,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC;IAC1B,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["const SMALL = 1e-10;\n\n/** Returns the intersection area of a bunch of circles (where each circle\n is an object having an x,y and radius property) */\nexport function intersectionArea(circles, stats?: any) {\n // get all the intersection points of the circles\n const intersectionPoints = getIntersectionPoints(circles);\n\n // filter out points that aren't included in all the circles\n const innerPoints = intersectionPoints.filter(function (p) {\n return containedInCircles(p, circles);\n });\n\n let arcArea = 0,\n polygonArea = 0,\n i;\n const arcs = [];\n // if we have intersection points that are within all the circles,\n // then figure out the area contained by them\n if (innerPoints.length > 1) {\n // sort the points by angle from the center of the polygon, which lets\n // us just iterate over points to get the edges\n const center = getCenter(innerPoints);\n for (i = 0; i < innerPoints.length; ++i) {\n const p = innerPoints[i];\n p.angle = Math.atan2(p.x - center.x, p.y - center.y);\n }\n innerPoints.sort(function (a, b) {\n return b.angle - a.angle;\n });\n\n // iterate over all points, get arc between the points\n // and update the areas\n let p2 = innerPoints[innerPoints.length - 1];\n for (i = 0; i < innerPoints.length; ++i) {\n const p1 = innerPoints[i];\n\n // polygon area updates easily ...\n polygonArea += (p2.x + p1.x) * (p1.y - p2.y);\n\n // updating the arc area is a little more involved\n const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };\n let arc = null;\n\n for (let j = 0; j < p1.parentIndex.length; ++j) {\n if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {\n // figure out the angle halfway between the two points\n // on the current circle\n const circle = circles[p1.parentIndex[j]],\n a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y),\n a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);\n\n let angleDiff = a2 - a1;\n if (angleDiff < 0) {\n angleDiff += 2 * Math.PI;\n }\n\n // and use that angle to figure out the width of the\n // arc\n const a = a2 - angleDiff / 2;\n let width = distance(midPoint, {\n x: circle.x + circle.radius * Math.sin(a),\n y: circle.y + circle.radius * Math.cos(a),\n });\n\n // clamp the width to the largest is can actually be\n // (sometimes slightly overflows because of FP errors)\n if (width > circle.radius * 2) {\n width = circle.radius * 2;\n }\n\n // pick the circle whose arc has the smallest width\n if (arc === null || arc.width > width) {\n arc = { circle: circle, width: width, p1: p1, p2: p2 };\n }\n }\n }\n\n if (arc !== null) {\n arcs.push(arc);\n arcArea += circleArea(arc.circle.radius, arc.width);\n p2 = p1;\n }\n }\n } else {\n // no intersection points, is either disjoint - or is completely\n // overlapped. figure out which by examining the smallest circle\n let smallest = circles[0];\n for (i = 1; i < circles.length; ++i) {\n if (circles[i].radius < smallest.radius) {\n smallest = circles[i];\n }\n }\n\n // make sure the smallest circle is completely contained in all\n // the other circles\n let disjoint = false;\n for (i = 0; i < circles.length; ++i) {\n if (distance(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {\n disjoint = true;\n break;\n }\n }\n\n if (disjoint) {\n arcArea = polygonArea = 0;\n } else {\n arcArea = smallest.radius * smallest.radius * Math.PI;\n arcs.push({\n circle: smallest,\n p1: { x: smallest.x, y: smallest.y + smallest.radius },\n p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },\n width: smallest.radius * 2,\n });\n }\n }\n\n polygonArea /= 2;\n if (stats) {\n stats.area = arcArea + polygonArea;\n stats.arcArea = arcArea;\n stats.polygonArea = polygonArea;\n stats.arcs = arcs;\n stats.innerPoints = innerPoints;\n stats.intersectionPoints = intersectionPoints;\n }\n\n return arcArea + polygonArea;\n}\n\n/** returns whether a point is contained by all of a list of circles */\nexport function containedInCircles(point, circles) {\n for (let i = 0; i < circles.length; ++i) {\n if (distance(point, circles[i]) > circles[i].radius + SMALL) {\n return false;\n }\n }\n return true;\n}\n\n/** Gets all intersection points between a bunch of circles */\nfunction getIntersectionPoints(circles) {\n const ret = [];\n for (let i = 0; i < circles.length; ++i) {\n for (let j = i + 1; j < circles.length; ++j) {\n const intersect = circleCircleIntersection(circles[i], circles[j]);\n for (let k = 0; k < intersect.length; ++k) {\n const p: any = intersect[k];\n p.parentIndex = [i, j];\n ret.push(p);\n }\n }\n }\n return ret;\n}\n\n/** Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html */\nexport function circleArea(r, width) {\n return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));\n}\n\n/** euclidean distance between two points */\nexport function distance(p1, p2) {\n return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));\n}\n\n/** Returns the overlap area of two circles of radius r1 and r2 - that\nhave their centers separated by distance d. Simpler faster\ncircle intersection for only two circles */\nexport function circleOverlap(r1, r2, d) {\n // no overlap\n if (d >= r1 + r2) {\n return 0;\n }\n\n // completely overlapped\n if (d <= Math.abs(r1 - r2)) {\n return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);\n }\n\n const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d),\n w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);\n return circleArea(r1, w1) + circleArea(r2, w2);\n}\n\n/** Given two circles (containing a x/y/radius attributes),\nreturns the intersecting points if possible.\nnote: doesn't handle cases where there are infinitely many\nintersection points (circles are equivalent):, or only one intersection point*/\nexport function circleCircleIntersection(p1, p2) {\n const d = distance(p1, p2),\n r1 = p1.radius,\n r2 = p2.radius;\n\n // if to far away, or self contained - can't be done\n if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {\n return [];\n }\n\n const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d),\n h = Math.sqrt(r1 * r1 - a * a),\n x0 = p1.x + (a * (p2.x - p1.x)) / d,\n y0 = p1.y + (a * (p2.y - p1.y)) / d,\n rx = -(p2.y - p1.y) * (h / d),\n ry = -(p2.x - p1.x) * (h / d);\n\n return [\n { x: x0 + rx, y: y0 - ry },\n { x: x0 - rx, y: y0 + ry },\n ];\n}\n\n/** Returns the center of a bunch of points */\nexport function getCenter(points) {\n const center = { x: 0, y: 0 };\n for (let i = 0; i < points.length; ++i) {\n center.x += points[i].x;\n center.y += points[i].y;\n }\n center.x /= points.length;\n center.y /= points.length;\n return center;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function computeTextCentre(interior: any, exterior: any): any;
|
|
2
|
+
export declare function computeTextCentres(circles: any, areas: any): {};
|
|
3
|
+
/**
|
|
4
|
+
* 根据圆心(x, y) 半径 r 返回圆的绘制 path
|
|
5
|
+
* @param x 圆心点 x
|
|
6
|
+
* @param y 圆心点 y
|
|
7
|
+
* @param r 圆的半径
|
|
8
|
+
* @returns 圆的 path
|
|
9
|
+
*/
|
|
10
|
+
export declare function circlePath(x: any, y: any, r: any): string;
|
|
11
|
+
export declare function circleFromPath(path: any): {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
radius: number;
|
|
15
|
+
};
|
|
16
|
+
/** returns a svg path of the intersection area of a bunch of circles */
|
|
17
|
+
export declare function intersectionAreaPath(circles: any): string;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { nelderMead } from 'fmin';
|
|
2
|
+
import { intersectionArea, distance, getCenter } from './circleintersection';
|
|
3
|
+
function circleMargin(current, interior, exterior) {
|
|
4
|
+
var margin = interior[0].radius - distance(interior[0], current), i, m;
|
|
5
|
+
for (i = 1; i < interior.length; ++i) {
|
|
6
|
+
m = interior[i].radius - distance(interior[i], current);
|
|
7
|
+
if (m <= margin) {
|
|
8
|
+
margin = m;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (i = 0; i < exterior.length; ++i) {
|
|
12
|
+
m = distance(exterior[i], current) - exterior[i].radius;
|
|
13
|
+
if (m <= margin) {
|
|
14
|
+
margin = m;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return margin;
|
|
18
|
+
}
|
|
19
|
+
// compute the center of some circles by maximizing the margin of
|
|
20
|
+
// the center point relative to the circles (interior) after subtracting
|
|
21
|
+
// nearby circles (exterior)
|
|
22
|
+
export function computeTextCentre(interior, exterior) {
|
|
23
|
+
// get an initial estimate by sampling around the interior circles
|
|
24
|
+
// and taking the point with the biggest margin
|
|
25
|
+
var points = [];
|
|
26
|
+
var i;
|
|
27
|
+
for (i = 0; i < interior.length; ++i) {
|
|
28
|
+
var c = interior[i];
|
|
29
|
+
points.push({ x: c.x, y: c.y });
|
|
30
|
+
points.push({ x: c.x + c.radius / 2, y: c.y });
|
|
31
|
+
points.push({ x: c.x - c.radius / 2, y: c.y });
|
|
32
|
+
points.push({ x: c.x, y: c.y + c.radius / 2 });
|
|
33
|
+
points.push({ x: c.x, y: c.y - c.radius / 2 });
|
|
34
|
+
}
|
|
35
|
+
var initial = points[0], margin = circleMargin(points[0], interior, exterior);
|
|
36
|
+
for (i = 1; i < points.length; ++i) {
|
|
37
|
+
var m = circleMargin(points[i], interior, exterior);
|
|
38
|
+
if (m >= margin) {
|
|
39
|
+
initial = points[i];
|
|
40
|
+
margin = m;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// maximize the margin numerically
|
|
44
|
+
var solution = nelderMead(function (p) {
|
|
45
|
+
return -1 * circleMargin({ x: p[0], y: p[1] }, interior, exterior);
|
|
46
|
+
}, [initial.x, initial.y], { maxIterations: 500, minErrorDelta: 1e-10 }).x;
|
|
47
|
+
var ret = { x: solution[0], y: solution[1] };
|
|
48
|
+
// check solution, fallback as needed (happens if fully overlapped
|
|
49
|
+
// etc)
|
|
50
|
+
var valid = true;
|
|
51
|
+
for (i = 0; i < interior.length; ++i) {
|
|
52
|
+
if (distance(ret, interior[i]) > interior[i].radius) {
|
|
53
|
+
valid = false;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (i = 0; i < exterior.length; ++i) {
|
|
58
|
+
if (distance(ret, exterior[i]) < exterior[i].radius) {
|
|
59
|
+
valid = false;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!valid) {
|
|
64
|
+
if (interior.length == 1) {
|
|
65
|
+
ret = { x: interior[0].x, y: interior[0].y };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
var areaStats = {};
|
|
69
|
+
intersectionArea(interior, areaStats);
|
|
70
|
+
if (areaStats.arcs.length === 0) {
|
|
71
|
+
ret = { x: 0, y: -1000, disjoint: true };
|
|
72
|
+
}
|
|
73
|
+
else if (areaStats.arcs.length == 1) {
|
|
74
|
+
ret = { x: areaStats.arcs[0].circle.x, y: areaStats.arcs[0].circle.y };
|
|
75
|
+
}
|
|
76
|
+
else if (exterior.length) {
|
|
77
|
+
// try again without other circles
|
|
78
|
+
ret = computeTextCentre(interior, []);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// take average of all the points in the intersection
|
|
82
|
+
// polygon. this should basically never happen
|
|
83
|
+
// and has some issues:
|
|
84
|
+
// https://github.com/benfred/venn.js/issues/48#issuecomment-146069777
|
|
85
|
+
ret = getCenter(areaStats.arcs.map(function (a) {
|
|
86
|
+
return a.p1;
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return ret;
|
|
92
|
+
}
|
|
93
|
+
// given a dictionary of {setid : circle}, returns
|
|
94
|
+
// a dictionary of setid to list of circles that completely overlap it
|
|
95
|
+
function getOverlappingCircles(circles) {
|
|
96
|
+
var ret = {}, circleids = [];
|
|
97
|
+
for (var circleid in circles) {
|
|
98
|
+
circleids.push(circleid);
|
|
99
|
+
ret[circleid] = [];
|
|
100
|
+
}
|
|
101
|
+
for (var i = 0; i < circleids.length; i++) {
|
|
102
|
+
var a = circles[circleids[i]];
|
|
103
|
+
for (var j = i + 1; j < circleids.length; ++j) {
|
|
104
|
+
var b = circles[circleids[j]], d = distance(a, b);
|
|
105
|
+
if (d + b.radius <= a.radius + 1e-10) {
|
|
106
|
+
ret[circleids[j]].push(circleids[i]);
|
|
107
|
+
}
|
|
108
|
+
else if (d + a.radius <= b.radius + 1e-10) {
|
|
109
|
+
ret[circleids[i]].push(circleids[j]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return ret;
|
|
114
|
+
}
|
|
115
|
+
export function computeTextCentres(circles, areas) {
|
|
116
|
+
var ret = {}, overlapped = getOverlappingCircles(circles);
|
|
117
|
+
for (var i = 0; i < areas.length; ++i) {
|
|
118
|
+
var area = areas[i].sets, areaids = {}, exclude = {};
|
|
119
|
+
for (var j = 0; j < area.length; ++j) {
|
|
120
|
+
areaids[area[j]] = true;
|
|
121
|
+
var overlaps = overlapped[area[j]];
|
|
122
|
+
// keep track of any circles that overlap this area,
|
|
123
|
+
// and don't consider for purposes of computing the text
|
|
124
|
+
// centre
|
|
125
|
+
for (var k = 0; k < overlaps.length; ++k) {
|
|
126
|
+
exclude[overlaps[k]] = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var interior = [], exterior = [];
|
|
130
|
+
for (var setid in circles) {
|
|
131
|
+
if (setid in areaids) {
|
|
132
|
+
interior.push(circles[setid]);
|
|
133
|
+
}
|
|
134
|
+
else if (!(setid in exclude)) {
|
|
135
|
+
exterior.push(circles[setid]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
var centre = computeTextCentre(interior, exterior);
|
|
139
|
+
ret[area] = centre;
|
|
140
|
+
if (centre.disjoint && areas[i].size > 0) {
|
|
141
|
+
console.log('WARNING: area ' + area + ' not represented on screen');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return ret;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 根据圆心(x, y) 半径 r 返回圆的绘制 path
|
|
148
|
+
* @param x 圆心点 x
|
|
149
|
+
* @param y 圆心点 y
|
|
150
|
+
* @param r 圆的半径
|
|
151
|
+
* @returns 圆的 path
|
|
152
|
+
*/
|
|
153
|
+
export function circlePath(x, y, r) {
|
|
154
|
+
var ret = [];
|
|
155
|
+
// ret.push('\nM', x, y);
|
|
156
|
+
// ret.push('\nm', -r, 0);
|
|
157
|
+
// ret.push('\na', r, r, 0, 1, 0, r * 2, 0);
|
|
158
|
+
// ret.push('\na', r, r, 0, 1, 0, -r * 2, 0);
|
|
159
|
+
var x0 = x - r;
|
|
160
|
+
var y0 = y;
|
|
161
|
+
ret.push('M', x0, y0);
|
|
162
|
+
ret.push('A', r, r, 0, 1, 0, x0 + 2 * r, y0);
|
|
163
|
+
ret.push('A', r, r, 0, 1, 0, x0, y0);
|
|
164
|
+
return ret.join(' ');
|
|
165
|
+
}
|
|
166
|
+
// inverse of the circlePath function, returns a circle object from an svg path
|
|
167
|
+
export function circleFromPath(path) {
|
|
168
|
+
var tokens = path.split(' ');
|
|
169
|
+
return { x: parseFloat(tokens[1]), y: parseFloat(tokens[2]), radius: -parseFloat(tokens[4]) };
|
|
170
|
+
}
|
|
171
|
+
/** returns a svg path of the intersection area of a bunch of circles */
|
|
172
|
+
export function intersectionAreaPath(circles) {
|
|
173
|
+
var stats = {};
|
|
174
|
+
intersectionArea(circles, stats);
|
|
175
|
+
var arcs = stats.arcs;
|
|
176
|
+
if (arcs.length === 0) {
|
|
177
|
+
return 'M 0 0';
|
|
178
|
+
}
|
|
179
|
+
else if (arcs.length == 1) {
|
|
180
|
+
var circle = arcs[0].circle;
|
|
181
|
+
return circlePath(circle.x, circle.y, circle.radius);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// draw path around arcs
|
|
185
|
+
var ret = ['\nM', arcs[0].p2.x, arcs[0].p2.y];
|
|
186
|
+
for (var i = 0; i < arcs.length; ++i) {
|
|
187
|
+
var arc = arcs[i], r = arc.circle.radius, wide = arc.width > r;
|
|
188
|
+
ret.push('\nA', r, r, 0, wide ? 1 : 0, 1, arc.p1.x, arc.p1.y);
|
|
189
|
+
}
|
|
190
|
+
return ret.join(' ');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=diagram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagram.js","sourceRoot":"","sources":["../../../../src/plots/venn/layout/diagram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE7E,SAAS,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAC/C,IAAI,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAC9D,CAAC,EACD,CAAC,CAAC;IACJ,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACpC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,MAAM,EAAE;YACf,MAAM,GAAG,CAAC,CAAC;SACZ;KACF;IAED,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,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AAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC/D;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACtB;AACH,CAAC","sourcesContent":["import { nelderMead } from 'fmin';\nimport { intersectionArea, distance, getCenter } from './circleintersection';\n\nfunction circleMargin(current, interior, exterior) {\n let margin = interior[0].radius - distance(interior[0], current),\n i,\n m;\n for (i = 1; i < interior.length; ++i) {\n m = interior[i].radius - distance(interior[i], current);\n if (m <= margin) {\n margin = m;\n }\n }\n\n for (i = 0; i < exterior.length; ++i) {\n m = distance(exterior[i], current) - exterior[i].radius;\n if (m <= margin) {\n margin = m;\n }\n }\n return margin;\n}\n\n// compute the center of some circles by maximizing the margin of\n// the center point relative to the circles (interior) after subtracting\n// nearby circles (exterior)\nexport function computeTextCentre(interior, exterior) {\n // get an initial estimate by sampling around the interior circles\n // and taking the point with the biggest margin\n const points = [];\n let i;\n for (i = 0; i < interior.length; ++i) {\n const c = interior[i];\n points.push({ x: c.x, y: c.y });\n points.push({ x: c.x + c.radius / 2, y: c.y });\n points.push({ x: c.x - c.radius / 2, y: c.y });\n points.push({ x: c.x, y: c.y + c.radius / 2 });\n points.push({ x: c.x, y: c.y - c.radius / 2 });\n }\n let initial = points[0],\n margin = circleMargin(points[0], interior, exterior);\n for (i = 1; i < points.length; ++i) {\n const m = circleMargin(points[i], interior, exterior);\n if (m >= margin) {\n initial = points[i];\n margin = m;\n }\n }\n\n // maximize the margin numerically\n const solution = nelderMead(\n function (p) {\n return -1 * circleMargin({ x: p[0], y: p[1] }, interior, exterior);\n },\n [initial.x, initial.y],\n { maxIterations: 500, minErrorDelta: 1e-10 }\n ).x;\n let ret: any = { x: solution[0], y: solution[1] };\n\n // check solution, fallback as needed (happens if fully overlapped\n // etc)\n let valid = true;\n for (i = 0; i < interior.length; ++i) {\n if (distance(ret, interior[i]) > interior[i].radius) {\n valid = false;\n break;\n }\n }\n\n for (i = 0; i < exterior.length; ++i) {\n if (distance(ret, exterior[i]) < exterior[i].radius) {\n valid = false;\n break;\n }\n }\n\n if (!valid) {\n if (interior.length == 1) {\n ret = { x: interior[0].x, y: interior[0].y };\n } else {\n const areaStats: any = {};\n intersectionArea(interior, areaStats);\n\n if (areaStats.arcs.length === 0) {\n ret = { x: 0, y: -1000, disjoint: true };\n } else if (areaStats.arcs.length == 1) {\n ret = { x: areaStats.arcs[0].circle.x, y: areaStats.arcs[0].circle.y };\n } else if (exterior.length) {\n // try again without other circles\n ret = computeTextCentre(interior, []);\n } else {\n // take average of all the points in the intersection\n // polygon. this should basically never happen\n // and has some issues:\n // https://github.com/benfred/venn.js/issues/48#issuecomment-146069777\n ret = getCenter(\n areaStats.arcs.map(function (a) {\n return a.p1;\n })\n );\n }\n }\n }\n\n return ret;\n}\n\n// given a dictionary of {setid : circle}, returns\n// a dictionary of setid to list of circles that completely overlap it\nfunction getOverlappingCircles(circles) {\n const ret = {},\n circleids = [];\n for (const circleid in circles) {\n circleids.push(circleid);\n ret[circleid] = [];\n }\n for (let i = 0; i < circleids.length; i++) {\n const a = circles[circleids[i]];\n for (let j = i + 1; j < circleids.length; ++j) {\n const b = circles[circleids[j]],\n d = distance(a, b);\n\n if (d + b.radius <= a.radius + 1e-10) {\n ret[circleids[j]].push(circleids[i]);\n } else if (d + a.radius <= b.radius + 1e-10) {\n ret[circleids[i]].push(circleids[j]);\n }\n }\n }\n return ret;\n}\n\nexport function computeTextCentres(circles, areas) {\n const ret = {},\n overlapped = getOverlappingCircles(circles);\n for (let i = 0; i < areas.length; ++i) {\n const area = areas[i].sets,\n areaids = {},\n exclude = {};\n for (let j = 0; j < area.length; ++j) {\n areaids[area[j]] = true;\n const overlaps = overlapped[area[j]];\n // keep track of any circles that overlap this area,\n // and don't consider for purposes of computing the text\n // centre\n for (let k = 0; k < overlaps.length; ++k) {\n exclude[overlaps[k]] = true;\n }\n }\n\n const interior = [],\n exterior = [];\n for (const setid in circles) {\n if (setid in areaids) {\n interior.push(circles[setid]);\n } else if (!(setid in exclude)) {\n exterior.push(circles[setid]);\n }\n }\n const centre = computeTextCentre(interior, exterior);\n ret[area] = centre;\n if (centre.disjoint && areas[i].size > 0) {\n console.log('WARNING: area ' + area + ' not represented on screen');\n }\n }\n return ret;\n}\n\n/**\n * 根据圆心(x, y) 半径 r 返回圆的绘制 path\n * @param x 圆心点 x\n * @param y 圆心点 y\n * @param r 圆的半径\n * @returns 圆的 path\n */\nexport function circlePath(x, y, r) {\n const ret = [];\n // ret.push('\\nM', x, y);\n // ret.push('\\nm', -r, 0);\n // ret.push('\\na', r, r, 0, 1, 0, r * 2, 0);\n // ret.push('\\na', r, r, 0, 1, 0, -r * 2, 0);\n const x0 = x - r;\n const y0 = y;\n ret.push('M', x0, y0);\n ret.push('A', r, r, 0, 1, 0, x0 + 2 * r, y0);\n ret.push('A', r, r, 0, 1, 0, x0, y0);\n\n return ret.join(' ');\n}\n\n// inverse of the circlePath function, returns a circle object from an svg path\nexport function circleFromPath(path) {\n const tokens = path.split(' ');\n return { x: parseFloat(tokens[1]), y: parseFloat(tokens[2]), radius: -parseFloat(tokens[4]) };\n}\n\n/** returns a svg path of the intersection area of a bunch of circles */\nexport function intersectionAreaPath(circles) {\n const stats: any = {};\n intersectionArea(circles, stats);\n const arcs = stats.arcs;\n\n if (arcs.length === 0) {\n return 'M 0 0';\n } else if (arcs.length == 1) {\n const circle = arcs[0].circle;\n return circlePath(circle.x, circle.y, circle.radius);\n } else {\n // draw path around arcs\n const ret = ['\\nM', arcs[0].p2.x, arcs[0].p2.y];\n for (let i = 0; i < arcs.length; ++i) {\n const arc = arcs[i],\n r = arc.circle.radius,\n wide = arc.width > r;\n ret.push('\\nA', r, r, 0, wide ? 1 : 0, 1, arc.p1.x, arc.p1.y);\n }\n return ret.join(' ');\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** given a list of set objects, and their corresponding overlaps.
|
|
2
|
+
updates the (x, y, radius) attribute on each set such that their positions
|
|
3
|
+
roughly correspond to the desired overlaps */
|
|
4
|
+
export declare function venn(areas: any, parameters?: any): any;
|
|
5
|
+
/** Returns the distance necessary for two circles of radius r1 + r2 to
|
|
6
|
+
have the overlap area 'overlap' */
|
|
7
|
+
export declare function distanceFromIntersectArea(r1: any, r2: any, overlap: any): any;
|
|
8
|
+
export declare function getDistanceMatrices(areas: any, sets: any, setids: any): {
|
|
9
|
+
distances: any;
|
|
10
|
+
constraints: any;
|
|
11
|
+
};
|
|
12
|
+
export declare function bestInitialLayout(areas: any, params: any): {};
|
|
13
|
+
export declare function constrainedMDSLayout(areas: any, params: any): {};
|
|
14
|
+
/** Lays out a Venn diagram greedily, going from most overlapped sets to
|
|
15
|
+
least overlapped, attempting to position each new set such that the
|
|
16
|
+
overlapping areas to already positioned sets are basically right */
|
|
17
|
+
export declare function greedyLayout(areas: any, params: any): {};
|
|
18
|
+
/** Given a bunch of sets, and the desired overlaps between these sets - computes
|
|
19
|
+
the distance from the actual overlaps to the desired overlaps. Note that
|
|
20
|
+
this method ignores overlaps of more than 2 circles */
|
|
21
|
+
export declare function lossFunction(sets: any, overlaps: any): number;
|
|
22
|
+
export declare function disjointCluster(circles: any): any[];
|
|
23
|
+
export declare function normalizeSolution(solution: any, orientation: any, orientationOrder: any): {};
|
|
24
|
+
/** Scales a solution from venn.venn or venn.greedyLayout such that it fits in
|
|
25
|
+
a rectangle of width/height - with padding around the borders. also
|
|
26
|
+
centers the diagram in the available space at the same time */
|
|
27
|
+
export declare function scaleSolution(solution: any, width: any, height: any, padding: any): any;
|