@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.
Files changed (298) hide show
  1. package/CHANGELOG.md +1270 -0
  2. package/{README.zh-CN.md → README.en-US.md} +33 -42
  3. package/README.md +43 -32
  4. package/dist/g2plot.min.js +3 -18
  5. package/dist/g2plot.min.js.map +1 -1
  6. package/esm/adaptor/common.d.ts +1 -0
  7. package/esm/adaptor/common.js +1 -0
  8. package/esm/adaptor/common.js.map +1 -1
  9. package/esm/adaptor/pattern.d.ts +10 -0
  10. package/esm/adaptor/pattern.js +54 -0
  11. package/esm/adaptor/pattern.js.map +1 -0
  12. package/esm/core/plot.d.ts +11 -1
  13. package/esm/core/plot.js +42 -1
  14. package/esm/core/plot.js.map +1 -1
  15. package/esm/index.d.ts +5 -1
  16. package/esm/index.js +5 -1
  17. package/esm/index.js.map +1 -1
  18. package/esm/plots/area/adaptor.js +2 -2
  19. package/esm/plots/area/adaptor.js.map +1 -1
  20. package/esm/plots/circle-packing/adaptor.js +4 -4
  21. package/esm/plots/circle-packing/adaptor.js.map +1 -1
  22. package/esm/plots/circle-packing/utils.d.ts +0 -5
  23. package/esm/plots/circle-packing/utils.js +1 -20
  24. package/esm/plots/circle-packing/utils.js.map +1 -1
  25. package/esm/plots/column/adaptor.js +3 -2
  26. package/esm/plots/column/adaptor.js.map +1 -1
  27. package/esm/plots/dual-axes/adaptor.js +6 -4
  28. package/esm/plots/dual-axes/adaptor.js.map +1 -1
  29. package/esm/plots/dual-axes/types.d.ts +2 -1
  30. package/esm/plots/dual-axes/types.js.map +1 -1
  31. package/esm/plots/dual-axes/util/geometry.js +3 -2
  32. package/esm/plots/dual-axes/util/geometry.js.map +1 -1
  33. package/esm/plots/dual-axes/util/legend.js +4 -1
  34. package/esm/plots/dual-axes/util/legend.js.map +1 -1
  35. package/esm/plots/funnel/geometries/basic.js +2 -7
  36. package/esm/plots/funnel/geometries/basic.js.map +1 -1
  37. package/esm/plots/heatmap/adaptor.js +2 -2
  38. package/esm/plots/heatmap/adaptor.js.map +1 -1
  39. package/esm/plots/heatmap/types.d.ts +4 -2
  40. package/esm/plots/heatmap/types.js.map +1 -1
  41. package/esm/plots/histogram/adaptor.js +2 -1
  42. package/esm/plots/histogram/adaptor.js.map +1 -1
  43. package/esm/plots/liquid/adaptor.js +2 -2
  44. package/esm/plots/liquid/adaptor.js.map +1 -1
  45. package/esm/plots/pie/adaptor.js +2 -1
  46. package/esm/plots/pie/adaptor.js.map +1 -1
  47. package/esm/plots/radial-bar/adaptor.js +2 -1
  48. package/esm/plots/radial-bar/adaptor.js.map +1 -1
  49. package/esm/plots/rose/adaptor.js +2 -2
  50. package/esm/plots/rose/adaptor.js.map +1 -1
  51. package/esm/plots/sunburst/adaptor.js +2 -2
  52. package/esm/plots/sunburst/adaptor.js.map +1 -1
  53. package/esm/plots/tiny-area/adaptor.js +2 -2
  54. package/esm/plots/tiny-area/adaptor.js.map +1 -1
  55. package/esm/plots/tiny-column/adaptor.js +2 -2
  56. package/esm/plots/tiny-column/adaptor.js.map +1 -1
  57. package/esm/plots/treemap/adaptor.js +2 -1
  58. package/esm/plots/treemap/adaptor.js.map +1 -1
  59. package/esm/plots/venn/adaptor.d.ts +23 -0
  60. package/esm/plots/venn/adaptor.js +177 -0
  61. package/esm/plots/venn/adaptor.js.map +1 -0
  62. package/esm/plots/venn/constant.d.ts +7 -0
  63. package/esm/plots/venn/constant.js +33 -0
  64. package/esm/plots/venn/constant.js.map +1 -0
  65. package/esm/plots/venn/index.d.ts +24 -0
  66. package/esm/plots/venn/index.js +47 -0
  67. package/esm/plots/venn/index.js.map +1 -0
  68. package/esm/plots/venn/interaction/action.d.ts +18 -0
  69. package/esm/plots/venn/interaction/action.js +77 -0
  70. package/esm/plots/venn/interaction/action.js.map +1 -0
  71. package/esm/plots/venn/interaction/index.d.ts +1 -0
  72. package/esm/plots/venn/interaction/index.js +15 -0
  73. package/esm/plots/venn/interaction/index.js.map +1 -0
  74. package/esm/plots/venn/label.d.ts +1 -0
  75. package/esm/plots/venn/label.js +31 -0
  76. package/esm/plots/venn/label.js.map +1 -0
  77. package/esm/plots/venn/layout/circleintersection.d.ts +29 -0
  78. package/esm/plots/venn/layout/circleintersection.js +186 -0
  79. package/esm/plots/venn/layout/circleintersection.js.map +1 -0
  80. package/esm/plots/venn/layout/diagram.d.ts +17 -0
  81. package/esm/plots/venn/layout/diagram.js +193 -0
  82. package/esm/plots/venn/layout/diagram.js.map +1 -0
  83. package/esm/plots/venn/layout/layout.d.ts +27 -0
  84. package/esm/plots/venn/layout/layout.js +593 -0
  85. package/esm/plots/venn/layout/layout.js.map +1 -0
  86. package/esm/plots/venn/shape.d.ts +1 -0
  87. package/esm/plots/venn/shape.js +42 -0
  88. package/esm/plots/venn/shape.js.map +1 -0
  89. package/esm/plots/venn/types.d.ts +27 -0
  90. package/esm/plots/venn/types.js +2 -0
  91. package/esm/plots/venn/types.js.map +1 -0
  92. package/esm/plots/venn/utils.d.ts +28 -0
  93. package/esm/plots/venn/utils.js +93 -0
  94. package/esm/plots/venn/utils.js.map +1 -0
  95. package/esm/types/annotation.d.ts +5 -1
  96. package/esm/types/annotation.js.map +1 -1
  97. package/esm/types/attr.d.ts +4 -1
  98. package/esm/types/attr.js.map +1 -1
  99. package/esm/types/common.d.ts +3 -1
  100. package/esm/types/common.js.map +1 -1
  101. package/esm/types/index.d.ts +1 -0
  102. package/esm/types/index.js +1 -0
  103. package/esm/types/index.js.map +1 -1
  104. package/esm/types/pattern.d.ts +47 -0
  105. package/esm/types/pattern.js +1 -0
  106. package/esm/types/pattern.js.map +1 -0
  107. package/esm/utils/color/blend.d.ts +20 -0
  108. package/esm/utils/color/blend.js +92 -0
  109. package/esm/utils/color/blend.js.map +1 -0
  110. package/esm/utils/padding.d.ts +5 -0
  111. package/esm/utils/padding.js +19 -0
  112. package/esm/utils/padding.js.map +1 -1
  113. package/esm/utils/pattern/dot.d.ts +32 -0
  114. package/esm/utils/pattern/dot.js +69 -0
  115. package/esm/utils/pattern/dot.js.map +1 -0
  116. package/esm/utils/pattern/index.d.ts +17 -0
  117. package/esm/utils/pattern/index.js +27 -0
  118. package/esm/utils/pattern/index.js.map +1 -0
  119. package/esm/utils/pattern/line.d.ts +25 -0
  120. package/esm/utils/pattern/line.js +56 -0
  121. package/esm/utils/pattern/line.js.map +1 -0
  122. package/esm/utils/pattern/square.d.ts +28 -0
  123. package/esm/utils/pattern/square.js +61 -0
  124. package/esm/utils/pattern/square.js.map +1 -0
  125. package/esm/utils/pattern/util.d.ts +50 -0
  126. package/esm/utils/pattern/util.js +90 -0
  127. package/esm/utils/pattern/util.js.map +1 -0
  128. package/lib/adaptor/common.d.ts +1 -0
  129. package/lib/adaptor/common.js +2 -0
  130. package/lib/adaptor/common.js.map +1 -1
  131. package/lib/adaptor/pattern.d.ts +10 -0
  132. package/lib/adaptor/pattern.js +58 -0
  133. package/lib/adaptor/pattern.js.map +1 -0
  134. package/lib/core/plot.d.ts +11 -1
  135. package/lib/core/plot.js +41 -0
  136. package/lib/core/plot.js.map +1 -1
  137. package/lib/index.d.ts +5 -1
  138. package/lib/index.js +7 -1
  139. package/lib/index.js.map +1 -1
  140. package/lib/plots/area/adaptor.js +1 -1
  141. package/lib/plots/area/adaptor.js.map +1 -1
  142. package/lib/plots/circle-packing/adaptor.js +2 -2
  143. package/lib/plots/circle-packing/adaptor.js.map +1 -1
  144. package/lib/plots/circle-packing/utils.d.ts +0 -5
  145. package/lib/plots/circle-packing/utils.js +2 -22
  146. package/lib/plots/circle-packing/utils.js.map +1 -1
  147. package/lib/plots/column/adaptor.js +3 -2
  148. package/lib/plots/column/adaptor.js.map +1 -1
  149. package/lib/plots/dual-axes/adaptor.js +6 -4
  150. package/lib/plots/dual-axes/adaptor.js.map +1 -1
  151. package/lib/plots/dual-axes/types.d.ts +2 -1
  152. package/lib/plots/dual-axes/types.js.map +1 -1
  153. package/lib/plots/dual-axes/util/geometry.js +2 -1
  154. package/lib/plots/dual-axes/util/geometry.js.map +1 -1
  155. package/lib/plots/dual-axes/util/legend.js +4 -1
  156. package/lib/plots/dual-axes/util/legend.js.map +1 -1
  157. package/lib/plots/funnel/geometries/basic.js +1 -6
  158. package/lib/plots/funnel/geometries/basic.js.map +1 -1
  159. package/lib/plots/heatmap/adaptor.js +1 -1
  160. package/lib/plots/heatmap/adaptor.js.map +1 -1
  161. package/lib/plots/heatmap/types.d.ts +4 -2
  162. package/lib/plots/heatmap/types.js.map +1 -1
  163. package/lib/plots/histogram/adaptor.js +2 -1
  164. package/lib/plots/histogram/adaptor.js.map +1 -1
  165. package/lib/plots/liquid/adaptor.js +1 -1
  166. package/lib/plots/liquid/adaptor.js.map +1 -1
  167. package/lib/plots/pie/adaptor.js +2 -1
  168. package/lib/plots/pie/adaptor.js.map +1 -1
  169. package/lib/plots/radial-bar/adaptor.js +2 -1
  170. package/lib/plots/radial-bar/adaptor.js.map +1 -1
  171. package/lib/plots/rose/adaptor.js +1 -1
  172. package/lib/plots/rose/adaptor.js.map +1 -1
  173. package/lib/plots/sunburst/adaptor.js +1 -1
  174. package/lib/plots/sunburst/adaptor.js.map +1 -1
  175. package/lib/plots/tiny-area/adaptor.js +1 -1
  176. package/lib/plots/tiny-area/adaptor.js.map +1 -1
  177. package/lib/plots/tiny-column/adaptor.js +1 -1
  178. package/lib/plots/tiny-column/adaptor.js.map +1 -1
  179. package/lib/plots/treemap/adaptor.js +2 -1
  180. package/lib/plots/treemap/adaptor.js.map +1 -1
  181. package/lib/plots/venn/adaptor.d.ts +23 -0
  182. package/lib/plots/venn/adaptor.js +183 -0
  183. package/lib/plots/venn/adaptor.js.map +1 -0
  184. package/lib/plots/venn/constant.d.ts +7 -0
  185. package/lib/plots/venn/constant.js +36 -0
  186. package/lib/plots/venn/constant.js.map +1 -0
  187. package/lib/plots/venn/index.d.ts +24 -0
  188. package/lib/plots/venn/index.js +50 -0
  189. package/lib/plots/venn/index.js.map +1 -0
  190. package/lib/plots/venn/interaction/action.d.ts +18 -0
  191. package/lib/plots/venn/interaction/action.js +80 -0
  192. package/lib/plots/venn/interaction/action.js.map +1 -0
  193. package/lib/plots/venn/interaction/index.d.ts +1 -0
  194. package/lib/plots/venn/interaction/index.js +17 -0
  195. package/lib/plots/venn/interaction/index.js.map +1 -0
  196. package/lib/plots/venn/label.d.ts +1 -0
  197. package/lib/plots/venn/label.js +33 -0
  198. package/lib/plots/venn/label.js.map +1 -0
  199. package/lib/plots/venn/layout/circleintersection.d.ts +29 -0
  200. package/lib/plots/venn/layout/circleintersection.js +196 -0
  201. package/lib/plots/venn/layout/circleintersection.js.map +1 -0
  202. package/lib/plots/venn/layout/diagram.d.ts +17 -0
  203. package/lib/plots/venn/layout/diagram.js +201 -0
  204. package/lib/plots/venn/layout/diagram.js.map +1 -0
  205. package/lib/plots/venn/layout/layout.d.ts +27 -0
  206. package/lib/plots/venn/layout/layout.js +606 -0
  207. package/lib/plots/venn/layout/layout.js.map +1 -0
  208. package/lib/plots/venn/shape.d.ts +1 -0
  209. package/lib/plots/venn/shape.js +44 -0
  210. package/lib/plots/venn/shape.js.map +1 -0
  211. package/lib/plots/venn/types.d.ts +27 -0
  212. package/lib/plots/venn/types.js +4 -0
  213. package/lib/plots/venn/types.js.map +1 -0
  214. package/lib/plots/venn/utils.d.ts +28 -0
  215. package/lib/plots/venn/utils.js +98 -0
  216. package/lib/plots/venn/utils.js.map +1 -0
  217. package/lib/types/annotation.d.ts +5 -1
  218. package/lib/types/annotation.js.map +1 -1
  219. package/lib/types/attr.d.ts +4 -1
  220. package/lib/types/attr.js.map +1 -1
  221. package/lib/types/common.d.ts +3 -1
  222. package/lib/types/common.js.map +1 -1
  223. package/lib/types/index.d.ts +1 -0
  224. package/lib/types/index.js +1 -0
  225. package/lib/types/index.js.map +1 -1
  226. package/lib/types/pattern.d.ts +47 -0
  227. package/lib/types/pattern.js +3 -0
  228. package/lib/types/pattern.js.map +1 -0
  229. package/lib/utils/color/blend.d.ts +20 -0
  230. package/lib/utils/color/blend.js +98 -0
  231. package/lib/utils/color/blend.js.map +1 -0
  232. package/lib/utils/padding.d.ts +5 -0
  233. package/lib/utils/padding.js +21 -1
  234. package/lib/utils/padding.js.map +1 -1
  235. package/lib/utils/pattern/dot.d.ts +32 -0
  236. package/lib/utils/pattern/dot.js +74 -0
  237. package/lib/utils/pattern/dot.js.map +1 -0
  238. package/lib/utils/pattern/index.d.ts +17 -0
  239. package/lib/utils/pattern/index.js +31 -0
  240. package/lib/utils/pattern/index.js.map +1 -0
  241. package/lib/utils/pattern/line.d.ts +25 -0
  242. package/lib/utils/pattern/line.js +61 -0
  243. package/lib/utils/pattern/line.js.map +1 -0
  244. package/lib/utils/pattern/square.d.ts +28 -0
  245. package/lib/utils/pattern/square.js +66 -0
  246. package/lib/utils/pattern/square.js.map +1 -0
  247. package/lib/utils/pattern/util.d.ts +50 -0
  248. package/lib/utils/pattern/util.js +99 -0
  249. package/lib/utils/pattern/util.js.map +1 -0
  250. package/package.json +10 -8
  251. package/src/adaptor/common.ts +2 -0
  252. package/src/adaptor/pattern.ts +66 -0
  253. package/src/core/plot.ts +43 -1
  254. package/src/index.ts +8 -1
  255. package/src/plots/area/adaptor.ts +3 -2
  256. package/src/plots/circle-packing/adaptor.ts +12 -3
  257. package/src/plots/circle-packing/utils.ts +1 -21
  258. package/src/plots/column/adaptor.ts +3 -1
  259. package/src/plots/dual-axes/adaptor.ts +6 -4
  260. package/src/plots/dual-axes/types.ts +11 -1
  261. package/src/plots/dual-axes/util/geometry.ts +3 -2
  262. package/src/plots/dual-axes/util/legend.ts +4 -1
  263. package/src/plots/funnel/geometries/basic.ts +2 -10
  264. package/src/plots/heatmap/adaptor.ts +12 -1
  265. package/src/plots/heatmap/types.ts +6 -2
  266. package/src/plots/histogram/adaptor.ts +13 -1
  267. package/src/plots/liquid/adaptor.ts +2 -2
  268. package/src/plots/pie/adaptor.ts +2 -0
  269. package/src/plots/radial-bar/adaptor.ts +2 -0
  270. package/src/plots/rose/adaptor.ts +2 -1
  271. package/src/plots/sunburst/adaptor.ts +2 -1
  272. package/src/plots/tiny-area/adaptor.ts +2 -2
  273. package/src/plots/tiny-column/adaptor.ts +2 -2
  274. package/src/plots/treemap/adaptor.ts +13 -1
  275. package/src/plots/venn/adaptor.ts +227 -0
  276. package/src/plots/venn/constant.ts +35 -0
  277. package/src/plots/venn/index.ts +47 -0
  278. package/src/plots/venn/interaction/action.ts +67 -0
  279. package/src/plots/venn/interaction/index.ts +17 -0
  280. package/src/plots/venn/label.ts +26 -0
  281. package/src/plots/venn/layout/circleintersection.ts +223 -0
  282. package/src/plots/venn/layout/diagram.ts +219 -0
  283. package/src/plots/venn/layout/layout.ts +734 -0
  284. package/src/plots/venn/shape.ts +53 -0
  285. package/src/plots/venn/types.ts +25 -0
  286. package/src/plots/venn/utils.ts +100 -0
  287. package/src/types/annotation.ts +3 -1
  288. package/src/types/attr.ts +7 -1
  289. package/src/types/common.ts +3 -1
  290. package/src/types/index.ts +1 -0
  291. package/src/types/pattern.ts +50 -0
  292. package/src/utils/color/blend.ts +103 -0
  293. package/src/utils/padding.ts +20 -0
  294. package/src/utils/pattern/dot.ts +86 -0
  295. package/src/utils/pattern/index.ts +45 -0
  296. package/src/utils/pattern/line.ts +70 -0
  297. package/src/utils/pattern/square.ts +78 -0
  298. package/src/utils/pattern/util.ts +104 -0
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCenter = exports.circleCircleIntersection = exports.circleOverlap = exports.distance = exports.circleArea = exports.containedInCircles = exports.intersectionArea = void 0;
4
+ var SMALL = 1e-10;
5
+ /** Returns the intersection area of a bunch of circles (where each circle
6
+ is an object having an x,y and radius property) */
7
+ function intersectionArea(circles, stats) {
8
+ // get all the intersection points of the circles
9
+ var intersectionPoints = getIntersectionPoints(circles);
10
+ // filter out points that aren't included in all the circles
11
+ var innerPoints = intersectionPoints.filter(function (p) {
12
+ return containedInCircles(p, circles);
13
+ });
14
+ var arcArea = 0, polygonArea = 0, i;
15
+ var arcs = [];
16
+ // if we have intersection points that are within all the circles,
17
+ // then figure out the area contained by them
18
+ if (innerPoints.length > 1) {
19
+ // sort the points by angle from the center of the polygon, which lets
20
+ // us just iterate over points to get the edges
21
+ var center = getCenter(innerPoints);
22
+ for (i = 0; i < innerPoints.length; ++i) {
23
+ var p = innerPoints[i];
24
+ p.angle = Math.atan2(p.x - center.x, p.y - center.y);
25
+ }
26
+ innerPoints.sort(function (a, b) {
27
+ return b.angle - a.angle;
28
+ });
29
+ // iterate over all points, get arc between the points
30
+ // and update the areas
31
+ var p2 = innerPoints[innerPoints.length - 1];
32
+ for (i = 0; i < innerPoints.length; ++i) {
33
+ var p1 = innerPoints[i];
34
+ // polygon area updates easily ...
35
+ polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
36
+ // updating the arc area is a little more involved
37
+ var midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
38
+ var arc = null;
39
+ for (var j = 0; j < p1.parentIndex.length; ++j) {
40
+ if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {
41
+ // figure out the angle halfway between the two points
42
+ // on the current circle
43
+ 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);
44
+ var angleDiff = a2 - a1;
45
+ if (angleDiff < 0) {
46
+ angleDiff += 2 * Math.PI;
47
+ }
48
+ // and use that angle to figure out the width of the
49
+ // arc
50
+ var a = a2 - angleDiff / 2;
51
+ var width = distance(midPoint, {
52
+ x: circle.x + circle.radius * Math.sin(a),
53
+ y: circle.y + circle.radius * Math.cos(a),
54
+ });
55
+ // clamp the width to the largest is can actually be
56
+ // (sometimes slightly overflows because of FP errors)
57
+ if (width > circle.radius * 2) {
58
+ width = circle.radius * 2;
59
+ }
60
+ // pick the circle whose arc has the smallest width
61
+ if (arc === null || arc.width > width) {
62
+ arc = { circle: circle, width: width, p1: p1, p2: p2 };
63
+ }
64
+ }
65
+ }
66
+ if (arc !== null) {
67
+ arcs.push(arc);
68
+ arcArea += circleArea(arc.circle.radius, arc.width);
69
+ p2 = p1;
70
+ }
71
+ }
72
+ }
73
+ else {
74
+ // no intersection points, is either disjoint - or is completely
75
+ // overlapped. figure out which by examining the smallest circle
76
+ var smallest = circles[0];
77
+ for (i = 1; i < circles.length; ++i) {
78
+ if (circles[i].radius < smallest.radius) {
79
+ smallest = circles[i];
80
+ }
81
+ }
82
+ // make sure the smallest circle is completely contained in all
83
+ // the other circles
84
+ var disjoint = false;
85
+ for (i = 0; i < circles.length; ++i) {
86
+ if (distance(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
87
+ disjoint = true;
88
+ break;
89
+ }
90
+ }
91
+ if (disjoint) {
92
+ arcArea = polygonArea = 0;
93
+ }
94
+ else {
95
+ arcArea = smallest.radius * smallest.radius * Math.PI;
96
+ arcs.push({
97
+ circle: smallest,
98
+ p1: { x: smallest.x, y: smallest.y + smallest.radius },
99
+ p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },
100
+ width: smallest.radius * 2,
101
+ });
102
+ }
103
+ }
104
+ polygonArea /= 2;
105
+ if (stats) {
106
+ stats.area = arcArea + polygonArea;
107
+ stats.arcArea = arcArea;
108
+ stats.polygonArea = polygonArea;
109
+ stats.arcs = arcs;
110
+ stats.innerPoints = innerPoints;
111
+ stats.intersectionPoints = intersectionPoints;
112
+ }
113
+ return arcArea + polygonArea;
114
+ }
115
+ exports.intersectionArea = intersectionArea;
116
+ /** returns whether a point is contained by all of a list of circles */
117
+ function containedInCircles(point, circles) {
118
+ for (var i = 0; i < circles.length; ++i) {
119
+ if (distance(point, circles[i]) > circles[i].radius + SMALL) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ exports.containedInCircles = containedInCircles;
126
+ /** Gets all intersection points between a bunch of circles */
127
+ function getIntersectionPoints(circles) {
128
+ var ret = [];
129
+ for (var i = 0; i < circles.length; ++i) {
130
+ for (var j = i + 1; j < circles.length; ++j) {
131
+ var intersect = circleCircleIntersection(circles[i], circles[j]);
132
+ for (var k = 0; k < intersect.length; ++k) {
133
+ var p = intersect[k];
134
+ p.parentIndex = [i, j];
135
+ ret.push(p);
136
+ }
137
+ }
138
+ }
139
+ return ret;
140
+ }
141
+ /** Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html */
142
+ function circleArea(r, width) {
143
+ return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
144
+ }
145
+ exports.circleArea = circleArea;
146
+ /** euclidean distance between two points */
147
+ function distance(p1, p2) {
148
+ return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
149
+ }
150
+ exports.distance = distance;
151
+ /** Returns the overlap area of two circles of radius r1 and r2 - that
152
+ have their centers separated by distance d. Simpler faster
153
+ circle intersection for only two circles */
154
+ function circleOverlap(r1, r2, d) {
155
+ // no overlap
156
+ if (d >= r1 + r2) {
157
+ return 0;
158
+ }
159
+ // completely overlapped
160
+ if (d <= Math.abs(r1 - r2)) {
161
+ return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
162
+ }
163
+ var w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d), w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
164
+ return circleArea(r1, w1) + circleArea(r2, w2);
165
+ }
166
+ exports.circleOverlap = circleOverlap;
167
+ /** Given two circles (containing a x/y/radius attributes),
168
+ returns the intersecting points if possible.
169
+ note: doesn't handle cases where there are infinitely many
170
+ intersection points (circles are equivalent):, or only one intersection point*/
171
+ function circleCircleIntersection(p1, p2) {
172
+ var d = distance(p1, p2), r1 = p1.radius, r2 = p2.radius;
173
+ // if to far away, or self contained - can't be done
174
+ if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
175
+ return [];
176
+ }
177
+ 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);
178
+ return [
179
+ { x: x0 + rx, y: y0 - ry },
180
+ { x: x0 - rx, y: y0 + ry },
181
+ ];
182
+ }
183
+ exports.circleCircleIntersection = circleCircleIntersection;
184
+ /** Returns the center of a bunch of points */
185
+ function getCenter(points) {
186
+ var center = { x: 0, y: 0 };
187
+ for (var i = 0; i < points.length; ++i) {
188
+ center.x += points[i].x;
189
+ center.y += points[i].y;
190
+ }
191
+ center.x /= points.length;
192
+ center.y /= points.length;
193
+ return center;
194
+ }
195
+ exports.getCenter = getCenter;
196
+ //# 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,SAAgB,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,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,GAAG,CAAC,EACb,WAAW,GAAG,CAAC,EACf,CAAC,CAAC;IACJ,IAAM,IAAI,GAAG,EAAE,CAAC;IAChB,kEAAkE;IAClE,6CAA6C;IAC7C,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,sEAAsE;QACtE,+CAA+C;QAC/C,IAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;QACtC,KAAK,CAAC,GAAG,CAA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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;AATD,8BASC","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,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.intersectionAreaPath = exports.circleFromPath = exports.circlePath = exports.computeTextCentres = exports.computeTextCentre = void 0;
4
+ var fmin_1 = require("fmin");
5
+ var circleintersection_1 = require("./circleintersection");
6
+ function circleMargin(current, interior, exterior) {
7
+ var margin = interior[0].radius - circleintersection_1.distance(interior[0], current), i, m;
8
+ for (i = 1; i < interior.length; ++i) {
9
+ m = interior[i].radius - circleintersection_1.distance(interior[i], current);
10
+ if (m <= margin) {
11
+ margin = m;
12
+ }
13
+ }
14
+ for (i = 0; i < exterior.length; ++i) {
15
+ m = circleintersection_1.distance(exterior[i], current) - exterior[i].radius;
16
+ if (m <= margin) {
17
+ margin = m;
18
+ }
19
+ }
20
+ return margin;
21
+ }
22
+ // compute the center of some circles by maximizing the margin of
23
+ // the center point relative to the circles (interior) after subtracting
24
+ // nearby circles (exterior)
25
+ function computeTextCentre(interior, exterior) {
26
+ // get an initial estimate by sampling around the interior circles
27
+ // and taking the point with the biggest margin
28
+ var points = [];
29
+ var i;
30
+ for (i = 0; i < interior.length; ++i) {
31
+ var c = interior[i];
32
+ points.push({ x: c.x, y: c.y });
33
+ points.push({ x: c.x + c.radius / 2, y: c.y });
34
+ points.push({ x: c.x - c.radius / 2, y: c.y });
35
+ points.push({ x: c.x, y: c.y + c.radius / 2 });
36
+ points.push({ x: c.x, y: c.y - c.radius / 2 });
37
+ }
38
+ var initial = points[0], margin = circleMargin(points[0], interior, exterior);
39
+ for (i = 1; i < points.length; ++i) {
40
+ var m = circleMargin(points[i], interior, exterior);
41
+ if (m >= margin) {
42
+ initial = points[i];
43
+ margin = m;
44
+ }
45
+ }
46
+ // maximize the margin numerically
47
+ var solution = fmin_1.nelderMead(function (p) {
48
+ return -1 * circleMargin({ x: p[0], y: p[1] }, interior, exterior);
49
+ }, [initial.x, initial.y], { maxIterations: 500, minErrorDelta: 1e-10 }).x;
50
+ var ret = { x: solution[0], y: solution[1] };
51
+ // check solution, fallback as needed (happens if fully overlapped
52
+ // etc)
53
+ var valid = true;
54
+ for (i = 0; i < interior.length; ++i) {
55
+ if (circleintersection_1.distance(ret, interior[i]) > interior[i].radius) {
56
+ valid = false;
57
+ break;
58
+ }
59
+ }
60
+ for (i = 0; i < exterior.length; ++i) {
61
+ if (circleintersection_1.distance(ret, exterior[i]) < exterior[i].radius) {
62
+ valid = false;
63
+ break;
64
+ }
65
+ }
66
+ if (!valid) {
67
+ if (interior.length == 1) {
68
+ ret = { x: interior[0].x, y: interior[0].y };
69
+ }
70
+ else {
71
+ var areaStats = {};
72
+ circleintersection_1.intersectionArea(interior, areaStats);
73
+ if (areaStats.arcs.length === 0) {
74
+ ret = { x: 0, y: -1000, disjoint: true };
75
+ }
76
+ else if (areaStats.arcs.length == 1) {
77
+ ret = { x: areaStats.arcs[0].circle.x, y: areaStats.arcs[0].circle.y };
78
+ }
79
+ else if (exterior.length) {
80
+ // try again without other circles
81
+ ret = computeTextCentre(interior, []);
82
+ }
83
+ else {
84
+ // take average of all the points in the intersection
85
+ // polygon. this should basically never happen
86
+ // and has some issues:
87
+ // https://github.com/benfred/venn.js/issues/48#issuecomment-146069777
88
+ ret = circleintersection_1.getCenter(areaStats.arcs.map(function (a) {
89
+ return a.p1;
90
+ }));
91
+ }
92
+ }
93
+ }
94
+ return ret;
95
+ }
96
+ exports.computeTextCentre = computeTextCentre;
97
+ // given a dictionary of {setid : circle}, returns
98
+ // a dictionary of setid to list of circles that completely overlap it
99
+ function getOverlappingCircles(circles) {
100
+ var ret = {}, circleids = [];
101
+ for (var circleid in circles) {
102
+ circleids.push(circleid);
103
+ ret[circleid] = [];
104
+ }
105
+ for (var i = 0; i < circleids.length; i++) {
106
+ var a = circles[circleids[i]];
107
+ for (var j = i + 1; j < circleids.length; ++j) {
108
+ var b = circles[circleids[j]], d = circleintersection_1.distance(a, b);
109
+ if (d + b.radius <= a.radius + 1e-10) {
110
+ ret[circleids[j]].push(circleids[i]);
111
+ }
112
+ else if (d + a.radius <= b.radius + 1e-10) {
113
+ ret[circleids[i]].push(circleids[j]);
114
+ }
115
+ }
116
+ }
117
+ return ret;
118
+ }
119
+ function computeTextCentres(circles, areas) {
120
+ var ret = {}, overlapped = getOverlappingCircles(circles);
121
+ for (var i = 0; i < areas.length; ++i) {
122
+ var area = areas[i].sets, areaids = {}, exclude = {};
123
+ for (var j = 0; j < area.length; ++j) {
124
+ areaids[area[j]] = true;
125
+ var overlaps = overlapped[area[j]];
126
+ // keep track of any circles that overlap this area,
127
+ // and don't consider for purposes of computing the text
128
+ // centre
129
+ for (var k = 0; k < overlaps.length; ++k) {
130
+ exclude[overlaps[k]] = true;
131
+ }
132
+ }
133
+ var interior = [], exterior = [];
134
+ for (var setid in circles) {
135
+ if (setid in areaids) {
136
+ interior.push(circles[setid]);
137
+ }
138
+ else if (!(setid in exclude)) {
139
+ exterior.push(circles[setid]);
140
+ }
141
+ }
142
+ var centre = computeTextCentre(interior, exterior);
143
+ ret[area] = centre;
144
+ if (centre.disjoint && areas[i].size > 0) {
145
+ console.log('WARNING: area ' + area + ' not represented on screen');
146
+ }
147
+ }
148
+ return ret;
149
+ }
150
+ exports.computeTextCentres = computeTextCentres;
151
+ /**
152
+ * 根据圆心(x, y) 半径 r 返回圆的绘制 path
153
+ * @param x 圆心点 x
154
+ * @param y 圆心点 y
155
+ * @param r 圆的半径
156
+ * @returns 圆的 path
157
+ */
158
+ function circlePath(x, y, r) {
159
+ var ret = [];
160
+ // ret.push('\nM', x, y);
161
+ // ret.push('\nm', -r, 0);
162
+ // ret.push('\na', r, r, 0, 1, 0, r * 2, 0);
163
+ // ret.push('\na', r, r, 0, 1, 0, -r * 2, 0);
164
+ var x0 = x - r;
165
+ var y0 = y;
166
+ ret.push('M', x0, y0);
167
+ ret.push('A', r, r, 0, 1, 0, x0 + 2 * r, y0);
168
+ ret.push('A', r, r, 0, 1, 0, x0, y0);
169
+ return ret.join(' ');
170
+ }
171
+ exports.circlePath = circlePath;
172
+ // inverse of the circlePath function, returns a circle object from an svg path
173
+ function circleFromPath(path) {
174
+ var tokens = path.split(' ');
175
+ return { x: parseFloat(tokens[1]), y: parseFloat(tokens[2]), radius: -parseFloat(tokens[4]) };
176
+ }
177
+ exports.circleFromPath = circleFromPath;
178
+ /** returns a svg path of the intersection area of a bunch of circles */
179
+ function intersectionAreaPath(circles) {
180
+ var stats = {};
181
+ circleintersection_1.intersectionArea(circles, stats);
182
+ var arcs = stats.arcs;
183
+ if (arcs.length === 0) {
184
+ return 'M 0 0';
185
+ }
186
+ else if (arcs.length == 1) {
187
+ var circle = arcs[0].circle;
188
+ return circlePath(circle.x, circle.y, circle.radius);
189
+ }
190
+ else {
191
+ // draw path around arcs
192
+ var ret = ['\nM', arcs[0].p2.x, arcs[0].p2.y];
193
+ for (var i = 0; i < arcs.length; ++i) {
194
+ var arc = arcs[i], r = arc.circle.radius, wide = arc.width > r;
195
+ ret.push('\nA', r, r, 0, wide ? 1 : 0, 1, arc.p1.x, arc.p1.y);
196
+ }
197
+ return ret.join(' ');
198
+ }
199
+ }
200
+ exports.intersectionAreaPath = intersectionAreaPath;
201
+ //# sourceMappingURL=diagram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagram.js","sourceRoot":"","sources":["../../../../src/plots/venn/layout/diagram.ts"],"names":[],"mappings":";;;AAAA,6BAAkC;AAClC,2DAA6E;AAE7E,SAAS,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAC/C,IAAI,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,6BAAQ,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,6BAAQ,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,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACpC,CAAC,GAAG,6BAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACxD,IAAI,CAAC,IAAI,MAAM,EAAE;YACf,MAAM,GAAG,CAAC,CAAC;SACZ;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iEAAiE;AACjE,wEAAwE;AACxE,4BAA4B;AAC5B,SAAgB,iBAAiB,CA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\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;