@zettelgeist/cli 0.1.0
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/LICENSE +202 -0
- package/README.md +64 -0
- package/dist/bin.js +2211 -0
- package/dist/bin.js.map +7 -0
- package/dist/templates/export.html +27 -0
- package/dist/templates/skill/SKILL.md +220 -0
- package/dist/viewer-bundle/architecture-YZFGNWBL-W2K3EQOM.js +14 -0
- package/dist/viewer-bundle/architecture-YZFGNWBL-W2K3EQOM.js.map +7 -0
- package/dist/viewer-bundle/architectureDiagram-Q4EWVU46-LCGRUEWT.js +8884 -0
- package/dist/viewer-bundle/architectureDiagram-Q4EWVU46-LCGRUEWT.js.map +7 -0
- package/dist/viewer-bundle/base.css +248 -0
- package/dist/viewer-bundle/blockDiagram-DXYQGD6D-KAM7BOAP.js +3777 -0
- package/dist/viewer-bundle/blockDiagram-DXYQGD6D-KAM7BOAP.js.map +7 -0
- package/dist/viewer-bundle/board.css +370 -0
- package/dist/viewer-bundle/c4Diagram-AHTNJAMY-C3FIQYXA.js +2596 -0
- package/dist/viewer-bundle/c4Diagram-AHTNJAMY-C3FIQYXA.js.map +7 -0
- package/dist/viewer-bundle/chunk-2QXGXAO5.js +68 -0
- package/dist/viewer-bundle/chunk-2QXGXAO5.js.map +7 -0
- package/dist/viewer-bundle/chunk-5PZT7VUU.js +67 -0
- package/dist/viewer-bundle/chunk-5PZT7VUU.js.map +7 -0
- package/dist/viewer-bundle/chunk-5YJCJF2C.js +112 -0
- package/dist/viewer-bundle/chunk-5YJCJF2C.js.map +7 -0
- package/dist/viewer-bundle/chunk-6LYV7PBV.js +1011 -0
- package/dist/viewer-bundle/chunk-6LYV7PBV.js.map +7 -0
- package/dist/viewer-bundle/chunk-6VW7D5WX.js +48 -0
- package/dist/viewer-bundle/chunk-6VW7D5WX.js.map +7 -0
- package/dist/viewer-bundle/chunk-76C5OSD4.js +2048 -0
- package/dist/viewer-bundle/chunk-76C5OSD4.js.map +7 -0
- package/dist/viewer-bundle/chunk-7NZMPQDX.js +6957 -0
- package/dist/viewer-bundle/chunk-7NZMPQDX.js.map +7 -0
- package/dist/viewer-bundle/chunk-A634GTZN.js +122 -0
- package/dist/viewer-bundle/chunk-A634GTZN.js.map +7 -0
- package/dist/viewer-bundle/chunk-AJQJUKMU.js +133 -0
- package/dist/viewer-bundle/chunk-AJQJUKMU.js.map +7 -0
- package/dist/viewer-bundle/chunk-BM2KPNFW.js +5556 -0
- package/dist/viewer-bundle/chunk-BM2KPNFW.js.map +7 -0
- package/dist/viewer-bundle/chunk-CIDUOCCG.js +25 -0
- package/dist/viewer-bundle/chunk-CIDUOCCG.js.map +7 -0
- package/dist/viewer-bundle/chunk-CZHJHAOR.js +6397 -0
- package/dist/viewer-bundle/chunk-CZHJHAOR.js.map +7 -0
- package/dist/viewer-bundle/chunk-D5RLIWY4.js +125 -0
- package/dist/viewer-bundle/chunk-D5RLIWY4.js.map +7 -0
- package/dist/viewer-bundle/chunk-DI52DQAC.js +44 -0
- package/dist/viewer-bundle/chunk-DI52DQAC.js.map +7 -0
- package/dist/viewer-bundle/chunk-EXJQLTIV.js +51 -0
- package/dist/viewer-bundle/chunk-EXJQLTIV.js.map +7 -0
- package/dist/viewer-bundle/chunk-G3PPZWPW.js +96 -0
- package/dist/viewer-bundle/chunk-G3PPZWPW.js.map +7 -0
- package/dist/viewer-bundle/chunk-GTW4IDD4.js +30297 -0
- package/dist/viewer-bundle/chunk-GTW4IDD4.js.map +7 -0
- package/dist/viewer-bundle/chunk-GVE7OA3Z.js +59 -0
- package/dist/viewer-bundle/chunk-GVE7OA3Z.js.map +7 -0
- package/dist/viewer-bundle/chunk-JBUVKVPY.js +2042 -0
- package/dist/viewer-bundle/chunk-JBUVKVPY.js.map +7 -0
- package/dist/viewer-bundle/chunk-JQLVOAQB.js +20 -0
- package/dist/viewer-bundle/chunk-JQLVOAQB.js.map +7 -0
- package/dist/viewer-bundle/chunk-LQMQSYLO.js +101 -0
- package/dist/viewer-bundle/chunk-LQMQSYLO.js.map +7 -0
- package/dist/viewer-bundle/chunk-MBFAQ3IK.js +34 -0
- package/dist/viewer-bundle/chunk-MBFAQ3IK.js.map +7 -0
- package/dist/viewer-bundle/chunk-N7G7IIKG.js +25 -0
- package/dist/viewer-bundle/chunk-N7G7IIKG.js.map +7 -0
- package/dist/viewer-bundle/chunk-NW4YG3NS.js +171 -0
- package/dist/viewer-bundle/chunk-NW4YG3NS.js.map +7 -0
- package/dist/viewer-bundle/chunk-ODEP5TKB.js +61 -0
- package/dist/viewer-bundle/chunk-ODEP5TKB.js.map +7 -0
- package/dist/viewer-bundle/chunk-OGKINV23.js +1050 -0
- package/dist/viewer-bundle/chunk-OGKINV23.js.map +7 -0
- package/dist/viewer-bundle/chunk-OGMSNDVH.js +1994 -0
- package/dist/viewer-bundle/chunk-OGMSNDVH.js.map +7 -0
- package/dist/viewer-bundle/chunk-QJVSDNAW.js +25 -0
- package/dist/viewer-bundle/chunk-QJVSDNAW.js.map +7 -0
- package/dist/viewer-bundle/chunk-RBTT26R4.js +2721 -0
- package/dist/viewer-bundle/chunk-RBTT26R4.js.map +7 -0
- package/dist/viewer-bundle/chunk-RQIPIIE2.js +48 -0
- package/dist/viewer-bundle/chunk-RQIPIIE2.js.map +7 -0
- package/dist/viewer-bundle/chunk-SRTYTXTX.js +22 -0
- package/dist/viewer-bundle/chunk-SRTYTXTX.js.map +7 -0
- package/dist/viewer-bundle/chunk-TRL7YIZG.js +1663 -0
- package/dist/viewer-bundle/chunk-TRL7YIZG.js.map +7 -0
- package/dist/viewer-bundle/chunk-U5T7X4BV.js +172 -0
- package/dist/viewer-bundle/chunk-U5T7X4BV.js.map +7 -0
- package/dist/viewer-bundle/chunk-UCAW6C6C.js +48 -0
- package/dist/viewer-bundle/chunk-UCAW6C6C.js.map +7 -0
- package/dist/viewer-bundle/chunk-UEAG4BJQ.js +93 -0
- package/dist/viewer-bundle/chunk-UEAG4BJQ.js.map +7 -0
- package/dist/viewer-bundle/chunk-UVRE3R6A.js +1039 -0
- package/dist/viewer-bundle/chunk-UVRE3R6A.js.map +7 -0
- package/dist/viewer-bundle/chunk-VODO7SV4.js +25029 -0
- package/dist/viewer-bundle/chunk-VODO7SV4.js.map +7 -0
- package/dist/viewer-bundle/chunk-YEU62MVS.js +682 -0
- package/dist/viewer-bundle/chunk-YEU62MVS.js.map +7 -0
- package/dist/viewer-bundle/chunk-YFQT7PPW.js +987 -0
- package/dist/viewer-bundle/chunk-YFQT7PPW.js.map +7 -0
- package/dist/viewer-bundle/chunk-Z4G7FG27.js +48 -0
- package/dist/viewer-bundle/chunk-Z4G7FG27.js.map +7 -0
- package/dist/viewer-bundle/chunk-ZW4Y7DIF.js +2044 -0
- package/dist/viewer-bundle/chunk-ZW4Y7DIF.js.map +7 -0
- package/dist/viewer-bundle/classDiagram-6PBFFD2Q-7VKYXLUX.js +46 -0
- package/dist/viewer-bundle/classDiagram-6PBFFD2Q-7VKYXLUX.js.map +7 -0
- package/dist/viewer-bundle/classDiagram-v2-HSJHXN6E-ACCNN7EN.js +46 -0
- package/dist/viewer-bundle/classDiagram-v2-HSJHXN6E-ACCNN7EN.js.map +7 -0
- package/dist/viewer-bundle/cose-bilkent-S5V4N54A-MUJHAA34.js +5009 -0
- package/dist/viewer-bundle/cose-bilkent-S5V4N54A-MUJHAA34.js.map +7 -0
- package/dist/viewer-bundle/dagre-KV5264BT-YC5VV3WF.js +739 -0
- package/dist/viewer-bundle/dagre-KV5264BT-YC5VV3WF.js.map +7 -0
- package/dist/viewer-bundle/dark.css +13 -0
- package/dist/viewer-bundle/detail.css +539 -0
- package/dist/viewer-bundle/diagram-5BDNPKRD-RXFPVFYK.js +214 -0
- package/dist/viewer-bundle/diagram-5BDNPKRD-RXFPVFYK.js.map +7 -0
- package/dist/viewer-bundle/diagram-G4DWMVQ6-KN7CBNBQ.js +578 -0
- package/dist/viewer-bundle/diagram-G4DWMVQ6-KN7CBNBQ.js.map +7 -0
- package/dist/viewer-bundle/diagram-MMDJMWI5-ZN6TQ7ZC.js +345 -0
- package/dist/viewer-bundle/diagram-MMDJMWI5-ZN6TQ7ZC.js.map +7 -0
- package/dist/viewer-bundle/diagram-TYMM5635-MMTUJ4KA.js +255 -0
- package/dist/viewer-bundle/diagram-TYMM5635-MMTUJ4KA.js.map +7 -0
- package/dist/viewer-bundle/docs.css +88 -0
- package/dist/viewer-bundle/edit-modal-BEGC2AO6.js +176 -0
- package/dist/viewer-bundle/edit-modal-BEGC2AO6.js.map +7 -0
- package/dist/viewer-bundle/erDiagram-SMLLAGMA-TBHMLD2E.js +1349 -0
- package/dist/viewer-bundle/erDiagram-SMLLAGMA-TBHMLD2E.js.map +7 -0
- package/dist/viewer-bundle/flowDiagram-DWJPFMVM-BZHLK6QB.js +2501 -0
- package/dist/viewer-bundle/flowDiagram-DWJPFMVM-BZHLK6QB.js.map +7 -0
- package/dist/viewer-bundle/ganttDiagram-T4ZO3ILL-YBARPTQR.js +2654 -0
- package/dist/viewer-bundle/ganttDiagram-T4ZO3ILL-YBARPTQR.js.map +7 -0
- package/dist/viewer-bundle/gitGraph-7Q5UKJZL-HENKIQDX.js +14 -0
- package/dist/viewer-bundle/gitGraph-7Q5UKJZL-HENKIQDX.js.map +7 -0
- package/dist/viewer-bundle/gitGraphDiagram-UUTBAWPF-M4VV3YVA.js +1946 -0
- package/dist/viewer-bundle/gitGraphDiagram-UUTBAWPF-M4VV3YVA.js.map +7 -0
- package/dist/viewer-bundle/index.html +28 -0
- package/dist/viewer-bundle/info-OMHHGYJF-E773USRS.js +14 -0
- package/dist/viewer-bundle/info-OMHHGYJF-E773USRS.js.map +7 -0
- package/dist/viewer-bundle/infoDiagram-42DDH7IO-C7JGUXKK.js +59 -0
- package/dist/viewer-bundle/infoDiagram-42DDH7IO-C7JGUXKK.js.map +7 -0
- package/dist/viewer-bundle/ishikawaDiagram-UXIWVN3A-YBC4X4VB.js +1012 -0
- package/dist/viewer-bundle/ishikawaDiagram-UXIWVN3A-YBC4X4VB.js.map +7 -0
- package/dist/viewer-bundle/journeyDiagram-VCZTEJTY-6WKVEOOO.js +1303 -0
- package/dist/viewer-bundle/journeyDiagram-VCZTEJTY-6WKVEOOO.js.map +7 -0
- package/dist/viewer-bundle/kanban-definition-6JOO6SKY-URTTHHO4.js +1131 -0
- package/dist/viewer-bundle/kanban-definition-6JOO6SKY-URTTHHO4.js.map +7 -0
- package/dist/viewer-bundle/katex-QN5266ZE.js +14318 -0
- package/dist/viewer-bundle/katex-QN5266ZE.js.map +7 -0
- package/dist/viewer-bundle/light.css +15 -0
- package/dist/viewer-bundle/main.js +4816 -0
- package/dist/viewer-bundle/main.js.map +7 -0
- package/dist/viewer-bundle/mermaid.core-AEBXU2JK.js +1708 -0
- package/dist/viewer-bundle/mermaid.core-AEBXU2JK.js.map +7 -0
- package/dist/viewer-bundle/mindmap-definition-QFDTVHPH-KUMAMRSF.js +1277 -0
- package/dist/viewer-bundle/mindmap-definition-QFDTVHPH-KUMAMRSF.js.map +7 -0
- package/dist/viewer-bundle/packet-4T2RLAQJ-IRYWWA66.js +14 -0
- package/dist/viewer-bundle/packet-4T2RLAQJ-IRYWWA66.js.map +7 -0
- package/dist/viewer-bundle/pico.classless.min.css +4 -0
- package/dist/viewer-bundle/pie-ZZUOXDRM-JYO4VL5N.js +14 -0
- package/dist/viewer-bundle/pie-ZZUOXDRM-JYO4VL5N.js.map +7 -0
- package/dist/viewer-bundle/pieDiagram-DEJITSTG-QOEHQN3N.js +238 -0
- package/dist/viewer-bundle/pieDiagram-DEJITSTG-QOEHQN3N.js.map +7 -0
- package/dist/viewer-bundle/prompt-modal-C4LHI7BS.js +12 -0
- package/dist/viewer-bundle/prompt-modal-C4LHI7BS.js.map +7 -0
- package/dist/viewer-bundle/quadrantDiagram-34T5L4WZ-SJNPUU5N.js +1409 -0
- package/dist/viewer-bundle/quadrantDiagram-34T5L4WZ-SJNPUU5N.js.map +7 -0
- package/dist/viewer-bundle/radar-PYXPWWZC-45BRYQSB.js +14 -0
- package/dist/viewer-bundle/radar-PYXPWWZC-45BRYQSB.js.map +7 -0
- package/dist/viewer-bundle/reason-modal-MK34MQ73.js +68 -0
- package/dist/viewer-bundle/reason-modal-MK34MQ73.js.map +7 -0
- package/dist/viewer-bundle/requirementDiagram-MS252O5E-UOMT3FCC.js +1311 -0
- package/dist/viewer-bundle/requirementDiagram-MS252O5E-UOMT3FCC.js.map +7 -0
- package/dist/viewer-bundle/sankeyDiagram-XADWPNL6-LAVJ5C6A.js +1263 -0
- package/dist/viewer-bundle/sankeyDiagram-XADWPNL6-LAVJ5C6A.js.map +7 -0
- package/dist/viewer-bundle/sequenceDiagram-FGHM5R23-3IWTOUNQ.js +4655 -0
- package/dist/viewer-bundle/sequenceDiagram-FGHM5R23-3IWTOUNQ.js.map +7 -0
- package/dist/viewer-bundle/stateDiagram-FHFEXIEX-S2OVQQON.js +495 -0
- package/dist/viewer-bundle/stateDiagram-FHFEXIEX-S2OVQQON.js.map +7 -0
- package/dist/viewer-bundle/stateDiagram-v2-QKLJ7IA2-XNZ3XXSV.js +44 -0
- package/dist/viewer-bundle/stateDiagram-v2-QKLJ7IA2-XNZ3XXSV.js.map +7 -0
- package/dist/viewer-bundle/timeline-definition-GMOUNBTQ-FHVZ7MHE.js +1646 -0
- package/dist/viewer-bundle/timeline-definition-GMOUNBTQ-FHVZ7MHE.js.map +7 -0
- package/dist/viewer-bundle/treeView-SZITEDCU-RXZXNYAM.js +14 -0
- package/dist/viewer-bundle/treeView-SZITEDCU-RXZXNYAM.js.map +7 -0
- package/dist/viewer-bundle/treemap-W4RFUUIX-2IGOFSJM.js +14 -0
- package/dist/viewer-bundle/treemap-W4RFUUIX-2IGOFSJM.js.map +7 -0
- package/dist/viewer-bundle/vennDiagram-DHZGUBPP-HEAOEXEZ.js +2544 -0
- package/dist/viewer-bundle/vennDiagram-DHZGUBPP-HEAOEXEZ.js.map +7 -0
- package/dist/viewer-bundle/wardley-RL74JXVD-VSPCLOX2.js +14 -0
- package/dist/viewer-bundle/wardley-RL74JXVD-VSPCLOX2.js.map +7 -0
- package/dist/viewer-bundle/wardleyDiagram-NUSXRM2D-EBY4FG3X.js +938 -0
- package/dist/viewer-bundle/wardleyDiagram-NUSXRM2D-EBY4FG3X.js.map +7 -0
- package/dist/viewer-bundle/xychartDiagram-5P7HB3ND-SSMUQEXK.js +1952 -0
- package/dist/viewer-bundle/xychartDiagram-5P7HB3ND-SSMUQEXK.js.map +7 -0
- package/package.json +51 -0
|
@@ -0,0 +1,2544 @@
|
|
|
1
|
+
import {
|
|
2
|
+
selectSvgElement
|
|
3
|
+
} from "./chunk-N7G7IIKG.js";
|
|
4
|
+
import {
|
|
5
|
+
at
|
|
6
|
+
} from "./chunk-6LYV7PBV.js";
|
|
7
|
+
import {
|
|
8
|
+
cleanAndMerge
|
|
9
|
+
} from "./chunk-UVRE3R6A.js";
|
|
10
|
+
import "./chunk-G3PPZWPW.js";
|
|
11
|
+
import {
|
|
12
|
+
clear,
|
|
13
|
+
configureSvgSize,
|
|
14
|
+
darken_default,
|
|
15
|
+
defaultConfig_default,
|
|
16
|
+
getAccDescription,
|
|
17
|
+
getAccTitle,
|
|
18
|
+
getConfig,
|
|
19
|
+
getDiagramTitle,
|
|
20
|
+
is_dark_default,
|
|
21
|
+
lighten_default,
|
|
22
|
+
setAccDescription,
|
|
23
|
+
setAccTitle,
|
|
24
|
+
setDiagramTitle,
|
|
25
|
+
transparentize_default
|
|
26
|
+
} from "./chunk-7NZMPQDX.js";
|
|
27
|
+
import "./chunk-YEU62MVS.js";
|
|
28
|
+
import {
|
|
29
|
+
__name,
|
|
30
|
+
select_default
|
|
31
|
+
} from "./chunk-CZHJHAOR.js";
|
|
32
|
+
import "./chunk-DI52DQAC.js";
|
|
33
|
+
|
|
34
|
+
// ../../node_modules/.pnpm/@upsetjs+venn.js@2.0.0/node_modules/@upsetjs/venn.js/build/venn.esm.js
|
|
35
|
+
var SMALL$1 = 1e-10;
|
|
36
|
+
function intersectionArea(circles, stats) {
|
|
37
|
+
const intersectionPoints = getIntersectionPoints(circles);
|
|
38
|
+
const innerPoints = intersectionPoints.filter((p) => containedInCircles(p, circles));
|
|
39
|
+
let arcArea = 0;
|
|
40
|
+
let polygonArea = 0;
|
|
41
|
+
const arcs = [];
|
|
42
|
+
if (innerPoints.length > 1) {
|
|
43
|
+
const center = getCenter(innerPoints);
|
|
44
|
+
for (let i = 0; i < innerPoints.length; ++i) {
|
|
45
|
+
const p = innerPoints[i];
|
|
46
|
+
p.angle = Math.atan2(p.x - center.x, p.y - center.y);
|
|
47
|
+
}
|
|
48
|
+
innerPoints.sort((a, b) => b.angle - a.angle);
|
|
49
|
+
let p2 = innerPoints[innerPoints.length - 1];
|
|
50
|
+
for (let i = 0; i < innerPoints.length; ++i) {
|
|
51
|
+
const p1 = innerPoints[i];
|
|
52
|
+
polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
|
|
53
|
+
const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
54
|
+
let arc = null;
|
|
55
|
+
for (let j = 0; j < p1.parentIndex.length; ++j) {
|
|
56
|
+
if (p2.parentIndex.includes(p1.parentIndex[j])) {
|
|
57
|
+
const circle = circles[p1.parentIndex[j]];
|
|
58
|
+
const a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y);
|
|
59
|
+
const a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
|
|
60
|
+
let angleDiff = a2 - a1;
|
|
61
|
+
if (angleDiff < 0) {
|
|
62
|
+
angleDiff += 2 * Math.PI;
|
|
63
|
+
}
|
|
64
|
+
const a = a2 - angleDiff / 2;
|
|
65
|
+
let width = distance(midPoint, {
|
|
66
|
+
x: circle.x + circle.radius * Math.sin(a),
|
|
67
|
+
y: circle.y + circle.radius * Math.cos(a)
|
|
68
|
+
});
|
|
69
|
+
if (width > circle.radius * 2) {
|
|
70
|
+
width = circle.radius * 2;
|
|
71
|
+
}
|
|
72
|
+
if (arc == null || arc.width > width) {
|
|
73
|
+
arc = { circle, width, p1, p2, large: width > circle.radius, sweep: true };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (arc != null) {
|
|
78
|
+
arcs.push(arc);
|
|
79
|
+
arcArea += circleArea(arc.circle.radius, arc.width);
|
|
80
|
+
p2 = p1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
let smallest = circles[0];
|
|
85
|
+
for (let i = 1; i < circles.length; ++i) {
|
|
86
|
+
if (circles[i].radius < smallest.radius) {
|
|
87
|
+
smallest = circles[i];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let disjoint = false;
|
|
91
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
92
|
+
if (distance(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
|
|
93
|
+
disjoint = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (disjoint) {
|
|
98
|
+
arcArea = polygonArea = 0;
|
|
99
|
+
} else {
|
|
100
|
+
arcArea = smallest.radius * smallest.radius * Math.PI;
|
|
101
|
+
arcs.push({
|
|
102
|
+
circle: smallest,
|
|
103
|
+
p1: { x: smallest.x, y: smallest.y + smallest.radius },
|
|
104
|
+
p2: { x: smallest.x - SMALL$1, y: smallest.y + smallest.radius },
|
|
105
|
+
width: smallest.radius * 2,
|
|
106
|
+
large: true,
|
|
107
|
+
sweep: true
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
polygonArea /= 2;
|
|
112
|
+
if (stats) {
|
|
113
|
+
stats.area = arcArea + polygonArea;
|
|
114
|
+
stats.arcArea = arcArea;
|
|
115
|
+
stats.polygonArea = polygonArea;
|
|
116
|
+
stats.arcs = arcs;
|
|
117
|
+
stats.innerPoints = innerPoints;
|
|
118
|
+
stats.intersectionPoints = intersectionPoints;
|
|
119
|
+
}
|
|
120
|
+
return arcArea + polygonArea;
|
|
121
|
+
}
|
|
122
|
+
function containedInCircles(point, circles) {
|
|
123
|
+
return circles.every((circle) => distance(point, circle) < circle.radius + SMALL$1);
|
|
124
|
+
}
|
|
125
|
+
function getIntersectionPoints(circles) {
|
|
126
|
+
const ret = [];
|
|
127
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
128
|
+
for (let j = i + 1; j < circles.length; ++j) {
|
|
129
|
+
const intersect = circleCircleIntersection(circles[i], circles[j]);
|
|
130
|
+
for (const p of intersect) {
|
|
131
|
+
p.parentIndex = [i, j];
|
|
132
|
+
ret.push(p);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return ret;
|
|
137
|
+
}
|
|
138
|
+
function circleArea(r, width) {
|
|
139
|
+
return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
|
|
140
|
+
}
|
|
141
|
+
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
|
+
function circleOverlap(r1, r2, d) {
|
|
145
|
+
if (d >= r1 + r2) {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
if (d <= Math.abs(r1 - r2)) {
|
|
149
|
+
return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
|
|
150
|
+
}
|
|
151
|
+
const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d);
|
|
152
|
+
const w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
|
|
153
|
+
return circleArea(r1, w1) + circleArea(r2, w2);
|
|
154
|
+
}
|
|
155
|
+
function circleCircleIntersection(p1, p2) {
|
|
156
|
+
const d = distance(p1, p2);
|
|
157
|
+
const r1 = p1.radius;
|
|
158
|
+
const r2 = p2.radius;
|
|
159
|
+
if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
|
|
163
|
+
const h = Math.sqrt(r1 * r1 - a * a);
|
|
164
|
+
const x0 = p1.x + a * (p2.x - p1.x) / d;
|
|
165
|
+
const y0 = p1.y + a * (p2.y - p1.y) / d;
|
|
166
|
+
const rx = -(p2.y - p1.y) * (h / d);
|
|
167
|
+
const ry = -(p2.x - p1.x) * (h / d);
|
|
168
|
+
return [
|
|
169
|
+
{ x: x0 + rx, y: y0 - ry },
|
|
170
|
+
{ x: x0 - rx, y: y0 + ry }
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
function getCenter(points) {
|
|
174
|
+
const center = { x: 0, y: 0 };
|
|
175
|
+
for (const point of points) {
|
|
176
|
+
center.x += point.x;
|
|
177
|
+
center.y += point.y;
|
|
178
|
+
}
|
|
179
|
+
center.x /= points.length;
|
|
180
|
+
center.y /= points.length;
|
|
181
|
+
return center;
|
|
182
|
+
}
|
|
183
|
+
function bisect(f, a, b, parameters) {
|
|
184
|
+
parameters = parameters || {};
|
|
185
|
+
const maxIterations = parameters.maxIterations || 100;
|
|
186
|
+
const tolerance = parameters.tolerance || 1e-10;
|
|
187
|
+
const fA = f(a);
|
|
188
|
+
const fB = f(b);
|
|
189
|
+
let delta = b - a;
|
|
190
|
+
if (fA * fB > 0) {
|
|
191
|
+
throw "Initial bisect points must have opposite signs";
|
|
192
|
+
}
|
|
193
|
+
if (fA === 0) return a;
|
|
194
|
+
if (fB === 0) return b;
|
|
195
|
+
for (let i = 0; i < maxIterations; ++i) {
|
|
196
|
+
delta /= 2;
|
|
197
|
+
const mid = a + delta;
|
|
198
|
+
const fMid = f(mid);
|
|
199
|
+
if (fMid * fA >= 0) {
|
|
200
|
+
a = mid;
|
|
201
|
+
}
|
|
202
|
+
if (Math.abs(delta) < tolerance || fMid === 0) {
|
|
203
|
+
return mid;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return a + delta;
|
|
207
|
+
}
|
|
208
|
+
function zeros(x) {
|
|
209
|
+
const r = new Array(x);
|
|
210
|
+
for (let i = 0; i < x; ++i) {
|
|
211
|
+
r[i] = 0;
|
|
212
|
+
}
|
|
213
|
+
return r;
|
|
214
|
+
}
|
|
215
|
+
function zerosM(x, y) {
|
|
216
|
+
return zeros(x).map(() => zeros(y));
|
|
217
|
+
}
|
|
218
|
+
function dot(a, b) {
|
|
219
|
+
let ret = 0;
|
|
220
|
+
for (let i = 0; i < a.length; ++i) {
|
|
221
|
+
ret += a[i] * b[i];
|
|
222
|
+
}
|
|
223
|
+
return ret;
|
|
224
|
+
}
|
|
225
|
+
function norm2(a) {
|
|
226
|
+
return Math.sqrt(dot(a, a));
|
|
227
|
+
}
|
|
228
|
+
function scale(ret, value, c) {
|
|
229
|
+
for (let i = 0; i < value.length; ++i) {
|
|
230
|
+
ret[i] = value[i] * c;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function weightedSum(ret, w1, v1, w2, v2) {
|
|
234
|
+
for (let j = 0; j < ret.length; ++j) {
|
|
235
|
+
ret[j] = w1 * v1[j] + w2 * v2[j];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function nelderMead(f, x0, parameters) {
|
|
239
|
+
parameters = parameters || {};
|
|
240
|
+
const maxIterations = parameters.maxIterations || x0.length * 200;
|
|
241
|
+
const nonZeroDelta = parameters.nonZeroDelta || 1.05;
|
|
242
|
+
const zeroDelta = parameters.zeroDelta || 1e-3;
|
|
243
|
+
const minErrorDelta = parameters.minErrorDelta || 1e-6;
|
|
244
|
+
const minTolerance = parameters.minErrorDelta || 1e-5;
|
|
245
|
+
const rho = parameters.rho !== void 0 ? parameters.rho : 1;
|
|
246
|
+
const chi = parameters.chi !== void 0 ? parameters.chi : 2;
|
|
247
|
+
const psi = parameters.psi !== void 0 ? parameters.psi : -0.5;
|
|
248
|
+
const sigma = parameters.sigma !== void 0 ? parameters.sigma : 0.5;
|
|
249
|
+
let maxDiff;
|
|
250
|
+
const N = x0.length;
|
|
251
|
+
const simplex = new Array(N + 1);
|
|
252
|
+
simplex[0] = x0;
|
|
253
|
+
simplex[0].fx = f(x0);
|
|
254
|
+
simplex[0].id = 0;
|
|
255
|
+
for (let i = 0; i < N; ++i) {
|
|
256
|
+
const point = x0.slice();
|
|
257
|
+
point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta;
|
|
258
|
+
simplex[i + 1] = point;
|
|
259
|
+
simplex[i + 1].fx = f(point);
|
|
260
|
+
simplex[i + 1].id = i + 1;
|
|
261
|
+
}
|
|
262
|
+
function updateSimplex(value) {
|
|
263
|
+
for (let i = 0; i < value.length; i++) {
|
|
264
|
+
simplex[N][i] = value[i];
|
|
265
|
+
}
|
|
266
|
+
simplex[N].fx = value.fx;
|
|
267
|
+
}
|
|
268
|
+
const sortOrder = (a, b) => a.fx - b.fx;
|
|
269
|
+
const centroid = x0.slice();
|
|
270
|
+
const reflected = x0.slice();
|
|
271
|
+
const contracted = x0.slice();
|
|
272
|
+
const expanded = x0.slice();
|
|
273
|
+
for (let iteration = 0; iteration < maxIterations; ++iteration) {
|
|
274
|
+
simplex.sort(sortOrder);
|
|
275
|
+
if (parameters.history) {
|
|
276
|
+
const sortedSimplex = simplex.map((x) => {
|
|
277
|
+
const state = x.slice();
|
|
278
|
+
state.fx = x.fx;
|
|
279
|
+
state.id = x.id;
|
|
280
|
+
return state;
|
|
281
|
+
});
|
|
282
|
+
sortedSimplex.sort((a, b) => a.id - b.id);
|
|
283
|
+
parameters.history.push({
|
|
284
|
+
x: simplex[0].slice(),
|
|
285
|
+
fx: simplex[0].fx,
|
|
286
|
+
simplex: sortedSimplex
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
maxDiff = 0;
|
|
290
|
+
for (let i = 0; i < N; ++i) {
|
|
291
|
+
maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));
|
|
292
|
+
}
|
|
293
|
+
if (Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta && maxDiff < minTolerance) {
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
for (let i = 0; i < N; ++i) {
|
|
297
|
+
centroid[i] = 0;
|
|
298
|
+
for (let j = 0; j < N; ++j) {
|
|
299
|
+
centroid[i] += simplex[j][i];
|
|
300
|
+
}
|
|
301
|
+
centroid[i] /= N;
|
|
302
|
+
}
|
|
303
|
+
const worst = simplex[N];
|
|
304
|
+
weightedSum(reflected, 1 + rho, centroid, -rho, worst);
|
|
305
|
+
reflected.fx = f(reflected);
|
|
306
|
+
if (reflected.fx < simplex[0].fx) {
|
|
307
|
+
weightedSum(expanded, 1 + chi, centroid, -chi, worst);
|
|
308
|
+
expanded.fx = f(expanded);
|
|
309
|
+
if (expanded.fx < reflected.fx) {
|
|
310
|
+
updateSimplex(expanded);
|
|
311
|
+
} else {
|
|
312
|
+
updateSimplex(reflected);
|
|
313
|
+
}
|
|
314
|
+
} else if (reflected.fx >= simplex[N - 1].fx) {
|
|
315
|
+
let shouldReduce = false;
|
|
316
|
+
if (reflected.fx > worst.fx) {
|
|
317
|
+
weightedSum(contracted, 1 + psi, centroid, -psi, worst);
|
|
318
|
+
contracted.fx = f(contracted);
|
|
319
|
+
if (contracted.fx < worst.fx) {
|
|
320
|
+
updateSimplex(contracted);
|
|
321
|
+
} else {
|
|
322
|
+
shouldReduce = true;
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
weightedSum(contracted, 1 - psi * rho, centroid, psi * rho, worst);
|
|
326
|
+
contracted.fx = f(contracted);
|
|
327
|
+
if (contracted.fx < reflected.fx) {
|
|
328
|
+
updateSimplex(contracted);
|
|
329
|
+
} else {
|
|
330
|
+
shouldReduce = true;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (shouldReduce) {
|
|
334
|
+
if (sigma >= 1) break;
|
|
335
|
+
for (let i = 1; i < simplex.length; ++i) {
|
|
336
|
+
weightedSum(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]);
|
|
337
|
+
simplex[i].fx = f(simplex[i]);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
updateSimplex(reflected);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
simplex.sort(sortOrder);
|
|
345
|
+
return { fx: simplex[0].fx, x: simplex[0] };
|
|
346
|
+
}
|
|
347
|
+
function wolfeLineSearch(f, pk, current, next, a, c1, c2) {
|
|
348
|
+
const phi0 = current.fx;
|
|
349
|
+
const phiPrime0 = dot(current.fxprime, pk);
|
|
350
|
+
let phi = phi0;
|
|
351
|
+
let phi_old = phi0;
|
|
352
|
+
let phiPrime = phiPrime0;
|
|
353
|
+
let a0 = 0;
|
|
354
|
+
a = a || 1;
|
|
355
|
+
c1 = c1 || 1e-6;
|
|
356
|
+
c2 = c2 || 0.1;
|
|
357
|
+
function zoom(a_lo, a_high, phi_lo) {
|
|
358
|
+
for (let iteration = 0; iteration < 16; ++iteration) {
|
|
359
|
+
a = (a_lo + a_high) / 2;
|
|
360
|
+
weightedSum(next.x, 1, current.x, a, pk);
|
|
361
|
+
phi = next.fx = f(next.x, next.fxprime);
|
|
362
|
+
phiPrime = dot(next.fxprime, pk);
|
|
363
|
+
if (phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) {
|
|
364
|
+
a_high = a;
|
|
365
|
+
} else {
|
|
366
|
+
if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
|
|
367
|
+
return a;
|
|
368
|
+
}
|
|
369
|
+
if (phiPrime * (a_high - a_lo) >= 0) {
|
|
370
|
+
a_high = a_lo;
|
|
371
|
+
}
|
|
372
|
+
a_lo = a;
|
|
373
|
+
phi_lo = phi;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
for (let iteration = 0; iteration < 10; ++iteration) {
|
|
379
|
+
weightedSum(next.x, 1, current.x, a, pk);
|
|
380
|
+
phi = next.fx = f(next.x, next.fxprime);
|
|
381
|
+
phiPrime = dot(next.fxprime, pk);
|
|
382
|
+
if (phi > phi0 + c1 * a * phiPrime0 || iteration && phi >= phi_old) {
|
|
383
|
+
return zoom(a0, a, phi_old);
|
|
384
|
+
}
|
|
385
|
+
if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
|
|
386
|
+
return a;
|
|
387
|
+
}
|
|
388
|
+
if (phiPrime >= 0) {
|
|
389
|
+
return zoom(a, a0, phi);
|
|
390
|
+
}
|
|
391
|
+
phi_old = phi;
|
|
392
|
+
a0 = a;
|
|
393
|
+
a *= 2;
|
|
394
|
+
}
|
|
395
|
+
return a;
|
|
396
|
+
}
|
|
397
|
+
function conjugateGradient(f, initial, params) {
|
|
398
|
+
let current = { x: initial.slice(), fx: 0, fxprime: initial.slice() };
|
|
399
|
+
let next = { x: initial.slice(), fx: 0, fxprime: initial.slice() };
|
|
400
|
+
const yk = initial.slice();
|
|
401
|
+
let pk;
|
|
402
|
+
let temp;
|
|
403
|
+
let a = 1;
|
|
404
|
+
let maxIterations;
|
|
405
|
+
params = params || {};
|
|
406
|
+
maxIterations = params.maxIterations || initial.length * 20;
|
|
407
|
+
current.fx = f(current.x, current.fxprime);
|
|
408
|
+
pk = current.fxprime.slice();
|
|
409
|
+
scale(pk, current.fxprime, -1);
|
|
410
|
+
for (let i = 0; i < maxIterations; ++i) {
|
|
411
|
+
a = wolfeLineSearch(f, pk, current, next, a);
|
|
412
|
+
if (params.history) {
|
|
413
|
+
params.history.push({
|
|
414
|
+
x: current.x.slice(),
|
|
415
|
+
fx: current.fx,
|
|
416
|
+
fxprime: current.fxprime.slice(),
|
|
417
|
+
alpha: a
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (!a) {
|
|
421
|
+
scale(pk, current.fxprime, -1);
|
|
422
|
+
} else {
|
|
423
|
+
weightedSum(yk, 1, next.fxprime, -1, current.fxprime);
|
|
424
|
+
const delta_k = dot(current.fxprime, current.fxprime);
|
|
425
|
+
const beta_k = Math.max(0, dot(yk, next.fxprime) / delta_k);
|
|
426
|
+
weightedSum(pk, beta_k, pk, -1, next.fxprime);
|
|
427
|
+
temp = current;
|
|
428
|
+
current = next;
|
|
429
|
+
next = temp;
|
|
430
|
+
}
|
|
431
|
+
if (norm2(current.fxprime) <= 1e-5) {
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (params.history) {
|
|
436
|
+
params.history.push({
|
|
437
|
+
x: current.x.slice(),
|
|
438
|
+
fx: current.fx,
|
|
439
|
+
fxprime: current.fxprime.slice(),
|
|
440
|
+
alpha: a
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
return current;
|
|
444
|
+
}
|
|
445
|
+
function venn(sets, parameters = {}) {
|
|
446
|
+
parameters.maxIterations = parameters.maxIterations || 500;
|
|
447
|
+
const initialLayout = parameters.initialLayout || bestInitialLayout;
|
|
448
|
+
const loss = parameters.lossFunction || lossFunction;
|
|
449
|
+
const areas = addMissingAreas(sets, parameters);
|
|
450
|
+
const circles = initialLayout(areas, parameters);
|
|
451
|
+
const setids = Object.keys(circles);
|
|
452
|
+
const initial = [];
|
|
453
|
+
for (const setid of setids) {
|
|
454
|
+
initial.push(circles[setid].x);
|
|
455
|
+
initial.push(circles[setid].y);
|
|
456
|
+
}
|
|
457
|
+
const solution = nelderMead(
|
|
458
|
+
(values) => {
|
|
459
|
+
const current = {};
|
|
460
|
+
for (let i = 0; i < setids.length; ++i) {
|
|
461
|
+
const setid = setids[i];
|
|
462
|
+
current[setid] = {
|
|
463
|
+
x: values[2 * i],
|
|
464
|
+
y: values[2 * i + 1],
|
|
465
|
+
radius: circles[setid].radius
|
|
466
|
+
// size : circles[setid].size
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
return loss(current, areas);
|
|
470
|
+
},
|
|
471
|
+
initial,
|
|
472
|
+
parameters
|
|
473
|
+
);
|
|
474
|
+
const positions = solution.x;
|
|
475
|
+
for (let i = 0; i < setids.length; ++i) {
|
|
476
|
+
const setid = setids[i];
|
|
477
|
+
circles[setid].x = positions[2 * i];
|
|
478
|
+
circles[setid].y = positions[2 * i + 1];
|
|
479
|
+
}
|
|
480
|
+
return circles;
|
|
481
|
+
}
|
|
482
|
+
var SMALL = 1e-10;
|
|
483
|
+
function distanceFromIntersectArea(r1, r2, overlap) {
|
|
484
|
+
if (Math.min(r1, r2) * Math.min(r1, r2) * Math.PI <= overlap + SMALL) {
|
|
485
|
+
return Math.abs(r1 - r2);
|
|
486
|
+
}
|
|
487
|
+
return bisect((distance2) => circleOverlap(r1, r2, distance2) - overlap, 0, r1 + r2);
|
|
488
|
+
}
|
|
489
|
+
function addMissingAreas(areas, parameters = {}) {
|
|
490
|
+
const distinct = parameters.distinct;
|
|
491
|
+
const r = areas.map((s) => Object.assign({}, s));
|
|
492
|
+
function toKey(arr) {
|
|
493
|
+
return arr.join(";");
|
|
494
|
+
}
|
|
495
|
+
if (distinct) {
|
|
496
|
+
const count = /* @__PURE__ */ new Map();
|
|
497
|
+
for (const area of r) {
|
|
498
|
+
for (let i = 0; i < area.sets.length; i++) {
|
|
499
|
+
const si = String(area.sets[i]);
|
|
500
|
+
count.set(si, area.size + (count.get(si) || 0));
|
|
501
|
+
for (let j = i + 1; j < area.sets.length; j++) {
|
|
502
|
+
const sj = String(area.sets[j]);
|
|
503
|
+
const k1 = `${si};${sj}`;
|
|
504
|
+
const k2 = `${sj};${si}`;
|
|
505
|
+
count.set(k1, area.size + (count.get(k1) || 0));
|
|
506
|
+
count.set(k2, area.size + (count.get(k2) || 0));
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
for (const area of r) {
|
|
511
|
+
if (area.sets.length < 3) {
|
|
512
|
+
area.size = count.get(toKey(area.sets));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const ids = [];
|
|
517
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
518
|
+
for (const area of r) {
|
|
519
|
+
if (area.sets.length === 1) {
|
|
520
|
+
ids.push(area.sets[0]);
|
|
521
|
+
} else if (area.sets.length === 2) {
|
|
522
|
+
const a = area.sets[0];
|
|
523
|
+
const b = area.sets[1];
|
|
524
|
+
pairs.add(toKey(area.sets));
|
|
525
|
+
pairs.add(toKey([b, a]));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
ids.sort((a, b) => a === b ? 0 : a < b ? -1 : 1);
|
|
529
|
+
for (let i = 0; i < ids.length; ++i) {
|
|
530
|
+
const a = ids[i];
|
|
531
|
+
for (let j = i + 1; j < ids.length; ++j) {
|
|
532
|
+
const b = ids[j];
|
|
533
|
+
if (!pairs.has(toKey([a, b]))) {
|
|
534
|
+
r.push({ sets: [a, b], size: 0 });
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return r;
|
|
539
|
+
}
|
|
540
|
+
function getDistanceMatrices(areas, sets, setids) {
|
|
541
|
+
const distances = zerosM(sets.length, sets.length);
|
|
542
|
+
const constraints = zerosM(sets.length, sets.length);
|
|
543
|
+
areas.filter((x) => x.sets.length === 2).forEach((current) => {
|
|
544
|
+
const left = setids[current.sets[0]];
|
|
545
|
+
const right = setids[current.sets[1]];
|
|
546
|
+
const r1 = Math.sqrt(sets[left].size / Math.PI);
|
|
547
|
+
const r2 = Math.sqrt(sets[right].size / Math.PI);
|
|
548
|
+
const distance2 = distanceFromIntersectArea(r1, r2, current.size);
|
|
549
|
+
distances[left][right] = distances[right][left] = distance2;
|
|
550
|
+
let c = 0;
|
|
551
|
+
if (current.size + 1e-10 >= Math.min(sets[left].size, sets[right].size)) {
|
|
552
|
+
c = 1;
|
|
553
|
+
} else if (current.size <= 1e-10) {
|
|
554
|
+
c = -1;
|
|
555
|
+
}
|
|
556
|
+
constraints[left][right] = constraints[right][left] = c;
|
|
557
|
+
});
|
|
558
|
+
return { distances, constraints };
|
|
559
|
+
}
|
|
560
|
+
function constrainedMDSGradient(x, fxprime, distances, constraints) {
|
|
561
|
+
for (let i = 0; i < fxprime.length; ++i) {
|
|
562
|
+
fxprime[i] = 0;
|
|
563
|
+
}
|
|
564
|
+
let loss = 0;
|
|
565
|
+
for (let i = 0; i < distances.length; ++i) {
|
|
566
|
+
const xi = x[2 * i];
|
|
567
|
+
const yi = x[2 * i + 1];
|
|
568
|
+
for (let j = i + 1; j < distances.length; ++j) {
|
|
569
|
+
const xj = x[2 * j];
|
|
570
|
+
const yj = x[2 * j + 1];
|
|
571
|
+
const dij = distances[i][j];
|
|
572
|
+
const constraint = constraints[i][j];
|
|
573
|
+
const squaredDistance = (xj - xi) * (xj - xi) + (yj - yi) * (yj - yi);
|
|
574
|
+
const distance2 = Math.sqrt(squaredDistance);
|
|
575
|
+
const delta = squaredDistance - dij * dij;
|
|
576
|
+
if (constraint > 0 && distance2 <= dij || constraint < 0 && distance2 >= dij) {
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
loss += 2 * delta * delta;
|
|
580
|
+
fxprime[2 * i] += 4 * delta * (xi - xj);
|
|
581
|
+
fxprime[2 * i + 1] += 4 * delta * (yi - yj);
|
|
582
|
+
fxprime[2 * j] += 4 * delta * (xj - xi);
|
|
583
|
+
fxprime[2 * j + 1] += 4 * delta * (yj - yi);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return loss;
|
|
587
|
+
}
|
|
588
|
+
function bestInitialLayout(areas, params = {}) {
|
|
589
|
+
let initial = greedyLayout(areas, params);
|
|
590
|
+
const loss = params.lossFunction || lossFunction;
|
|
591
|
+
if (areas.length >= 8) {
|
|
592
|
+
const constrained = constrainedMDSLayout(areas, params);
|
|
593
|
+
const constrainedLoss = loss(constrained, areas);
|
|
594
|
+
const greedyLoss = loss(initial, areas);
|
|
595
|
+
if (constrainedLoss + 1e-8 < greedyLoss) {
|
|
596
|
+
initial = constrained;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return initial;
|
|
600
|
+
}
|
|
601
|
+
function constrainedMDSLayout(areas, params = {}) {
|
|
602
|
+
const restarts = params.restarts || 10;
|
|
603
|
+
const sets = [];
|
|
604
|
+
const setids = {};
|
|
605
|
+
for (const area of areas) {
|
|
606
|
+
if (area.sets.length === 1) {
|
|
607
|
+
setids[area.sets[0]] = sets.length;
|
|
608
|
+
sets.push(area);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
let { distances, constraints } = getDistanceMatrices(areas, sets, setids);
|
|
612
|
+
const norm = norm2(distances.map(norm2)) / distances.length;
|
|
613
|
+
distances = distances.map((row) => row.map((value) => value / norm));
|
|
614
|
+
const obj = (x, fxprime) => constrainedMDSGradient(x, fxprime, distances, constraints);
|
|
615
|
+
let best = null;
|
|
616
|
+
for (let i = 0; i < restarts; ++i) {
|
|
617
|
+
const initial = zeros(distances.length * 2).map(Math.random);
|
|
618
|
+
const current = conjugateGradient(obj, initial, params);
|
|
619
|
+
if (!best || current.fx < best.fx) {
|
|
620
|
+
best = current;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
const positions = best.x;
|
|
624
|
+
const circles = {};
|
|
625
|
+
for (let i = 0; i < sets.length; ++i) {
|
|
626
|
+
const set = sets[i];
|
|
627
|
+
circles[set.sets[0]] = {
|
|
628
|
+
x: positions[2 * i] * norm,
|
|
629
|
+
y: positions[2 * i + 1] * norm,
|
|
630
|
+
radius: Math.sqrt(set.size / Math.PI)
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
if (params.history) {
|
|
634
|
+
for (const h of params.history) {
|
|
635
|
+
scale(h.x, norm);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return circles;
|
|
639
|
+
}
|
|
640
|
+
function greedyLayout(areas, params) {
|
|
641
|
+
const loss = params && params.lossFunction ? params.lossFunction : lossFunction;
|
|
642
|
+
const circles = {};
|
|
643
|
+
const setOverlaps = {};
|
|
644
|
+
for (const area of areas) {
|
|
645
|
+
if (area.sets.length === 1) {
|
|
646
|
+
const set = area.sets[0];
|
|
647
|
+
circles[set] = {
|
|
648
|
+
x: 1e10,
|
|
649
|
+
y: 1e10,
|
|
650
|
+
rowid: circles.length,
|
|
651
|
+
size: area.size,
|
|
652
|
+
radius: Math.sqrt(area.size / Math.PI)
|
|
653
|
+
};
|
|
654
|
+
setOverlaps[set] = [];
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
areas = areas.filter((a) => a.sets.length === 2);
|
|
658
|
+
for (const current of areas) {
|
|
659
|
+
let weight = current.weight != null ? current.weight : 1;
|
|
660
|
+
const left = current.sets[0];
|
|
661
|
+
const right = current.sets[1];
|
|
662
|
+
if (current.size + SMALL >= Math.min(circles[left].size, circles[right].size)) {
|
|
663
|
+
weight = 0;
|
|
664
|
+
}
|
|
665
|
+
setOverlaps[left].push({ set: right, size: current.size, weight });
|
|
666
|
+
setOverlaps[right].push({ set: left, size: current.size, weight });
|
|
667
|
+
}
|
|
668
|
+
const mostOverlapped = [];
|
|
669
|
+
Object.keys(setOverlaps).forEach((set) => {
|
|
670
|
+
let size = 0;
|
|
671
|
+
for (let i = 0; i < setOverlaps[set].length; ++i) {
|
|
672
|
+
size += setOverlaps[set][i].size * setOverlaps[set][i].weight;
|
|
673
|
+
}
|
|
674
|
+
mostOverlapped.push({ set, size });
|
|
675
|
+
});
|
|
676
|
+
function sortOrder(a, b) {
|
|
677
|
+
return b.size - a.size;
|
|
678
|
+
}
|
|
679
|
+
mostOverlapped.sort(sortOrder);
|
|
680
|
+
const positioned = {};
|
|
681
|
+
function isPositioned(element) {
|
|
682
|
+
return element.set in positioned;
|
|
683
|
+
}
|
|
684
|
+
function positionSet(point, index) {
|
|
685
|
+
circles[index].x = point.x;
|
|
686
|
+
circles[index].y = point.y;
|
|
687
|
+
positioned[index] = true;
|
|
688
|
+
}
|
|
689
|
+
positionSet({ x: 0, y: 0 }, mostOverlapped[0].set);
|
|
690
|
+
for (let i = 1; i < mostOverlapped.length; ++i) {
|
|
691
|
+
const setIndex = mostOverlapped[i].set;
|
|
692
|
+
const overlap = setOverlaps[setIndex].filter(isPositioned);
|
|
693
|
+
const set = circles[setIndex];
|
|
694
|
+
overlap.sort(sortOrder);
|
|
695
|
+
if (overlap.length === 0) {
|
|
696
|
+
throw "ERROR: missing pairwise overlap information";
|
|
697
|
+
}
|
|
698
|
+
const points = [];
|
|
699
|
+
for (var j = 0; j < overlap.length; ++j) {
|
|
700
|
+
const p1 = circles[overlap[j].set];
|
|
701
|
+
const d1 = distanceFromIntersectArea(set.radius, p1.radius, overlap[j].size);
|
|
702
|
+
points.push({ x: p1.x + d1, y: p1.y });
|
|
703
|
+
points.push({ x: p1.x - d1, y: p1.y });
|
|
704
|
+
points.push({ y: p1.y + d1, x: p1.x });
|
|
705
|
+
points.push({ y: p1.y - d1, x: p1.x });
|
|
706
|
+
for (let k = j + 1; k < overlap.length; ++k) {
|
|
707
|
+
const p2 = circles[overlap[k].set];
|
|
708
|
+
const d2 = distanceFromIntersectArea(set.radius, p2.radius, overlap[k].size);
|
|
709
|
+
const extraPoints = circleCircleIntersection(
|
|
710
|
+
{ x: p1.x, y: p1.y, radius: d1 },
|
|
711
|
+
{ x: p2.x, y: p2.y, radius: d2 }
|
|
712
|
+
);
|
|
713
|
+
points.push(...extraPoints);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
let bestLoss = 1e50;
|
|
717
|
+
let bestPoint = points[0];
|
|
718
|
+
for (const point of points) {
|
|
719
|
+
circles[setIndex].x = point.x;
|
|
720
|
+
circles[setIndex].y = point.y;
|
|
721
|
+
const localLoss = loss(circles, areas);
|
|
722
|
+
if (localLoss < bestLoss) {
|
|
723
|
+
bestLoss = localLoss;
|
|
724
|
+
bestPoint = point;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
positionSet(bestPoint, setIndex);
|
|
728
|
+
}
|
|
729
|
+
return circles;
|
|
730
|
+
}
|
|
731
|
+
function lossFunction(circles, overlaps) {
|
|
732
|
+
let output = 0;
|
|
733
|
+
for (const area of overlaps) {
|
|
734
|
+
if (area.sets.length === 1) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
let overlap;
|
|
738
|
+
if (area.sets.length === 2) {
|
|
739
|
+
const left = circles[area.sets[0]];
|
|
740
|
+
const right = circles[area.sets[1]];
|
|
741
|
+
overlap = circleOverlap(left.radius, right.radius, distance(left, right));
|
|
742
|
+
} else {
|
|
743
|
+
overlap = intersectionArea(area.sets.map((d) => circles[d]));
|
|
744
|
+
}
|
|
745
|
+
const weight = area.weight != null ? area.weight : 1;
|
|
746
|
+
output += weight * (overlap - area.size) * (overlap - area.size);
|
|
747
|
+
}
|
|
748
|
+
return output;
|
|
749
|
+
}
|
|
750
|
+
function logRatioLossFunction(circles, overlaps) {
|
|
751
|
+
let output = 0;
|
|
752
|
+
for (const area of overlaps) {
|
|
753
|
+
if (area.sets.length === 1) {
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
let overlap;
|
|
757
|
+
if (area.sets.length === 2) {
|
|
758
|
+
const left = circles[area.sets[0]];
|
|
759
|
+
const right = circles[area.sets[1]];
|
|
760
|
+
overlap = circleOverlap(left.radius, right.radius, distance(left, right));
|
|
761
|
+
} else {
|
|
762
|
+
overlap = intersectionArea(area.sets.map((d) => circles[d]));
|
|
763
|
+
}
|
|
764
|
+
const weight = area.weight != null ? area.weight : 1;
|
|
765
|
+
const differenceFromIdeal = Math.log((overlap + 1) / (area.size + 1));
|
|
766
|
+
output += weight * differenceFromIdeal * differenceFromIdeal;
|
|
767
|
+
}
|
|
768
|
+
return output;
|
|
769
|
+
}
|
|
770
|
+
function orientateCircles(circles, orientation, orientationOrder) {
|
|
771
|
+
if (orientationOrder == null) {
|
|
772
|
+
circles.sort((a, b) => b.radius - a.radius);
|
|
773
|
+
} else {
|
|
774
|
+
circles.sort(orientationOrder);
|
|
775
|
+
}
|
|
776
|
+
if (circles.length > 0) {
|
|
777
|
+
const largestX = circles[0].x;
|
|
778
|
+
const largestY = circles[0].y;
|
|
779
|
+
for (const circle of circles) {
|
|
780
|
+
circle.x -= largestX;
|
|
781
|
+
circle.y -= largestY;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (circles.length === 2) {
|
|
785
|
+
const dist = distance(circles[0], circles[1]);
|
|
786
|
+
if (dist < Math.abs(circles[1].radius - circles[0].radius)) {
|
|
787
|
+
circles[1].x = circles[0].x + circles[0].radius - circles[1].radius - 1e-10;
|
|
788
|
+
circles[1].y = circles[0].y;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if (circles.length > 1) {
|
|
792
|
+
const rotation = Math.atan2(circles[1].x, circles[1].y) - orientation;
|
|
793
|
+
const c = Math.cos(rotation);
|
|
794
|
+
const s = Math.sin(rotation);
|
|
795
|
+
for (const circle of circles) {
|
|
796
|
+
const x = circle.x;
|
|
797
|
+
const y = circle.y;
|
|
798
|
+
circle.x = c * x - s * y;
|
|
799
|
+
circle.y = s * x + c * y;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (circles.length > 2) {
|
|
803
|
+
let angle = Math.atan2(circles[2].x, circles[2].y) - orientation;
|
|
804
|
+
while (angle < 0) {
|
|
805
|
+
angle += 2 * Math.PI;
|
|
806
|
+
}
|
|
807
|
+
while (angle > 2 * Math.PI) {
|
|
808
|
+
angle -= 2 * Math.PI;
|
|
809
|
+
}
|
|
810
|
+
if (angle > Math.PI) {
|
|
811
|
+
const slope = circles[1].y / (1e-10 + circles[1].x);
|
|
812
|
+
for (const circle of circles) {
|
|
813
|
+
var d = (circle.x + slope * circle.y) / (1 + slope * slope);
|
|
814
|
+
circle.x = 2 * d - circle.x;
|
|
815
|
+
circle.y = 2 * d * slope - circle.y;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
function disjointCluster(circles) {
|
|
821
|
+
circles.forEach((circle) => {
|
|
822
|
+
circle.parent = circle;
|
|
823
|
+
});
|
|
824
|
+
function find(circle) {
|
|
825
|
+
if (circle.parent !== circle) {
|
|
826
|
+
circle.parent = find(circle.parent);
|
|
827
|
+
}
|
|
828
|
+
return circle.parent;
|
|
829
|
+
}
|
|
830
|
+
function union(x, y) {
|
|
831
|
+
const xRoot = find(x);
|
|
832
|
+
const yRoot = find(y);
|
|
833
|
+
xRoot.parent = yRoot;
|
|
834
|
+
}
|
|
835
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
836
|
+
for (let j = i + 1; j < circles.length; ++j) {
|
|
837
|
+
const maxDistance = circles[i].radius + circles[j].radius;
|
|
838
|
+
if (distance(circles[i], circles[j]) + 1e-10 < maxDistance) {
|
|
839
|
+
union(circles[j], circles[i]);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
const disjointClusters = /* @__PURE__ */ new Map();
|
|
844
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
845
|
+
const setid = find(circles[i]).parent.setid;
|
|
846
|
+
if (!disjointClusters.has(setid)) {
|
|
847
|
+
disjointClusters.set(setid, []);
|
|
848
|
+
}
|
|
849
|
+
disjointClusters.get(setid).push(circles[i]);
|
|
850
|
+
}
|
|
851
|
+
circles.forEach((circle) => {
|
|
852
|
+
delete circle.parent;
|
|
853
|
+
});
|
|
854
|
+
return Array.from(disjointClusters.values());
|
|
855
|
+
}
|
|
856
|
+
function getBoundingBox(circles) {
|
|
857
|
+
const minMax = (d) => {
|
|
858
|
+
const hi = circles.reduce((acc, c) => Math.max(acc, c[d] + c.radius), Number.NEGATIVE_INFINITY);
|
|
859
|
+
const lo = circles.reduce((acc, c) => Math.min(acc, c[d] - c.radius), Number.POSITIVE_INFINITY);
|
|
860
|
+
return { max: hi, min: lo };
|
|
861
|
+
};
|
|
862
|
+
return { xRange: minMax("x"), yRange: minMax("y") };
|
|
863
|
+
}
|
|
864
|
+
function normalizeSolution(solution, orientation, orientationOrder) {
|
|
865
|
+
if (orientation == null) {
|
|
866
|
+
orientation = Math.PI / 2;
|
|
867
|
+
}
|
|
868
|
+
let circles = fromObjectNotation(solution).map((d) => Object.assign({}, d));
|
|
869
|
+
const clusters = disjointCluster(circles);
|
|
870
|
+
for (const cluster of clusters) {
|
|
871
|
+
orientateCircles(cluster, orientation, orientationOrder);
|
|
872
|
+
const bounds = getBoundingBox(cluster);
|
|
873
|
+
cluster.size = (bounds.xRange.max - bounds.xRange.min) * (bounds.yRange.max - bounds.yRange.min);
|
|
874
|
+
cluster.bounds = bounds;
|
|
875
|
+
}
|
|
876
|
+
clusters.sort((a, b) => b.size - a.size);
|
|
877
|
+
circles = clusters[0];
|
|
878
|
+
let returnBounds = circles.bounds;
|
|
879
|
+
const spacing = (returnBounds.xRange.max - returnBounds.xRange.min) / 50;
|
|
880
|
+
function addCluster(cluster, right, bottom) {
|
|
881
|
+
if (!cluster) {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
const bounds = cluster.bounds;
|
|
885
|
+
let xOffset;
|
|
886
|
+
let yOffset;
|
|
887
|
+
if (right) {
|
|
888
|
+
xOffset = returnBounds.xRange.max - bounds.xRange.min + spacing;
|
|
889
|
+
} else {
|
|
890
|
+
xOffset = returnBounds.xRange.max - bounds.xRange.max;
|
|
891
|
+
const centreing = (bounds.xRange.max - bounds.xRange.min) / 2 - (returnBounds.xRange.max - returnBounds.xRange.min) / 2;
|
|
892
|
+
if (centreing < 0) {
|
|
893
|
+
xOffset += centreing;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (bottom) {
|
|
897
|
+
yOffset = returnBounds.yRange.max - bounds.yRange.min + spacing;
|
|
898
|
+
} else {
|
|
899
|
+
yOffset = returnBounds.yRange.max - bounds.yRange.max;
|
|
900
|
+
const centreing = (bounds.yRange.max - bounds.yRange.min) / 2 - (returnBounds.yRange.max - returnBounds.yRange.min) / 2;
|
|
901
|
+
if (centreing < 0) {
|
|
902
|
+
yOffset += centreing;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
for (const c of cluster) {
|
|
906
|
+
c.x += xOffset;
|
|
907
|
+
c.y += yOffset;
|
|
908
|
+
circles.push(c);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
let index = 1;
|
|
912
|
+
while (index < clusters.length) {
|
|
913
|
+
addCluster(clusters[index], true, false);
|
|
914
|
+
addCluster(clusters[index + 1], false, true);
|
|
915
|
+
addCluster(clusters[index + 2], true, true);
|
|
916
|
+
index += 3;
|
|
917
|
+
returnBounds = getBoundingBox(circles);
|
|
918
|
+
}
|
|
919
|
+
return toObjectNotation(circles);
|
|
920
|
+
}
|
|
921
|
+
function scaleSolution(solution, width, height, padding, scaleToFit) {
|
|
922
|
+
const circles = fromObjectNotation(solution);
|
|
923
|
+
width -= 2 * padding;
|
|
924
|
+
height -= 2 * padding;
|
|
925
|
+
const { xRange, yRange } = getBoundingBox(circles);
|
|
926
|
+
if (xRange.max === xRange.min || yRange.max === yRange.min) {
|
|
927
|
+
console.log("not scaling solution: zero size detected");
|
|
928
|
+
return solution;
|
|
929
|
+
}
|
|
930
|
+
let xScaling;
|
|
931
|
+
let yScaling;
|
|
932
|
+
if (scaleToFit) {
|
|
933
|
+
const toScaleDiameter = Math.sqrt(scaleToFit / Math.PI) * 2;
|
|
934
|
+
xScaling = width / toScaleDiameter;
|
|
935
|
+
yScaling = height / toScaleDiameter;
|
|
936
|
+
} else {
|
|
937
|
+
xScaling = width / (xRange.max - xRange.min);
|
|
938
|
+
yScaling = height / (yRange.max - yRange.min);
|
|
939
|
+
}
|
|
940
|
+
const scaling = Math.min(yScaling, xScaling);
|
|
941
|
+
const xOffset = (width - (xRange.max - xRange.min) * scaling) / 2;
|
|
942
|
+
const yOffset = (height - (yRange.max - yRange.min) * scaling) / 2;
|
|
943
|
+
return toObjectNotation(
|
|
944
|
+
circles.map((circle) => ({
|
|
945
|
+
radius: scaling * circle.radius,
|
|
946
|
+
x: padding + xOffset + (circle.x - xRange.min) * scaling,
|
|
947
|
+
y: padding + yOffset + (circle.y - yRange.min) * scaling,
|
|
948
|
+
setid: circle.setid
|
|
949
|
+
}))
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
function toObjectNotation(circles) {
|
|
953
|
+
const r = {};
|
|
954
|
+
for (const circle of circles) {
|
|
955
|
+
r[circle.setid] = circle;
|
|
956
|
+
}
|
|
957
|
+
return r;
|
|
958
|
+
}
|
|
959
|
+
function fromObjectNotation(solution) {
|
|
960
|
+
const setids = Object.keys(solution);
|
|
961
|
+
return setids.map((id) => Object.assign(solution[id], { setid: id }));
|
|
962
|
+
}
|
|
963
|
+
function VennDiagram(options = {}) {
|
|
964
|
+
let useViewBox = false, width = 600, height = 350, padding = 15, duration = 1e3, orientation = Math.PI / 2, normalize = true, scaleToFit = null, wrap = true, styled = true, fontSize = null, orientationOrder = null, distinct = false, round = null, symmetricalTextCentre = options && options.symmetricalTextCentre ? options.symmetricalTextCentre : false, colourMap = {}, colourScheme = options && options.colourScheme ? options.colourScheme : options && options.colorScheme ? options.colorScheme : [
|
|
965
|
+
"#1f77b4",
|
|
966
|
+
"#ff7f0e",
|
|
967
|
+
"#2ca02c",
|
|
968
|
+
"#d62728",
|
|
969
|
+
"#9467bd",
|
|
970
|
+
"#8c564b",
|
|
971
|
+
"#e377c2",
|
|
972
|
+
"#7f7f7f",
|
|
973
|
+
"#bcbd22",
|
|
974
|
+
"#17becf"
|
|
975
|
+
], colourIndex = 0, colours = function(key) {
|
|
976
|
+
if (key in colourMap) {
|
|
977
|
+
return colourMap[key];
|
|
978
|
+
}
|
|
979
|
+
var ret = colourMap[key] = colourScheme[colourIndex];
|
|
980
|
+
colourIndex += 1;
|
|
981
|
+
if (colourIndex >= colourScheme.length) {
|
|
982
|
+
colourIndex = 0;
|
|
983
|
+
}
|
|
984
|
+
return ret;
|
|
985
|
+
}, layoutFunction = venn, loss = lossFunction;
|
|
986
|
+
function chart(selection) {
|
|
987
|
+
let data = selection.datum();
|
|
988
|
+
const toRemove = /* @__PURE__ */ new Set();
|
|
989
|
+
data.forEach((datum) => {
|
|
990
|
+
if (datum.size == 0 && datum.sets.length == 1) {
|
|
991
|
+
toRemove.add(datum.sets[0]);
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
data = data.filter((datum) => !datum.sets.some((set) => toRemove.has(set)));
|
|
995
|
+
let circles = {};
|
|
996
|
+
let textCentres = {};
|
|
997
|
+
if (data.length > 0) {
|
|
998
|
+
let solution = layoutFunction(data, { lossFunction: loss, distinct });
|
|
999
|
+
if (normalize) {
|
|
1000
|
+
solution = normalizeSolution(solution, orientation, orientationOrder);
|
|
1001
|
+
}
|
|
1002
|
+
circles = scaleSolution(solution, width, height, padding, scaleToFit);
|
|
1003
|
+
textCentres = computeTextCentres(circles, data, symmetricalTextCentre);
|
|
1004
|
+
}
|
|
1005
|
+
const labels = {};
|
|
1006
|
+
data.forEach((datum) => {
|
|
1007
|
+
if (datum.label) {
|
|
1008
|
+
labels[datum.sets] = datum.label;
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
function label(d) {
|
|
1012
|
+
if (d.sets in labels) {
|
|
1013
|
+
return labels[d.sets];
|
|
1014
|
+
}
|
|
1015
|
+
if (d.sets.length == 1) {
|
|
1016
|
+
return "" + d.sets[0];
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
selection.selectAll("svg").data([circles]).enter().append("svg");
|
|
1020
|
+
const svg = selection.select("svg");
|
|
1021
|
+
if (useViewBox) {
|
|
1022
|
+
svg.attr("viewBox", `0 0 ${width} ${height}`);
|
|
1023
|
+
} else {
|
|
1024
|
+
svg.attr("width", width).attr("height", height);
|
|
1025
|
+
}
|
|
1026
|
+
const previous = {};
|
|
1027
|
+
let hasPrevious = false;
|
|
1028
|
+
svg.selectAll(".venn-area path").each(function(d) {
|
|
1029
|
+
const path = this.getAttribute("d");
|
|
1030
|
+
if (d.sets.length == 1 && path && !distinct) {
|
|
1031
|
+
hasPrevious = true;
|
|
1032
|
+
previous[d.sets[0]] = circleFromPath(path);
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
function pathTween(d) {
|
|
1036
|
+
return (t) => {
|
|
1037
|
+
const c = d.sets.map((set) => {
|
|
1038
|
+
let start = previous[set];
|
|
1039
|
+
let end = circles[set];
|
|
1040
|
+
if (!start) {
|
|
1041
|
+
start = { x: width / 2, y: height / 2, radius: 1 };
|
|
1042
|
+
}
|
|
1043
|
+
if (!end) {
|
|
1044
|
+
end = { x: width / 2, y: height / 2, radius: 1 };
|
|
1045
|
+
}
|
|
1046
|
+
return {
|
|
1047
|
+
x: start.x * (1 - t) + end.x * t,
|
|
1048
|
+
y: start.y * (1 - t) + end.y * t,
|
|
1049
|
+
radius: start.radius * (1 - t) + end.radius * t
|
|
1050
|
+
};
|
|
1051
|
+
});
|
|
1052
|
+
return intersectionAreaPath(c, round);
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
const nodes = svg.selectAll(".venn-area").data(data, (d) => d.sets);
|
|
1056
|
+
const enter = nodes.enter().append("g").attr(
|
|
1057
|
+
"class",
|
|
1058
|
+
(d) => `venn-area venn-${d.sets.length == 1 ? "circle" : "intersection"}${d.colour || d.color ? " venn-coloured" : ""}`
|
|
1059
|
+
).attr("data-venn-sets", (d) => d.sets.join("_"));
|
|
1060
|
+
const enterPath = enter.append("path");
|
|
1061
|
+
const enterText = enter.append("text").attr("class", "label").text((d) => label(d)).attr("text-anchor", "middle").attr("dy", ".35em").attr("x", width / 2).attr("y", height / 2);
|
|
1062
|
+
if (styled) {
|
|
1063
|
+
enterPath.style("fill-opacity", "0").filter((d) => d.sets.length == 1).style("fill", (d) => d.colour ? d.colour : d.color ? d.color : colours(d.sets)).style("fill-opacity", ".25");
|
|
1064
|
+
enterText.style("fill", (d) => {
|
|
1065
|
+
if (d.colour || d.color) {
|
|
1066
|
+
return "#FFF";
|
|
1067
|
+
}
|
|
1068
|
+
if (options.textFill) {
|
|
1069
|
+
return options.textFill;
|
|
1070
|
+
}
|
|
1071
|
+
return d.sets.length == 1 ? colours(d.sets) : "#444";
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
function asTransition(s) {
|
|
1075
|
+
if (typeof s.transition === "function") {
|
|
1076
|
+
return s.transition("venn").duration(duration);
|
|
1077
|
+
}
|
|
1078
|
+
return s;
|
|
1079
|
+
}
|
|
1080
|
+
let update = selection;
|
|
1081
|
+
if (hasPrevious && typeof update.transition === "function") {
|
|
1082
|
+
update = asTransition(selection);
|
|
1083
|
+
update.selectAll("path").attrTween("d", pathTween);
|
|
1084
|
+
} else {
|
|
1085
|
+
update.selectAll("path").attr("d", (d) => intersectionAreaPath(d.sets.map((set) => circles[set])), round);
|
|
1086
|
+
}
|
|
1087
|
+
const updateText = update.selectAll("text").filter((d) => d.sets in textCentres).text((d) => label(d)).attr("x", (d) => Math.floor(textCentres[d.sets].x)).attr("y", (d) => Math.floor(textCentres[d.sets].y));
|
|
1088
|
+
if (wrap) {
|
|
1089
|
+
if (hasPrevious) {
|
|
1090
|
+
if ("on" in updateText) {
|
|
1091
|
+
updateText.on("end", wrapText(circles, label));
|
|
1092
|
+
} else {
|
|
1093
|
+
updateText.each("end", wrapText(circles, label));
|
|
1094
|
+
}
|
|
1095
|
+
} else {
|
|
1096
|
+
updateText.each(wrapText(circles, label));
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
const exit = asTransition(nodes.exit()).remove();
|
|
1100
|
+
if (typeof nodes.transition === "function") {
|
|
1101
|
+
exit.selectAll("path").attrTween("d", pathTween);
|
|
1102
|
+
}
|
|
1103
|
+
const exitText = exit.selectAll("text").attr("x", width / 2).attr("y", height / 2);
|
|
1104
|
+
if (fontSize !== null) {
|
|
1105
|
+
enterText.style("font-size", "0px");
|
|
1106
|
+
updateText.style("font-size", fontSize);
|
|
1107
|
+
exitText.style("font-size", "0px");
|
|
1108
|
+
}
|
|
1109
|
+
return { circles, textCentres, nodes, enter, update, exit };
|
|
1110
|
+
}
|
|
1111
|
+
chart.wrap = function(_) {
|
|
1112
|
+
if (!arguments.length) return wrap;
|
|
1113
|
+
wrap = _;
|
|
1114
|
+
return chart;
|
|
1115
|
+
};
|
|
1116
|
+
chart.useViewBox = function() {
|
|
1117
|
+
useViewBox = true;
|
|
1118
|
+
return chart;
|
|
1119
|
+
};
|
|
1120
|
+
chart.width = function(_) {
|
|
1121
|
+
if (!arguments.length) return width;
|
|
1122
|
+
width = _;
|
|
1123
|
+
return chart;
|
|
1124
|
+
};
|
|
1125
|
+
chart.height = function(_) {
|
|
1126
|
+
if (!arguments.length) return height;
|
|
1127
|
+
height = _;
|
|
1128
|
+
return chart;
|
|
1129
|
+
};
|
|
1130
|
+
chart.padding = function(_) {
|
|
1131
|
+
if (!arguments.length) return padding;
|
|
1132
|
+
padding = _;
|
|
1133
|
+
return chart;
|
|
1134
|
+
};
|
|
1135
|
+
chart.distinct = function(_) {
|
|
1136
|
+
if (!arguments.length) return distinct;
|
|
1137
|
+
distinct = _;
|
|
1138
|
+
return chart;
|
|
1139
|
+
};
|
|
1140
|
+
chart.colours = function(_) {
|
|
1141
|
+
if (!arguments.length) return colours;
|
|
1142
|
+
colours = _;
|
|
1143
|
+
return chart;
|
|
1144
|
+
};
|
|
1145
|
+
chart.colors = function(_) {
|
|
1146
|
+
if (!arguments.length) return colours;
|
|
1147
|
+
colours = _;
|
|
1148
|
+
return chart;
|
|
1149
|
+
};
|
|
1150
|
+
chart.fontSize = function(_) {
|
|
1151
|
+
if (!arguments.length) return fontSize;
|
|
1152
|
+
fontSize = _;
|
|
1153
|
+
return chart;
|
|
1154
|
+
};
|
|
1155
|
+
chart.round = function(_) {
|
|
1156
|
+
if (!arguments.length) return round;
|
|
1157
|
+
round = _;
|
|
1158
|
+
return chart;
|
|
1159
|
+
};
|
|
1160
|
+
chart.duration = function(_) {
|
|
1161
|
+
if (!arguments.length) return duration;
|
|
1162
|
+
duration = _;
|
|
1163
|
+
return chart;
|
|
1164
|
+
};
|
|
1165
|
+
chart.layoutFunction = function(_) {
|
|
1166
|
+
if (!arguments.length) return layoutFunction;
|
|
1167
|
+
layoutFunction = _;
|
|
1168
|
+
return chart;
|
|
1169
|
+
};
|
|
1170
|
+
chart.normalize = function(_) {
|
|
1171
|
+
if (!arguments.length) return normalize;
|
|
1172
|
+
normalize = _;
|
|
1173
|
+
return chart;
|
|
1174
|
+
};
|
|
1175
|
+
chart.scaleToFit = function(_) {
|
|
1176
|
+
if (!arguments.length) return scaleToFit;
|
|
1177
|
+
scaleToFit = _;
|
|
1178
|
+
return chart;
|
|
1179
|
+
};
|
|
1180
|
+
chart.styled = function(_) {
|
|
1181
|
+
if (!arguments.length) return styled;
|
|
1182
|
+
styled = _;
|
|
1183
|
+
return chart;
|
|
1184
|
+
};
|
|
1185
|
+
chart.orientation = function(_) {
|
|
1186
|
+
if (!arguments.length) return orientation;
|
|
1187
|
+
orientation = _;
|
|
1188
|
+
return chart;
|
|
1189
|
+
};
|
|
1190
|
+
chart.orientationOrder = function(_) {
|
|
1191
|
+
if (!arguments.length) return orientationOrder;
|
|
1192
|
+
orientationOrder = _;
|
|
1193
|
+
return chart;
|
|
1194
|
+
};
|
|
1195
|
+
chart.lossFunction = function(_) {
|
|
1196
|
+
if (!arguments.length) return loss;
|
|
1197
|
+
loss = _ === "default" ? lossFunction : _ === "logRatio" ? logRatioLossFunction : _;
|
|
1198
|
+
return chart;
|
|
1199
|
+
};
|
|
1200
|
+
return chart;
|
|
1201
|
+
}
|
|
1202
|
+
function wrapText(circles, labeller) {
|
|
1203
|
+
return function(data) {
|
|
1204
|
+
const text = this;
|
|
1205
|
+
const width = circles[data.sets[0]].radius || 50;
|
|
1206
|
+
const label = labeller(data) || "";
|
|
1207
|
+
const words = label.split(/\s+/).reverse();
|
|
1208
|
+
const maxLines = 3;
|
|
1209
|
+
const minChars = (label.length + words.length) / maxLines;
|
|
1210
|
+
let word = words.pop();
|
|
1211
|
+
let line = [word];
|
|
1212
|
+
let lineNumber = 0;
|
|
1213
|
+
const lineHeight = 1.1;
|
|
1214
|
+
text.textContent = null;
|
|
1215
|
+
const tspans = [];
|
|
1216
|
+
function append(word2) {
|
|
1217
|
+
const tspan2 = text.ownerDocument.createElementNS(text.namespaceURI, "tspan");
|
|
1218
|
+
tspan2.textContent = word2;
|
|
1219
|
+
tspans.push(tspan2);
|
|
1220
|
+
text.append(tspan2);
|
|
1221
|
+
return tspan2;
|
|
1222
|
+
}
|
|
1223
|
+
let tspan = append(word);
|
|
1224
|
+
while (true) {
|
|
1225
|
+
word = words.pop();
|
|
1226
|
+
if (!word) {
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
line.push(word);
|
|
1230
|
+
const joined = line.join(" ");
|
|
1231
|
+
tspan.textContent = joined;
|
|
1232
|
+
if (joined.length > minChars && tspan.getComputedTextLength() > width) {
|
|
1233
|
+
line.pop();
|
|
1234
|
+
tspan.textContent = line.join(" ");
|
|
1235
|
+
line = [word];
|
|
1236
|
+
tspan = append(word);
|
|
1237
|
+
lineNumber++;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
const initial = 0.35 - lineNumber * lineHeight / 2;
|
|
1241
|
+
const x = text.getAttribute("x");
|
|
1242
|
+
const y = text.getAttribute("y");
|
|
1243
|
+
tspans.forEach((t, i) => {
|
|
1244
|
+
t.setAttribute("x", x);
|
|
1245
|
+
t.setAttribute("y", y);
|
|
1246
|
+
t.setAttribute("dy", `${initial + i * lineHeight}em`);
|
|
1247
|
+
});
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
function circleMargin(current, interior, exterior) {
|
|
1251
|
+
let margin = interior[0].radius - distance(interior[0], current);
|
|
1252
|
+
for (let i = 1; i < interior.length; ++i) {
|
|
1253
|
+
const m = interior[i].radius - distance(interior[i], current);
|
|
1254
|
+
if (m <= margin) {
|
|
1255
|
+
margin = m;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
for (let i = 0; i < exterior.length; ++i) {
|
|
1259
|
+
const m = distance(exterior[i], current) - exterior[i].radius;
|
|
1260
|
+
if (m <= margin) {
|
|
1261
|
+
margin = m;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return margin;
|
|
1265
|
+
}
|
|
1266
|
+
function computeTextCentre(interior, exterior, symmetricalTextCentre) {
|
|
1267
|
+
const points = [];
|
|
1268
|
+
for (const c of interior) {
|
|
1269
|
+
points.push({ x: c.x, y: c.y });
|
|
1270
|
+
points.push({ x: c.x + c.radius / 2, y: c.y });
|
|
1271
|
+
points.push({ x: c.x - c.radius / 2, y: c.y });
|
|
1272
|
+
points.push({ x: c.x, y: c.y + c.radius / 2 });
|
|
1273
|
+
points.push({ x: c.x, y: c.y - c.radius / 2 });
|
|
1274
|
+
}
|
|
1275
|
+
let initial = points[0];
|
|
1276
|
+
let margin = circleMargin(points[0], interior, exterior);
|
|
1277
|
+
for (let i = 1; i < points.length; ++i) {
|
|
1278
|
+
const m = circleMargin(points[i], interior, exterior);
|
|
1279
|
+
if (m >= margin) {
|
|
1280
|
+
initial = points[i];
|
|
1281
|
+
margin = m;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
const solution = nelderMead(
|
|
1285
|
+
(p) => -1 * circleMargin({ x: p[0], y: p[1] }, interior, exterior),
|
|
1286
|
+
[initial.x, initial.y],
|
|
1287
|
+
{ maxIterations: 500, minErrorDelta: 1e-10 }
|
|
1288
|
+
).x;
|
|
1289
|
+
const ret = { x: symmetricalTextCentre ? 0 : solution[0], y: solution[1] };
|
|
1290
|
+
let valid = true;
|
|
1291
|
+
for (const i of interior) {
|
|
1292
|
+
if (distance(ret, i) > i.radius) {
|
|
1293
|
+
valid = false;
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
for (const e of exterior) {
|
|
1298
|
+
if (distance(ret, e) < e.radius) {
|
|
1299
|
+
valid = false;
|
|
1300
|
+
break;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
if (valid) {
|
|
1304
|
+
return ret;
|
|
1305
|
+
}
|
|
1306
|
+
if (interior.length == 1) {
|
|
1307
|
+
return { x: interior[0].x, y: interior[0].y };
|
|
1308
|
+
}
|
|
1309
|
+
const areaStats = {};
|
|
1310
|
+
intersectionArea(interior, areaStats);
|
|
1311
|
+
if (areaStats.arcs.length === 0) {
|
|
1312
|
+
return { x: 0, y: -1e3, disjoint: true };
|
|
1313
|
+
}
|
|
1314
|
+
if (areaStats.arcs.length == 1) {
|
|
1315
|
+
return { x: areaStats.arcs[0].circle.x, y: areaStats.arcs[0].circle.y };
|
|
1316
|
+
}
|
|
1317
|
+
if (exterior.length) {
|
|
1318
|
+
return computeTextCentre(interior, []);
|
|
1319
|
+
}
|
|
1320
|
+
return getCenter(areaStats.arcs.map((a) => a.p1));
|
|
1321
|
+
}
|
|
1322
|
+
function getOverlappingCircles(circles) {
|
|
1323
|
+
const ret = {};
|
|
1324
|
+
const circleids = Object.keys(circles);
|
|
1325
|
+
for (const circleid of circleids) {
|
|
1326
|
+
ret[circleid] = [];
|
|
1327
|
+
}
|
|
1328
|
+
for (let i = 0; i < circleids.length; i++) {
|
|
1329
|
+
const ci = circleids[i];
|
|
1330
|
+
const a = circles[ci];
|
|
1331
|
+
for (let j = i + 1; j < circleids.length; ++j) {
|
|
1332
|
+
const cj = circleids[j];
|
|
1333
|
+
const b = circles[cj];
|
|
1334
|
+
const d = distance(a, b);
|
|
1335
|
+
if (d + b.radius <= a.radius + 1e-10) {
|
|
1336
|
+
ret[cj].push(ci);
|
|
1337
|
+
} else if (d + a.radius <= b.radius + 1e-10) {
|
|
1338
|
+
ret[ci].push(cj);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
return ret;
|
|
1343
|
+
}
|
|
1344
|
+
function computeTextCentres(circles, areas, symmetricalTextCentre) {
|
|
1345
|
+
const ret = {};
|
|
1346
|
+
const overlapped = getOverlappingCircles(circles);
|
|
1347
|
+
for (let i = 0; i < areas.length; ++i) {
|
|
1348
|
+
const area = areas[i].sets;
|
|
1349
|
+
const areaids = {};
|
|
1350
|
+
const exclude = {};
|
|
1351
|
+
for (let j = 0; j < area.length; ++j) {
|
|
1352
|
+
areaids[area[j]] = true;
|
|
1353
|
+
const overlaps = overlapped[area[j]];
|
|
1354
|
+
for (let k = 0; k < overlaps.length; ++k) {
|
|
1355
|
+
exclude[overlaps[k]] = true;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
const interior = [];
|
|
1359
|
+
const exterior = [];
|
|
1360
|
+
for (let setid in circles) {
|
|
1361
|
+
if (setid in areaids) {
|
|
1362
|
+
interior.push(circles[setid]);
|
|
1363
|
+
} else if (!(setid in exclude)) {
|
|
1364
|
+
exterior.push(circles[setid]);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
const centre = computeTextCentre(interior, exterior, symmetricalTextCentre);
|
|
1368
|
+
ret[area] = centre;
|
|
1369
|
+
if (centre.disjoint && areas[i].size > 0) {
|
|
1370
|
+
console.log("WARNING: area " + area + " not represented on screen");
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
return ret;
|
|
1374
|
+
}
|
|
1375
|
+
function circlePath(x, y, r) {
|
|
1376
|
+
const ret = [];
|
|
1377
|
+
ret.push("\nM", x, y);
|
|
1378
|
+
ret.push("\nm", -r, 0);
|
|
1379
|
+
ret.push("\na", r, r, 0, 1, 0, r * 2, 0);
|
|
1380
|
+
ret.push("\na", r, r, 0, 1, 0, -r * 2, 0);
|
|
1381
|
+
return ret.join(" ");
|
|
1382
|
+
}
|
|
1383
|
+
function circleFromPath(path) {
|
|
1384
|
+
const tokens = path.split(" ");
|
|
1385
|
+
return { x: Number.parseFloat(tokens[1]), y: Number.parseFloat(tokens[2]), radius: -Number.parseFloat(tokens[4]) };
|
|
1386
|
+
}
|
|
1387
|
+
function intersectionAreaArcs(circles) {
|
|
1388
|
+
if (circles.length === 0) {
|
|
1389
|
+
return [];
|
|
1390
|
+
}
|
|
1391
|
+
const stats = {};
|
|
1392
|
+
intersectionArea(circles, stats);
|
|
1393
|
+
return stats.arcs;
|
|
1394
|
+
}
|
|
1395
|
+
function arcsToPath(arcs, round) {
|
|
1396
|
+
if (arcs.length === 0) {
|
|
1397
|
+
return "M 0 0";
|
|
1398
|
+
}
|
|
1399
|
+
const rFactor = Math.pow(10, round || 0);
|
|
1400
|
+
const r = round != null ? (v) => Math.round(v * rFactor) / rFactor : (v) => v;
|
|
1401
|
+
if (arcs.length == 1) {
|
|
1402
|
+
const circle = arcs[0].circle;
|
|
1403
|
+
return circlePath(r(circle.x), r(circle.y), r(circle.radius));
|
|
1404
|
+
}
|
|
1405
|
+
const ret = ["\nM", r(arcs[0].p2.x), r(arcs[0].p2.y)];
|
|
1406
|
+
for (const arc of arcs) {
|
|
1407
|
+
const radius = r(arc.circle.radius);
|
|
1408
|
+
ret.push("\nA", radius, radius, 0, arc.large ? 1 : 0, arc.sweep ? 1 : 0, r(arc.p1.x), r(arc.p1.y));
|
|
1409
|
+
}
|
|
1410
|
+
return ret.join(" ");
|
|
1411
|
+
}
|
|
1412
|
+
function intersectionAreaPath(circles, round) {
|
|
1413
|
+
return arcsToPath(intersectionAreaArcs(circles), round);
|
|
1414
|
+
}
|
|
1415
|
+
function layout(data, options = {}) {
|
|
1416
|
+
const {
|
|
1417
|
+
lossFunction: loss,
|
|
1418
|
+
layoutFunction: layout2 = venn,
|
|
1419
|
+
normalize = true,
|
|
1420
|
+
orientation = Math.PI / 2,
|
|
1421
|
+
orientationOrder,
|
|
1422
|
+
width = 600,
|
|
1423
|
+
height = 350,
|
|
1424
|
+
padding = 15,
|
|
1425
|
+
scaleToFit = false,
|
|
1426
|
+
symmetricalTextCentre = false,
|
|
1427
|
+
distinct,
|
|
1428
|
+
round = 2
|
|
1429
|
+
} = options;
|
|
1430
|
+
let solution = layout2(data, {
|
|
1431
|
+
lossFunction: loss === "default" || !loss ? lossFunction : loss === "logRatio" ? logRatioLossFunction : loss,
|
|
1432
|
+
distinct
|
|
1433
|
+
});
|
|
1434
|
+
if (normalize) {
|
|
1435
|
+
solution = normalizeSolution(solution, orientation, orientationOrder);
|
|
1436
|
+
}
|
|
1437
|
+
const circles = scaleSolution(solution, width, height, padding, scaleToFit);
|
|
1438
|
+
const textCentres = computeTextCentres(circles, data, symmetricalTextCentre);
|
|
1439
|
+
const circleLookup = new Map(
|
|
1440
|
+
Object.keys(circles).map((set) => [
|
|
1441
|
+
set,
|
|
1442
|
+
{
|
|
1443
|
+
set,
|
|
1444
|
+
x: circles[set].x,
|
|
1445
|
+
y: circles[set].y,
|
|
1446
|
+
radius: circles[set].radius
|
|
1447
|
+
}
|
|
1448
|
+
])
|
|
1449
|
+
);
|
|
1450
|
+
const helpers = data.map((area) => {
|
|
1451
|
+
const circles2 = area.sets.map((s) => circleLookup.get(s));
|
|
1452
|
+
const arcs = intersectionAreaArcs(circles2);
|
|
1453
|
+
const path = arcsToPath(arcs, round);
|
|
1454
|
+
return { circles: circles2, arcs, path, area, has: new Set(area.sets) };
|
|
1455
|
+
});
|
|
1456
|
+
function genDistinctPath(sets) {
|
|
1457
|
+
let r = "";
|
|
1458
|
+
for (const e of helpers) {
|
|
1459
|
+
if (e.has.size > sets.length && sets.every((s) => e.has.has(s))) {
|
|
1460
|
+
r += " " + e.path;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return r;
|
|
1464
|
+
}
|
|
1465
|
+
return helpers.map(({ circles: circles2, arcs, path, area }) => {
|
|
1466
|
+
return {
|
|
1467
|
+
data: area,
|
|
1468
|
+
text: textCentres[area.sets],
|
|
1469
|
+
circles: circles2,
|
|
1470
|
+
arcs,
|
|
1471
|
+
path,
|
|
1472
|
+
distinctPath: path + genDistinctPath(area.sets)
|
|
1473
|
+
};
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
// ../../node_modules/.pnpm/mermaid@11.14.0/node_modules/mermaid/dist/chunks/mermaid.core/vennDiagram-DHZGUBPP.mjs
|
|
1478
|
+
var parser = function() {
|
|
1479
|
+
var o = /* @__PURE__ */ __name(function(k, v, o2, l) {
|
|
1480
|
+
for (o2 = o2 || {}, l = k.length; l--; o2[k[l]] = v) ;
|
|
1481
|
+
return o2;
|
|
1482
|
+
}, "o"), $V0 = [5, 8], $V1 = [7, 8, 11, 12, 17, 19, 22, 24], $V2 = [1, 17], $V3 = [1, 18], $V4 = [7, 8, 11, 12, 14, 15, 16, 17, 19, 20, 21, 22, 24, 27], $V5 = [1, 31], $V6 = [1, 39], $V7 = [7, 8, 11, 12, 17, 19, 22, 24, 27], $V8 = [1, 57], $V9 = [1, 56], $Va = [1, 58], $Vb = [1, 59], $Vc = [1, 60], $Vd = [7, 8, 11, 12, 16, 17, 19, 20, 22, 24, 27, 31, 32, 33];
|
|
1483
|
+
var parser2 = {
|
|
1484
|
+
trace: /* @__PURE__ */ __name(function trace() {
|
|
1485
|
+
}, "trace"),
|
|
1486
|
+
yy: {},
|
|
1487
|
+
symbols_: { "error": 2, "start": 3, "optNewlines": 4, "VENN": 5, "document": 6, "EOF": 7, "NEWLINE": 8, "line": 9, "statement": 10, "TITLE": 11, "SET": 12, "identifier": 13, "BRACKET_LABEL": 14, "COLON": 15, "NUMERIC": 16, "UNION": 17, "identifierList": 18, "TEXT": 19, "IDENTIFIER": 20, "STRING": 21, "INDENT_TEXT": 22, "indentedTextTail": 23, "STYLE": 24, "stylesOpt": 25, "styleField": 26, "COMMA": 27, "styleValue": 28, "valueTokens": 29, "valueToken": 30, "HEXCOLOR": 31, "RGBCOLOR": 32, "RGBACOLOR": 33, "$accept": 0, "$end": 1 },
|
|
1488
|
+
terminals_: { 2: "error", 5: "VENN", 7: "EOF", 8: "NEWLINE", 11: "TITLE", 12: "SET", 14: "BRACKET_LABEL", 15: "COLON", 16: "NUMERIC", 17: "UNION", 19: "TEXT", 20: "IDENTIFIER", 21: "STRING", 22: "INDENT_TEXT", 24: "STYLE", 27: "COMMA", 31: "HEXCOLOR", 32: "RGBCOLOR", 33: "RGBACOLOR" },
|
|
1489
|
+
productions_: [0, [3, 4], [4, 0], [4, 2], [6, 0], [6, 2], [9, 1], [9, 1], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 2], [10, 3], [10, 4], [10, 5], [10, 3], [10, 3], [10, 3], [10, 4], [10, 4], [10, 2], [10, 3], [23, 1], [23, 1], [23, 1], [23, 2], [23, 2], [25, 1], [25, 3], [26, 3], [28, 1], [28, 1], [29, 1], [29, 2], [30, 1], [30, 1], [30, 1], [30, 1], [30, 1], [18, 1], [18, 3], [13, 1], [13, 1]],
|
|
1490
|
+
performAction: /* @__PURE__ */ __name(function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
|
|
1491
|
+
var $0 = $$.length - 1;
|
|
1492
|
+
switch (yystate) {
|
|
1493
|
+
case 1:
|
|
1494
|
+
return $$[$0 - 1];
|
|
1495
|
+
break;
|
|
1496
|
+
case 2:
|
|
1497
|
+
case 3:
|
|
1498
|
+
case 4:
|
|
1499
|
+
this.$ = [];
|
|
1500
|
+
break;
|
|
1501
|
+
case 5:
|
|
1502
|
+
$$[$0 - 1].push($$[$0]);
|
|
1503
|
+
this.$ = $$[$0 - 1];
|
|
1504
|
+
break;
|
|
1505
|
+
case 6:
|
|
1506
|
+
this.$ = [];
|
|
1507
|
+
break;
|
|
1508
|
+
case 7:
|
|
1509
|
+
case 22:
|
|
1510
|
+
case 32:
|
|
1511
|
+
case 36:
|
|
1512
|
+
case 37:
|
|
1513
|
+
case 38:
|
|
1514
|
+
case 39:
|
|
1515
|
+
case 40:
|
|
1516
|
+
this.$ = $$[$0];
|
|
1517
|
+
break;
|
|
1518
|
+
case 8:
|
|
1519
|
+
yy.setDiagramTitle($$[$0].substr(6));
|
|
1520
|
+
this.$ = $$[$0].substr(6);
|
|
1521
|
+
break;
|
|
1522
|
+
case 9:
|
|
1523
|
+
yy.addSubsetData([$$[$0]], void 0, void 0);
|
|
1524
|
+
if (yy.setIndentMode) {
|
|
1525
|
+
yy.setIndentMode(true);
|
|
1526
|
+
}
|
|
1527
|
+
break;
|
|
1528
|
+
case 10:
|
|
1529
|
+
yy.addSubsetData([$$[$0 - 1]], $$[$0], void 0);
|
|
1530
|
+
if (yy.setIndentMode) {
|
|
1531
|
+
yy.setIndentMode(true);
|
|
1532
|
+
}
|
|
1533
|
+
break;
|
|
1534
|
+
case 11:
|
|
1535
|
+
yy.addSubsetData([$$[$0 - 2]], void 0, parseFloat($$[$0]));
|
|
1536
|
+
if (yy.setIndentMode) {
|
|
1537
|
+
yy.setIndentMode(true);
|
|
1538
|
+
}
|
|
1539
|
+
break;
|
|
1540
|
+
case 12:
|
|
1541
|
+
yy.addSubsetData([$$[$0 - 3]], $$[$0 - 2], parseFloat($$[$0]));
|
|
1542
|
+
if (yy.setIndentMode) {
|
|
1543
|
+
yy.setIndentMode(true);
|
|
1544
|
+
}
|
|
1545
|
+
break;
|
|
1546
|
+
case 13:
|
|
1547
|
+
if ($$[$0].length < 2) {
|
|
1548
|
+
throw new Error("union requires multiple identifiers");
|
|
1549
|
+
}
|
|
1550
|
+
if (yy.validateUnionIdentifiers) {
|
|
1551
|
+
yy.validateUnionIdentifiers($$[$0]);
|
|
1552
|
+
}
|
|
1553
|
+
yy.addSubsetData($$[$0], void 0, void 0);
|
|
1554
|
+
if (yy.setIndentMode) {
|
|
1555
|
+
yy.setIndentMode(true);
|
|
1556
|
+
}
|
|
1557
|
+
break;
|
|
1558
|
+
case 14:
|
|
1559
|
+
if ($$[$0 - 1].length < 2) {
|
|
1560
|
+
throw new Error("union requires multiple identifiers");
|
|
1561
|
+
}
|
|
1562
|
+
if (yy.validateUnionIdentifiers) {
|
|
1563
|
+
yy.validateUnionIdentifiers($$[$0 - 1]);
|
|
1564
|
+
}
|
|
1565
|
+
yy.addSubsetData($$[$0 - 1], $$[$0], void 0);
|
|
1566
|
+
if (yy.setIndentMode) {
|
|
1567
|
+
yy.setIndentMode(true);
|
|
1568
|
+
}
|
|
1569
|
+
break;
|
|
1570
|
+
case 15:
|
|
1571
|
+
if ($$[$0 - 2].length < 2) {
|
|
1572
|
+
throw new Error("union requires multiple identifiers");
|
|
1573
|
+
}
|
|
1574
|
+
if (yy.validateUnionIdentifiers) {
|
|
1575
|
+
yy.validateUnionIdentifiers($$[$0 - 2]);
|
|
1576
|
+
}
|
|
1577
|
+
yy.addSubsetData($$[$0 - 2], void 0, parseFloat($$[$0]));
|
|
1578
|
+
if (yy.setIndentMode) {
|
|
1579
|
+
yy.setIndentMode(true);
|
|
1580
|
+
}
|
|
1581
|
+
break;
|
|
1582
|
+
case 16:
|
|
1583
|
+
if ($$[$0 - 3].length < 2) {
|
|
1584
|
+
throw new Error("union requires multiple identifiers");
|
|
1585
|
+
}
|
|
1586
|
+
if (yy.validateUnionIdentifiers) {
|
|
1587
|
+
yy.validateUnionIdentifiers($$[$0 - 3]);
|
|
1588
|
+
}
|
|
1589
|
+
yy.addSubsetData($$[$0 - 3], $$[$0 - 2], parseFloat($$[$0]));
|
|
1590
|
+
if (yy.setIndentMode) {
|
|
1591
|
+
yy.setIndentMode(true);
|
|
1592
|
+
}
|
|
1593
|
+
break;
|
|
1594
|
+
case 17:
|
|
1595
|
+
case 18:
|
|
1596
|
+
case 19:
|
|
1597
|
+
yy.addTextData($$[$0 - 1], $$[$0], void 0);
|
|
1598
|
+
break;
|
|
1599
|
+
case 20:
|
|
1600
|
+
case 21:
|
|
1601
|
+
yy.addTextData($$[$0 - 2], $$[$0 - 1], $$[$0]);
|
|
1602
|
+
break;
|
|
1603
|
+
case 23:
|
|
1604
|
+
yy.addStyleData($$[$0 - 1], $$[$0]);
|
|
1605
|
+
break;
|
|
1606
|
+
case 24:
|
|
1607
|
+
case 25:
|
|
1608
|
+
case 26:
|
|
1609
|
+
var cs = yy.getCurrentSets();
|
|
1610
|
+
if (!cs) throw new Error("text requires set");
|
|
1611
|
+
yy.addTextData(cs, $$[$0], void 0);
|
|
1612
|
+
break;
|
|
1613
|
+
case 27:
|
|
1614
|
+
case 28:
|
|
1615
|
+
var cs = yy.getCurrentSets();
|
|
1616
|
+
if (!cs) throw new Error("text requires set");
|
|
1617
|
+
yy.addTextData(cs, $$[$0 - 1], $$[$0]);
|
|
1618
|
+
break;
|
|
1619
|
+
case 29:
|
|
1620
|
+
case 41:
|
|
1621
|
+
this.$ = [$$[$0]];
|
|
1622
|
+
break;
|
|
1623
|
+
case 30:
|
|
1624
|
+
case 42:
|
|
1625
|
+
this.$ = [...$$[$0 - 2], $$[$0]];
|
|
1626
|
+
break;
|
|
1627
|
+
case 31:
|
|
1628
|
+
this.$ = [$$[$0 - 2], $$[$0]];
|
|
1629
|
+
break;
|
|
1630
|
+
case 33:
|
|
1631
|
+
this.$ = $$[$0].join(" ");
|
|
1632
|
+
break;
|
|
1633
|
+
case 34:
|
|
1634
|
+
this.$ = [$$[$0]];
|
|
1635
|
+
break;
|
|
1636
|
+
case 35:
|
|
1637
|
+
$$[$0 - 1].push($$[$0]);
|
|
1638
|
+
this.$ = $$[$0 - 1];
|
|
1639
|
+
break;
|
|
1640
|
+
case 43:
|
|
1641
|
+
case 44:
|
|
1642
|
+
this.$ = $$[$0];
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
}, "anonymous"),
|
|
1646
|
+
table: [o($V0, [2, 2], { 3: 1, 4: 2 }), { 1: [3] }, { 5: [1, 3], 8: [1, 4] }, o($V1, [2, 4], { 6: 5 }), o($V0, [2, 3]), { 7: [1, 6], 8: [1, 8], 9: 7, 10: 9, 11: [1, 10], 12: [1, 11], 17: [1, 12], 19: [1, 13], 22: [1, 14], 24: [1, 15] }, { 1: [2, 1] }, o($V1, [2, 5]), o($V1, [2, 6]), o($V1, [2, 7]), o($V1, [2, 8]), { 13: 16, 20: $V2, 21: $V3 }, { 13: 20, 18: 19, 20: $V2, 21: $V3 }, { 13: 20, 18: 21, 20: $V2, 21: $V3 }, { 16: [1, 25], 20: [1, 23], 21: [1, 24], 23: 22 }, { 13: 20, 18: 26, 20: $V2, 21: $V3 }, o($V1, [2, 9], { 14: [1, 27], 15: [1, 28] }), o($V4, [2, 43]), o($V4, [2, 44]), o($V1, [2, 13], { 14: [1, 29], 15: [1, 30], 27: $V5 }), o($V4, [2, 41]), { 16: [1, 34], 20: [1, 32], 21: [1, 33], 27: $V5 }, o($V1, [2, 22]), o($V1, [2, 24], { 14: [1, 35] }), o($V1, [2, 25], { 14: [1, 36] }), o($V1, [2, 26]), { 20: $V6, 25: 37, 26: 38, 27: $V5 }, o($V1, [2, 10], { 15: [1, 40] }), { 16: [1, 41] }, o($V1, [2, 14], { 15: [1, 42] }), { 16: [1, 43] }, { 13: 44, 20: $V2, 21: $V3 }, o($V1, [2, 17], { 14: [1, 45] }), o($V1, [2, 18], { 14: [1, 46] }), o($V1, [2, 19]), o($V1, [2, 27]), o($V1, [2, 28]), o($V1, [2, 23], { 27: [1, 47] }), o($V7, [2, 29]), { 15: [1, 48] }, { 16: [1, 49] }, o($V1, [2, 11]), { 16: [1, 50] }, o($V1, [2, 15]), o($V4, [2, 42]), o($V1, [2, 20]), o($V1, [2, 21]), { 20: $V6, 26: 51 }, { 16: $V8, 20: $V9, 21: [1, 53], 28: 52, 29: 54, 30: 55, 31: $Va, 32: $Vb, 33: $Vc }, o($V1, [2, 12]), o($V1, [2, 16]), o($V7, [2, 30]), o($V7, [2, 31]), o($V7, [2, 32]), o($V7, [2, 33], { 30: 61, 16: $V8, 20: $V9, 31: $Va, 32: $Vb, 33: $Vc }), o($Vd, [2, 34]), o($Vd, [2, 36]), o($Vd, [2, 37]), o($Vd, [2, 38]), o($Vd, [2, 39]), o($Vd, [2, 40]), o($Vd, [2, 35])],
|
|
1647
|
+
defaultActions: { 6: [2, 1] },
|
|
1648
|
+
parseError: /* @__PURE__ */ __name(function parseError(str, hash) {
|
|
1649
|
+
if (hash.recoverable) {
|
|
1650
|
+
this.trace(str);
|
|
1651
|
+
} else {
|
|
1652
|
+
var error = new Error(str);
|
|
1653
|
+
error.hash = hash;
|
|
1654
|
+
throw error;
|
|
1655
|
+
}
|
|
1656
|
+
}, "parseError"),
|
|
1657
|
+
parse: /* @__PURE__ */ __name(function parse(input) {
|
|
1658
|
+
var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
|
|
1659
|
+
var args = lstack.slice.call(arguments, 1);
|
|
1660
|
+
var lexer2 = Object.create(this.lexer);
|
|
1661
|
+
var sharedState = { yy: {} };
|
|
1662
|
+
for (var k in this.yy) {
|
|
1663
|
+
if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
|
|
1664
|
+
sharedState.yy[k] = this.yy[k];
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
lexer2.setInput(input, sharedState.yy);
|
|
1668
|
+
sharedState.yy.lexer = lexer2;
|
|
1669
|
+
sharedState.yy.parser = this;
|
|
1670
|
+
if (typeof lexer2.yylloc == "undefined") {
|
|
1671
|
+
lexer2.yylloc = {};
|
|
1672
|
+
}
|
|
1673
|
+
var yyloc = lexer2.yylloc;
|
|
1674
|
+
lstack.push(yyloc);
|
|
1675
|
+
var ranges = lexer2.options && lexer2.options.ranges;
|
|
1676
|
+
if (typeof sharedState.yy.parseError === "function") {
|
|
1677
|
+
this.parseError = sharedState.yy.parseError;
|
|
1678
|
+
} else {
|
|
1679
|
+
this.parseError = Object.getPrototypeOf(this).parseError;
|
|
1680
|
+
}
|
|
1681
|
+
function popStack(n) {
|
|
1682
|
+
stack.length = stack.length - 2 * n;
|
|
1683
|
+
vstack.length = vstack.length - n;
|
|
1684
|
+
lstack.length = lstack.length - n;
|
|
1685
|
+
}
|
|
1686
|
+
__name(popStack, "popStack");
|
|
1687
|
+
function lex() {
|
|
1688
|
+
var token;
|
|
1689
|
+
token = tstack.pop() || lexer2.lex() || EOF;
|
|
1690
|
+
if (typeof token !== "number") {
|
|
1691
|
+
if (token instanceof Array) {
|
|
1692
|
+
tstack = token;
|
|
1693
|
+
token = tstack.pop();
|
|
1694
|
+
}
|
|
1695
|
+
token = self.symbols_[token] || token;
|
|
1696
|
+
}
|
|
1697
|
+
return token;
|
|
1698
|
+
}
|
|
1699
|
+
__name(lex, "lex");
|
|
1700
|
+
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
|
|
1701
|
+
while (true) {
|
|
1702
|
+
state = stack[stack.length - 1];
|
|
1703
|
+
if (this.defaultActions[state]) {
|
|
1704
|
+
action = this.defaultActions[state];
|
|
1705
|
+
} else {
|
|
1706
|
+
if (symbol === null || typeof symbol == "undefined") {
|
|
1707
|
+
symbol = lex();
|
|
1708
|
+
}
|
|
1709
|
+
action = table[state] && table[state][symbol];
|
|
1710
|
+
}
|
|
1711
|
+
if (typeof action === "undefined" || !action.length || !action[0]) {
|
|
1712
|
+
var errStr = "";
|
|
1713
|
+
expected = [];
|
|
1714
|
+
for (p in table[state]) {
|
|
1715
|
+
if (this.terminals_[p] && p > TERROR) {
|
|
1716
|
+
expected.push("'" + this.terminals_[p] + "'");
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
if (lexer2.showPosition) {
|
|
1720
|
+
errStr = "Parse error on line " + (yylineno + 1) + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
|
|
1721
|
+
} else {
|
|
1722
|
+
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
|
|
1723
|
+
}
|
|
1724
|
+
this.parseError(errStr, {
|
|
1725
|
+
text: lexer2.match,
|
|
1726
|
+
token: this.terminals_[symbol] || symbol,
|
|
1727
|
+
line: lexer2.yylineno,
|
|
1728
|
+
loc: yyloc,
|
|
1729
|
+
expected
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
if (action[0] instanceof Array && action.length > 1) {
|
|
1733
|
+
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
|
|
1734
|
+
}
|
|
1735
|
+
switch (action[0]) {
|
|
1736
|
+
case 1:
|
|
1737
|
+
stack.push(symbol);
|
|
1738
|
+
vstack.push(lexer2.yytext);
|
|
1739
|
+
lstack.push(lexer2.yylloc);
|
|
1740
|
+
stack.push(action[1]);
|
|
1741
|
+
symbol = null;
|
|
1742
|
+
if (!preErrorSymbol) {
|
|
1743
|
+
yyleng = lexer2.yyleng;
|
|
1744
|
+
yytext = lexer2.yytext;
|
|
1745
|
+
yylineno = lexer2.yylineno;
|
|
1746
|
+
yyloc = lexer2.yylloc;
|
|
1747
|
+
if (recovering > 0) {
|
|
1748
|
+
recovering--;
|
|
1749
|
+
}
|
|
1750
|
+
} else {
|
|
1751
|
+
symbol = preErrorSymbol;
|
|
1752
|
+
preErrorSymbol = null;
|
|
1753
|
+
}
|
|
1754
|
+
break;
|
|
1755
|
+
case 2:
|
|
1756
|
+
len = this.productions_[action[1]][1];
|
|
1757
|
+
yyval.$ = vstack[vstack.length - len];
|
|
1758
|
+
yyval._$ = {
|
|
1759
|
+
first_line: lstack[lstack.length - (len || 1)].first_line,
|
|
1760
|
+
last_line: lstack[lstack.length - 1].last_line,
|
|
1761
|
+
first_column: lstack[lstack.length - (len || 1)].first_column,
|
|
1762
|
+
last_column: lstack[lstack.length - 1].last_column
|
|
1763
|
+
};
|
|
1764
|
+
if (ranges) {
|
|
1765
|
+
yyval._$.range = [
|
|
1766
|
+
lstack[lstack.length - (len || 1)].range[0],
|
|
1767
|
+
lstack[lstack.length - 1].range[1]
|
|
1768
|
+
];
|
|
1769
|
+
}
|
|
1770
|
+
r = this.performAction.apply(yyval, [
|
|
1771
|
+
yytext,
|
|
1772
|
+
yyleng,
|
|
1773
|
+
yylineno,
|
|
1774
|
+
sharedState.yy,
|
|
1775
|
+
action[1],
|
|
1776
|
+
vstack,
|
|
1777
|
+
lstack
|
|
1778
|
+
].concat(args));
|
|
1779
|
+
if (typeof r !== "undefined") {
|
|
1780
|
+
return r;
|
|
1781
|
+
}
|
|
1782
|
+
if (len) {
|
|
1783
|
+
stack = stack.slice(0, -1 * len * 2);
|
|
1784
|
+
vstack = vstack.slice(0, -1 * len);
|
|
1785
|
+
lstack = lstack.slice(0, -1 * len);
|
|
1786
|
+
}
|
|
1787
|
+
stack.push(this.productions_[action[1]][0]);
|
|
1788
|
+
vstack.push(yyval.$);
|
|
1789
|
+
lstack.push(yyval._$);
|
|
1790
|
+
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
|
|
1791
|
+
stack.push(newState);
|
|
1792
|
+
break;
|
|
1793
|
+
case 3:
|
|
1794
|
+
return true;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
return true;
|
|
1798
|
+
}, "parse")
|
|
1799
|
+
};
|
|
1800
|
+
var lexer = /* @__PURE__ */ function() {
|
|
1801
|
+
var lexer2 = {
|
|
1802
|
+
EOF: 1,
|
|
1803
|
+
parseError: /* @__PURE__ */ __name(function parseError(str, hash) {
|
|
1804
|
+
if (this.yy.parser) {
|
|
1805
|
+
this.yy.parser.parseError(str, hash);
|
|
1806
|
+
} else {
|
|
1807
|
+
throw new Error(str);
|
|
1808
|
+
}
|
|
1809
|
+
}, "parseError"),
|
|
1810
|
+
// resets the lexer, sets new input
|
|
1811
|
+
setInput: /* @__PURE__ */ __name(function(input, yy) {
|
|
1812
|
+
this.yy = yy || this.yy || {};
|
|
1813
|
+
this._input = input;
|
|
1814
|
+
this._more = this._backtrack = this.done = false;
|
|
1815
|
+
this.yylineno = this.yyleng = 0;
|
|
1816
|
+
this.yytext = this.matched = this.match = "";
|
|
1817
|
+
this.conditionStack = ["INITIAL"];
|
|
1818
|
+
this.yylloc = {
|
|
1819
|
+
first_line: 1,
|
|
1820
|
+
first_column: 0,
|
|
1821
|
+
last_line: 1,
|
|
1822
|
+
last_column: 0
|
|
1823
|
+
};
|
|
1824
|
+
if (this.options.ranges) {
|
|
1825
|
+
this.yylloc.range = [0, 0];
|
|
1826
|
+
}
|
|
1827
|
+
this.offset = 0;
|
|
1828
|
+
return this;
|
|
1829
|
+
}, "setInput"),
|
|
1830
|
+
// consumes and returns one char from the input
|
|
1831
|
+
input: /* @__PURE__ */ __name(function() {
|
|
1832
|
+
var ch = this._input[0];
|
|
1833
|
+
this.yytext += ch;
|
|
1834
|
+
this.yyleng++;
|
|
1835
|
+
this.offset++;
|
|
1836
|
+
this.match += ch;
|
|
1837
|
+
this.matched += ch;
|
|
1838
|
+
var lines = ch.match(/(?:\r\n?|\n).*/g);
|
|
1839
|
+
if (lines) {
|
|
1840
|
+
this.yylineno++;
|
|
1841
|
+
this.yylloc.last_line++;
|
|
1842
|
+
} else {
|
|
1843
|
+
this.yylloc.last_column++;
|
|
1844
|
+
}
|
|
1845
|
+
if (this.options.ranges) {
|
|
1846
|
+
this.yylloc.range[1]++;
|
|
1847
|
+
}
|
|
1848
|
+
this._input = this._input.slice(1);
|
|
1849
|
+
return ch;
|
|
1850
|
+
}, "input"),
|
|
1851
|
+
// unshifts one char (or a string) into the input
|
|
1852
|
+
unput: /* @__PURE__ */ __name(function(ch) {
|
|
1853
|
+
var len = ch.length;
|
|
1854
|
+
var lines = ch.split(/(?:\r\n?|\n)/g);
|
|
1855
|
+
this._input = ch + this._input;
|
|
1856
|
+
this.yytext = this.yytext.substr(0, this.yytext.length - len);
|
|
1857
|
+
this.offset -= len;
|
|
1858
|
+
var oldLines = this.match.split(/(?:\r\n?|\n)/g);
|
|
1859
|
+
this.match = this.match.substr(0, this.match.length - 1);
|
|
1860
|
+
this.matched = this.matched.substr(0, this.matched.length - 1);
|
|
1861
|
+
if (lines.length - 1) {
|
|
1862
|
+
this.yylineno -= lines.length - 1;
|
|
1863
|
+
}
|
|
1864
|
+
var r = this.yylloc.range;
|
|
1865
|
+
this.yylloc = {
|
|
1866
|
+
first_line: this.yylloc.first_line,
|
|
1867
|
+
last_line: this.yylineno + 1,
|
|
1868
|
+
first_column: this.yylloc.first_column,
|
|
1869
|
+
last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
|
|
1870
|
+
};
|
|
1871
|
+
if (this.options.ranges) {
|
|
1872
|
+
this.yylloc.range = [r[0], r[0] + this.yyleng - len];
|
|
1873
|
+
}
|
|
1874
|
+
this.yyleng = this.yytext.length;
|
|
1875
|
+
return this;
|
|
1876
|
+
}, "unput"),
|
|
1877
|
+
// When called from action, caches matched text and appends it on next action
|
|
1878
|
+
more: /* @__PURE__ */ __name(function() {
|
|
1879
|
+
this._more = true;
|
|
1880
|
+
return this;
|
|
1881
|
+
}, "more"),
|
|
1882
|
+
// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
|
|
1883
|
+
reject: /* @__PURE__ */ __name(function() {
|
|
1884
|
+
if (this.options.backtrack_lexer) {
|
|
1885
|
+
this._backtrack = true;
|
|
1886
|
+
} else {
|
|
1887
|
+
return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
|
|
1888
|
+
text: "",
|
|
1889
|
+
token: null,
|
|
1890
|
+
line: this.yylineno
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
return this;
|
|
1894
|
+
}, "reject"),
|
|
1895
|
+
// retain first n characters of the match
|
|
1896
|
+
less: /* @__PURE__ */ __name(function(n) {
|
|
1897
|
+
this.unput(this.match.slice(n));
|
|
1898
|
+
}, "less"),
|
|
1899
|
+
// displays already matched input, i.e. for error messages
|
|
1900
|
+
pastInput: /* @__PURE__ */ __name(function() {
|
|
1901
|
+
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
|
1902
|
+
return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
|
|
1903
|
+
}, "pastInput"),
|
|
1904
|
+
// displays upcoming input, i.e. for error messages
|
|
1905
|
+
upcomingInput: /* @__PURE__ */ __name(function() {
|
|
1906
|
+
var next = this.match;
|
|
1907
|
+
if (next.length < 20) {
|
|
1908
|
+
next += this._input.substr(0, 20 - next.length);
|
|
1909
|
+
}
|
|
1910
|
+
return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
|
|
1911
|
+
}, "upcomingInput"),
|
|
1912
|
+
// displays the character position where the lexing error occurred, i.e. for error messages
|
|
1913
|
+
showPosition: /* @__PURE__ */ __name(function() {
|
|
1914
|
+
var pre = this.pastInput();
|
|
1915
|
+
var c = new Array(pre.length + 1).join("-");
|
|
1916
|
+
return pre + this.upcomingInput() + "\n" + c + "^";
|
|
1917
|
+
}, "showPosition"),
|
|
1918
|
+
// test the lexed token: return FALSE when not a match, otherwise return token
|
|
1919
|
+
test_match: /* @__PURE__ */ __name(function(match, indexed_rule) {
|
|
1920
|
+
var token, lines, backup;
|
|
1921
|
+
if (this.options.backtrack_lexer) {
|
|
1922
|
+
backup = {
|
|
1923
|
+
yylineno: this.yylineno,
|
|
1924
|
+
yylloc: {
|
|
1925
|
+
first_line: this.yylloc.first_line,
|
|
1926
|
+
last_line: this.last_line,
|
|
1927
|
+
first_column: this.yylloc.first_column,
|
|
1928
|
+
last_column: this.yylloc.last_column
|
|
1929
|
+
},
|
|
1930
|
+
yytext: this.yytext,
|
|
1931
|
+
match: this.match,
|
|
1932
|
+
matches: this.matches,
|
|
1933
|
+
matched: this.matched,
|
|
1934
|
+
yyleng: this.yyleng,
|
|
1935
|
+
offset: this.offset,
|
|
1936
|
+
_more: this._more,
|
|
1937
|
+
_input: this._input,
|
|
1938
|
+
yy: this.yy,
|
|
1939
|
+
conditionStack: this.conditionStack.slice(0),
|
|
1940
|
+
done: this.done
|
|
1941
|
+
};
|
|
1942
|
+
if (this.options.ranges) {
|
|
1943
|
+
backup.yylloc.range = this.yylloc.range.slice(0);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
lines = match[0].match(/(?:\r\n?|\n).*/g);
|
|
1947
|
+
if (lines) {
|
|
1948
|
+
this.yylineno += lines.length;
|
|
1949
|
+
}
|
|
1950
|
+
this.yylloc = {
|
|
1951
|
+
first_line: this.yylloc.last_line,
|
|
1952
|
+
last_line: this.yylineno + 1,
|
|
1953
|
+
first_column: this.yylloc.last_column,
|
|
1954
|
+
last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
|
|
1955
|
+
};
|
|
1956
|
+
this.yytext += match[0];
|
|
1957
|
+
this.match += match[0];
|
|
1958
|
+
this.matches = match;
|
|
1959
|
+
this.yyleng = this.yytext.length;
|
|
1960
|
+
if (this.options.ranges) {
|
|
1961
|
+
this.yylloc.range = [this.offset, this.offset += this.yyleng];
|
|
1962
|
+
}
|
|
1963
|
+
this._more = false;
|
|
1964
|
+
this._backtrack = false;
|
|
1965
|
+
this._input = this._input.slice(match[0].length);
|
|
1966
|
+
this.matched += match[0];
|
|
1967
|
+
token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
|
|
1968
|
+
if (this.done && this._input) {
|
|
1969
|
+
this.done = false;
|
|
1970
|
+
}
|
|
1971
|
+
if (token) {
|
|
1972
|
+
return token;
|
|
1973
|
+
} else if (this._backtrack) {
|
|
1974
|
+
for (var k in backup) {
|
|
1975
|
+
this[k] = backup[k];
|
|
1976
|
+
}
|
|
1977
|
+
return false;
|
|
1978
|
+
}
|
|
1979
|
+
return false;
|
|
1980
|
+
}, "test_match"),
|
|
1981
|
+
// return next match in input
|
|
1982
|
+
next: /* @__PURE__ */ __name(function() {
|
|
1983
|
+
if (this.done) {
|
|
1984
|
+
return this.EOF;
|
|
1985
|
+
}
|
|
1986
|
+
if (!this._input) {
|
|
1987
|
+
this.done = true;
|
|
1988
|
+
}
|
|
1989
|
+
var token, match, tempMatch, index;
|
|
1990
|
+
if (!this._more) {
|
|
1991
|
+
this.yytext = "";
|
|
1992
|
+
this.match = "";
|
|
1993
|
+
}
|
|
1994
|
+
var rules = this._currentRules();
|
|
1995
|
+
for (var i = 0; i < rules.length; i++) {
|
|
1996
|
+
tempMatch = this._input.match(this.rules[rules[i]]);
|
|
1997
|
+
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
|
1998
|
+
match = tempMatch;
|
|
1999
|
+
index = i;
|
|
2000
|
+
if (this.options.backtrack_lexer) {
|
|
2001
|
+
token = this.test_match(tempMatch, rules[i]);
|
|
2002
|
+
if (token !== false) {
|
|
2003
|
+
return token;
|
|
2004
|
+
} else if (this._backtrack) {
|
|
2005
|
+
match = false;
|
|
2006
|
+
continue;
|
|
2007
|
+
} else {
|
|
2008
|
+
return false;
|
|
2009
|
+
}
|
|
2010
|
+
} else if (!this.options.flex) {
|
|
2011
|
+
break;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
if (match) {
|
|
2016
|
+
token = this.test_match(match, rules[index]);
|
|
2017
|
+
if (token !== false) {
|
|
2018
|
+
return token;
|
|
2019
|
+
}
|
|
2020
|
+
return false;
|
|
2021
|
+
}
|
|
2022
|
+
if (this._input === "") {
|
|
2023
|
+
return this.EOF;
|
|
2024
|
+
} else {
|
|
2025
|
+
return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
|
|
2026
|
+
text: "",
|
|
2027
|
+
token: null,
|
|
2028
|
+
line: this.yylineno
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
}, "next"),
|
|
2032
|
+
// return next match that has a token
|
|
2033
|
+
lex: /* @__PURE__ */ __name(function lex() {
|
|
2034
|
+
var r = this.next();
|
|
2035
|
+
if (r) {
|
|
2036
|
+
return r;
|
|
2037
|
+
} else {
|
|
2038
|
+
return this.lex();
|
|
2039
|
+
}
|
|
2040
|
+
}, "lex"),
|
|
2041
|
+
// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
|
|
2042
|
+
begin: /* @__PURE__ */ __name(function begin(condition) {
|
|
2043
|
+
this.conditionStack.push(condition);
|
|
2044
|
+
}, "begin"),
|
|
2045
|
+
// pop the previously active lexer condition state off the condition stack
|
|
2046
|
+
popState: /* @__PURE__ */ __name(function popState() {
|
|
2047
|
+
var n = this.conditionStack.length - 1;
|
|
2048
|
+
if (n > 0) {
|
|
2049
|
+
return this.conditionStack.pop();
|
|
2050
|
+
} else {
|
|
2051
|
+
return this.conditionStack[0];
|
|
2052
|
+
}
|
|
2053
|
+
}, "popState"),
|
|
2054
|
+
// produce the lexer rule set which is active for the currently active lexer condition state
|
|
2055
|
+
_currentRules: /* @__PURE__ */ __name(function _currentRules() {
|
|
2056
|
+
if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
|
|
2057
|
+
return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
|
|
2058
|
+
} else {
|
|
2059
|
+
return this.conditions["INITIAL"].rules;
|
|
2060
|
+
}
|
|
2061
|
+
}, "_currentRules"),
|
|
2062
|
+
// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
|
|
2063
|
+
topState: /* @__PURE__ */ __name(function topState(n) {
|
|
2064
|
+
n = this.conditionStack.length - 1 - Math.abs(n || 0);
|
|
2065
|
+
if (n >= 0) {
|
|
2066
|
+
return this.conditionStack[n];
|
|
2067
|
+
} else {
|
|
2068
|
+
return "INITIAL";
|
|
2069
|
+
}
|
|
2070
|
+
}, "topState"),
|
|
2071
|
+
// alias for begin(condition)
|
|
2072
|
+
pushState: /* @__PURE__ */ __name(function pushState(condition) {
|
|
2073
|
+
this.begin(condition);
|
|
2074
|
+
}, "pushState"),
|
|
2075
|
+
// return the number of states currently on the stack
|
|
2076
|
+
stateStackSize: /* @__PURE__ */ __name(function stateStackSize() {
|
|
2077
|
+
return this.conditionStack.length;
|
|
2078
|
+
}, "stateStackSize"),
|
|
2079
|
+
options: { "case-insensitive": true },
|
|
2080
|
+
performAction: /* @__PURE__ */ __name(function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
|
|
2081
|
+
var YYSTATE = YY_START;
|
|
2082
|
+
switch ($avoiding_name_collisions) {
|
|
2083
|
+
case 0:
|
|
2084
|
+
break;
|
|
2085
|
+
case 1:
|
|
2086
|
+
break;
|
|
2087
|
+
case 2:
|
|
2088
|
+
break;
|
|
2089
|
+
case 3:
|
|
2090
|
+
if (yy.getIndentMode && yy.getIndentMode()) {
|
|
2091
|
+
yy.consumeIndentText = true;
|
|
2092
|
+
this.begin("INITIAL");
|
|
2093
|
+
return 22;
|
|
2094
|
+
}
|
|
2095
|
+
break;
|
|
2096
|
+
case 4:
|
|
2097
|
+
break;
|
|
2098
|
+
case 5:
|
|
2099
|
+
if (yy.setIndentMode) {
|
|
2100
|
+
yy.setIndentMode(false);
|
|
2101
|
+
}
|
|
2102
|
+
this.begin("INITIAL");
|
|
2103
|
+
this.unput(yy_.yytext);
|
|
2104
|
+
break;
|
|
2105
|
+
case 6:
|
|
2106
|
+
this.begin("bol");
|
|
2107
|
+
return 8;
|
|
2108
|
+
break;
|
|
2109
|
+
case 7:
|
|
2110
|
+
break;
|
|
2111
|
+
case 8:
|
|
2112
|
+
break;
|
|
2113
|
+
case 9:
|
|
2114
|
+
return 7;
|
|
2115
|
+
break;
|
|
2116
|
+
case 10:
|
|
2117
|
+
return 11;
|
|
2118
|
+
break;
|
|
2119
|
+
case 11:
|
|
2120
|
+
return 5;
|
|
2121
|
+
break;
|
|
2122
|
+
case 12:
|
|
2123
|
+
return 12;
|
|
2124
|
+
break;
|
|
2125
|
+
case 13:
|
|
2126
|
+
return 17;
|
|
2127
|
+
break;
|
|
2128
|
+
case 14:
|
|
2129
|
+
if (yy.consumeIndentText) {
|
|
2130
|
+
yy.consumeIndentText = false;
|
|
2131
|
+
} else {
|
|
2132
|
+
return 19;
|
|
2133
|
+
}
|
|
2134
|
+
break;
|
|
2135
|
+
case 15:
|
|
2136
|
+
return 24;
|
|
2137
|
+
break;
|
|
2138
|
+
case 16:
|
|
2139
|
+
yy_.yytext = yy_.yytext.slice(2, -2);
|
|
2140
|
+
return 14;
|
|
2141
|
+
break;
|
|
2142
|
+
case 17:
|
|
2143
|
+
yy_.yytext = yy_.yytext.slice(1, -1).trim();
|
|
2144
|
+
return 14;
|
|
2145
|
+
break;
|
|
2146
|
+
case 18:
|
|
2147
|
+
return 16;
|
|
2148
|
+
break;
|
|
2149
|
+
case 19:
|
|
2150
|
+
return 31;
|
|
2151
|
+
break;
|
|
2152
|
+
case 20:
|
|
2153
|
+
return 33;
|
|
2154
|
+
break;
|
|
2155
|
+
case 21:
|
|
2156
|
+
return 32;
|
|
2157
|
+
break;
|
|
2158
|
+
case 22:
|
|
2159
|
+
return 20;
|
|
2160
|
+
break;
|
|
2161
|
+
case 23:
|
|
2162
|
+
return 21;
|
|
2163
|
+
break;
|
|
2164
|
+
case 24:
|
|
2165
|
+
return 27;
|
|
2166
|
+
break;
|
|
2167
|
+
case 25:
|
|
2168
|
+
return 15;
|
|
2169
|
+
break;
|
|
2170
|
+
}
|
|
2171
|
+
}, "anonymous"),
|
|
2172
|
+
rules: [/^(?:%%(?!\{)[^\n]*)/i, /^(?:[^\}]%%[^\n]*)/i, /^(?:[ \t]+(?=[\n\r]))/i, /^(?:[ \t]+(?=text\b))/i, /^(?:[ \t]+)/i, /^(?:[^ \t\n\r])/i, /^(?:[\n\r]+)/i, /^(?:%%[^\n]*)/i, /^(?:[ \t]+)/i, /^(?:$)/i, /^(?:title\s[^#\n;]+)/i, /^(?:venn-beta\b)/i, /^(?:set\b)/i, /^(?:union\b)/i, /^(?:text\b)/i, /^(?:style\b)/i, /^(?:\["[^\"]*"\])/i, /^(?:\[[^\]\"]+\])/i, /^(?:[+-]?(\d+(\.\d+)?|\.\d+))/i, /^(?:#[0-9a-fA-F]{3,8})/i, /^(?:rgba\(\s*[0-9.]+\s*[,]\s*[0-9.]+\s*[,]\s*[0-9.]+\s*[,]\s*[0-9.]+\s*\))/i, /^(?:rgb\(\s*[0-9.]+\s*[,]\s*[0-9.]+\s*[,]\s*[0-9.]+\s*\))/i, /^(?:[A-Za-z_][A-Za-z0-9\-_]*)/i, /^(?:"[^\"]*")/i, /^(?:,)/i, /^(?::)/i],
|
|
2173
|
+
conditions: { "bol": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], "inclusive": true }, "INITIAL": { "rules": [0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], "inclusive": true } }
|
|
2174
|
+
};
|
|
2175
|
+
return lexer2;
|
|
2176
|
+
}();
|
|
2177
|
+
parser2.lexer = lexer;
|
|
2178
|
+
function Parser() {
|
|
2179
|
+
this.yy = {};
|
|
2180
|
+
}
|
|
2181
|
+
__name(Parser, "Parser");
|
|
2182
|
+
Parser.prototype = parser2;
|
|
2183
|
+
parser2.Parser = Parser;
|
|
2184
|
+
return new Parser();
|
|
2185
|
+
}();
|
|
2186
|
+
parser.parser = parser;
|
|
2187
|
+
var venn_default = parser;
|
|
2188
|
+
var subsets = [];
|
|
2189
|
+
var textNodes = [];
|
|
2190
|
+
var styleEntries = [];
|
|
2191
|
+
var knownSets = /* @__PURE__ */ new Set();
|
|
2192
|
+
var currentSets;
|
|
2193
|
+
var indentMode = false;
|
|
2194
|
+
var addSubsetData = /* @__PURE__ */ __name((identifierList, label, size) => {
|
|
2195
|
+
const sets = normalizeIdentifierList(identifierList).sort();
|
|
2196
|
+
const resolvedSize = size ?? 10 / Math.pow(identifierList.length, 2);
|
|
2197
|
+
currentSets = sets;
|
|
2198
|
+
if (sets.length === 1) {
|
|
2199
|
+
knownSets.add(sets[0]);
|
|
2200
|
+
}
|
|
2201
|
+
subsets.push({
|
|
2202
|
+
sets,
|
|
2203
|
+
size: resolvedSize,
|
|
2204
|
+
label: label ? normalizeText(label) : void 0
|
|
2205
|
+
});
|
|
2206
|
+
}, "addSubsetData");
|
|
2207
|
+
var getSubsetData = /* @__PURE__ */ __name(() => {
|
|
2208
|
+
return subsets;
|
|
2209
|
+
}, "getSubsetData");
|
|
2210
|
+
var normalizeText = /* @__PURE__ */ __name((text) => {
|
|
2211
|
+
const trimmed = text.trim();
|
|
2212
|
+
if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
2213
|
+
return trimmed.slice(1, -1);
|
|
2214
|
+
}
|
|
2215
|
+
return trimmed;
|
|
2216
|
+
}, "normalizeText");
|
|
2217
|
+
var normalizeStyleValue = /* @__PURE__ */ __name((value) => {
|
|
2218
|
+
return value ? normalizeText(value) : value;
|
|
2219
|
+
}, "normalizeStyleValue");
|
|
2220
|
+
var addTextData = /* @__PURE__ */ __name((identifierList, id, label) => {
|
|
2221
|
+
const normalizedId = normalizeText(id);
|
|
2222
|
+
textNodes.push({
|
|
2223
|
+
sets: normalizeIdentifierList(identifierList).sort(),
|
|
2224
|
+
id: normalizedId,
|
|
2225
|
+
label: label ? normalizeText(label) : void 0
|
|
2226
|
+
});
|
|
2227
|
+
}, "addTextData");
|
|
2228
|
+
var addStyleData = /* @__PURE__ */ __name((identifierList, data) => {
|
|
2229
|
+
const targets = normalizeIdentifierList(identifierList).sort();
|
|
2230
|
+
const styles = {};
|
|
2231
|
+
for (const [key, value] of data) {
|
|
2232
|
+
styles[key] = normalizeStyleValue(value) ?? value;
|
|
2233
|
+
}
|
|
2234
|
+
styleEntries.push({ targets, styles });
|
|
2235
|
+
}, "addStyleData");
|
|
2236
|
+
var getStyleData = /* @__PURE__ */ __name(() => {
|
|
2237
|
+
return styleEntries;
|
|
2238
|
+
}, "getStyleData");
|
|
2239
|
+
var normalizeIdentifierList = /* @__PURE__ */ __name((identifierList) => {
|
|
2240
|
+
return identifierList.map((identifier) => normalizeText(identifier));
|
|
2241
|
+
}, "normalizeIdentifierList");
|
|
2242
|
+
var validateUnionIdentifiers = /* @__PURE__ */ __name((identifierList) => {
|
|
2243
|
+
const normalized = normalizeIdentifierList(identifierList);
|
|
2244
|
+
const unknown = normalized.filter((identifier) => !knownSets.has(identifier));
|
|
2245
|
+
if (unknown.length > 0) {
|
|
2246
|
+
throw new Error(`unknown set identifier: ${unknown.join(", ")}`);
|
|
2247
|
+
}
|
|
2248
|
+
}, "validateUnionIdentifiers");
|
|
2249
|
+
var getTextData = /* @__PURE__ */ __name(() => {
|
|
2250
|
+
return textNodes;
|
|
2251
|
+
}, "getTextData");
|
|
2252
|
+
var getCurrentSets = /* @__PURE__ */ __name(() => currentSets, "getCurrentSets");
|
|
2253
|
+
var getIndentMode = /* @__PURE__ */ __name(() => indentMode, "getIndentMode");
|
|
2254
|
+
var setIndentMode = /* @__PURE__ */ __name((enabled) => {
|
|
2255
|
+
indentMode = enabled;
|
|
2256
|
+
}, "setIndentMode");
|
|
2257
|
+
var DEFAULT_VENN_CONFIG = defaultConfig_default.venn;
|
|
2258
|
+
function getConfig2() {
|
|
2259
|
+
return cleanAndMerge(DEFAULT_VENN_CONFIG, getConfig().venn);
|
|
2260
|
+
}
|
|
2261
|
+
__name(getConfig2, "getConfig");
|
|
2262
|
+
var customClear = /* @__PURE__ */ __name(() => {
|
|
2263
|
+
clear();
|
|
2264
|
+
subsets.length = 0;
|
|
2265
|
+
textNodes.length = 0;
|
|
2266
|
+
styleEntries.length = 0;
|
|
2267
|
+
knownSets.clear();
|
|
2268
|
+
currentSets = void 0;
|
|
2269
|
+
indentMode = false;
|
|
2270
|
+
}, "customClear");
|
|
2271
|
+
var db = {
|
|
2272
|
+
getConfig: getConfig2,
|
|
2273
|
+
clear: customClear,
|
|
2274
|
+
setAccTitle,
|
|
2275
|
+
getAccTitle,
|
|
2276
|
+
setDiagramTitle,
|
|
2277
|
+
getDiagramTitle,
|
|
2278
|
+
getAccDescription,
|
|
2279
|
+
setAccDescription,
|
|
2280
|
+
addSubsetData,
|
|
2281
|
+
getSubsetData,
|
|
2282
|
+
addTextData,
|
|
2283
|
+
addStyleData,
|
|
2284
|
+
validateUnionIdentifiers,
|
|
2285
|
+
getTextData,
|
|
2286
|
+
getStyleData,
|
|
2287
|
+
getCurrentSets,
|
|
2288
|
+
getIndentMode,
|
|
2289
|
+
setIndentMode
|
|
2290
|
+
};
|
|
2291
|
+
var getStyles = /* @__PURE__ */ __name((options) => `
|
|
2292
|
+
.venn-title {
|
|
2293
|
+
font-size: 32px;
|
|
2294
|
+
fill: ${options.vennTitleTextColor};
|
|
2295
|
+
font-family: ${options.fontFamily};
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
.venn-circle text {
|
|
2299
|
+
font-size: 48px;
|
|
2300
|
+
font-family: ${options.fontFamily};
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
.venn-intersection text {
|
|
2304
|
+
font-size: 48px;
|
|
2305
|
+
fill: ${options.vennSetTextColor};
|
|
2306
|
+
font-family: ${options.fontFamily};
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
.venn-text-node {
|
|
2310
|
+
font-family: ${options.fontFamily};
|
|
2311
|
+
color: ${options.vennSetTextColor};
|
|
2312
|
+
}
|
|
2313
|
+
`, "getStyles");
|
|
2314
|
+
var styles_default = getStyles;
|
|
2315
|
+
function buildStyleByKey(styleData) {
|
|
2316
|
+
const map = /* @__PURE__ */ new Map();
|
|
2317
|
+
for (const entry of styleData) {
|
|
2318
|
+
const key = entry.targets.join("|");
|
|
2319
|
+
const existing = map.get(key);
|
|
2320
|
+
if (existing) {
|
|
2321
|
+
Object.assign(existing, entry.styles);
|
|
2322
|
+
} else {
|
|
2323
|
+
map.set(key, { ...entry.styles });
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
return map;
|
|
2327
|
+
}
|
|
2328
|
+
__name(buildStyleByKey, "buildStyleByKey");
|
|
2329
|
+
var draw = /* @__PURE__ */ __name((_text, id, _version, diagObj) => {
|
|
2330
|
+
const db2 = diagObj.db;
|
|
2331
|
+
const config = db2.getConfig?.();
|
|
2332
|
+
const { themeVariables, look, handDrawnSeed } = getConfig();
|
|
2333
|
+
const isHandDrawn = look === "handDrawn";
|
|
2334
|
+
const themeColors = [
|
|
2335
|
+
themeVariables.venn1,
|
|
2336
|
+
themeVariables.venn2,
|
|
2337
|
+
themeVariables.venn3,
|
|
2338
|
+
themeVariables.venn4,
|
|
2339
|
+
themeVariables.venn5,
|
|
2340
|
+
themeVariables.venn6,
|
|
2341
|
+
themeVariables.venn7,
|
|
2342
|
+
themeVariables.venn8
|
|
2343
|
+
].filter(Boolean);
|
|
2344
|
+
const title = db2.getDiagramTitle?.();
|
|
2345
|
+
const sets = db2.getSubsetData();
|
|
2346
|
+
const textNodes2 = db2.getTextData();
|
|
2347
|
+
const styleByKey = buildStyleByKey(db2.getStyleData());
|
|
2348
|
+
const svgWidth = config?.width ?? 800;
|
|
2349
|
+
const svgHeight = config?.height ?? 450;
|
|
2350
|
+
const REFERENCE_WIDTH = 1600;
|
|
2351
|
+
const scale2 = svgWidth / REFERENCE_WIDTH;
|
|
2352
|
+
const titleHeight = title ? 48 * scale2 : 0;
|
|
2353
|
+
const defaultTextColor = themeVariables.primaryTextColor ?? themeVariables.textColor;
|
|
2354
|
+
const svg = selectSvgElement(id);
|
|
2355
|
+
svg.attr("viewBox", `0 0 ${svgWidth} ${svgHeight}`);
|
|
2356
|
+
if (title) {
|
|
2357
|
+
svg.append("text").text(title).attr("class", "venn-title").attr("font-size", `${32 * scale2}px`).attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("x", "50%").attr("y", 32 * scale2).style("fill", themeVariables.vennTitleTextColor || themeVariables.titleColor);
|
|
2358
|
+
}
|
|
2359
|
+
const dummyD3root = select_default(document.createElement("div"));
|
|
2360
|
+
const vennDiagram = VennDiagram().width(svgWidth).height(svgHeight - titleHeight);
|
|
2361
|
+
dummyD3root.datum(sets).call(vennDiagram);
|
|
2362
|
+
const roughSvg = isHandDrawn ? at.svg(dummyD3root.select("svg").node()) : void 0;
|
|
2363
|
+
const layoutAreas = layout(sets, {
|
|
2364
|
+
width: svgWidth,
|
|
2365
|
+
height: svgHeight - titleHeight,
|
|
2366
|
+
padding: config?.padding ?? 15
|
|
2367
|
+
});
|
|
2368
|
+
const layoutByKey = /* @__PURE__ */ new Map();
|
|
2369
|
+
for (const area of layoutAreas) {
|
|
2370
|
+
const key = stableSetsKey([...area.data.sets].sort());
|
|
2371
|
+
layoutByKey.set(key, area);
|
|
2372
|
+
}
|
|
2373
|
+
if (textNodes2.length > 0) {
|
|
2374
|
+
renderTextNodes(config, layoutByKey, dummyD3root, textNodes2, scale2, styleByKey);
|
|
2375
|
+
}
|
|
2376
|
+
const themeDark = is_dark_default(themeVariables.background || "#f4f4f4");
|
|
2377
|
+
dummyD3root.selectAll(".venn-circle").each(function(d, i) {
|
|
2378
|
+
const group = select_default(this);
|
|
2379
|
+
const data = d;
|
|
2380
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2381
|
+
const customStyle = styleByKey.get(setsKey);
|
|
2382
|
+
const baseColor = customStyle?.fill || themeColors[i % themeColors.length] || themeVariables.primaryColor;
|
|
2383
|
+
group.classed(`venn-set-${i % 8}`, true);
|
|
2384
|
+
const fillOpacity = customStyle?.["fill-opacity"] ?? 0.1;
|
|
2385
|
+
const strokeColor = customStyle?.stroke || baseColor;
|
|
2386
|
+
const strokeWidthVal = customStyle?.["stroke-width"] || `${5 * scale2}`;
|
|
2387
|
+
if (isHandDrawn && roughSvg) {
|
|
2388
|
+
const layoutArea = layoutByKey.get(setsKey);
|
|
2389
|
+
if (layoutArea && layoutArea.circles.length > 0) {
|
|
2390
|
+
const c = layoutArea.circles[0];
|
|
2391
|
+
const roughNode = roughSvg.circle(c.x, c.y, c.radius * 2, {
|
|
2392
|
+
roughness: 0.7,
|
|
2393
|
+
seed: handDrawnSeed,
|
|
2394
|
+
fill: transparentize_default(baseColor, 0.7),
|
|
2395
|
+
fillStyle: "hachure",
|
|
2396
|
+
fillWeight: 2,
|
|
2397
|
+
hachureGap: 8,
|
|
2398
|
+
hachureAngle: -41 + i * 60,
|
|
2399
|
+
stroke: strokeColor,
|
|
2400
|
+
strokeWidth: parseFloat(String(strokeWidthVal))
|
|
2401
|
+
});
|
|
2402
|
+
group.select("path").remove();
|
|
2403
|
+
group.node()?.insertBefore(roughNode, group.select("text").node());
|
|
2404
|
+
}
|
|
2405
|
+
} else {
|
|
2406
|
+
group.select("path").style("fill", baseColor).style("fill-opacity", fillOpacity).style("stroke", strokeColor).style("stroke-width", strokeWidthVal).style("stroke-opacity", 0.95);
|
|
2407
|
+
}
|
|
2408
|
+
const textColor = customStyle?.color || (themeDark ? lighten_default(baseColor, 30) : darken_default(baseColor, 30));
|
|
2409
|
+
group.select("text").style("font-size", `${48 * scale2}px`).style("fill", textColor);
|
|
2410
|
+
});
|
|
2411
|
+
if (isHandDrawn && roughSvg) {
|
|
2412
|
+
dummyD3root.selectAll(".venn-intersection").each(function(d) {
|
|
2413
|
+
const group = select_default(this);
|
|
2414
|
+
const data = d;
|
|
2415
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2416
|
+
const customStyle = styleByKey.get(setsKey);
|
|
2417
|
+
const customFill = customStyle?.fill;
|
|
2418
|
+
if (customFill) {
|
|
2419
|
+
const pathEl = group.select("path");
|
|
2420
|
+
const pathD = pathEl.attr("d");
|
|
2421
|
+
if (pathD) {
|
|
2422
|
+
const roughNode = roughSvg.path(pathD, {
|
|
2423
|
+
roughness: 0.7,
|
|
2424
|
+
seed: handDrawnSeed,
|
|
2425
|
+
fill: transparentize_default(customFill, 0.3),
|
|
2426
|
+
fillStyle: "cross-hatch",
|
|
2427
|
+
fillWeight: 2,
|
|
2428
|
+
hachureGap: 6,
|
|
2429
|
+
hachureAngle: 60,
|
|
2430
|
+
stroke: "none"
|
|
2431
|
+
});
|
|
2432
|
+
const existingPath = pathEl.node();
|
|
2433
|
+
existingPath?.parentNode?.insertBefore(roughNode, existingPath);
|
|
2434
|
+
pathEl.remove();
|
|
2435
|
+
}
|
|
2436
|
+
} else {
|
|
2437
|
+
group.select("path").style("fill-opacity", 0);
|
|
2438
|
+
}
|
|
2439
|
+
group.select("text").style("font-size", `${48 * scale2}px`).style("fill", customStyle?.color ?? themeVariables.vennSetTextColor ?? defaultTextColor);
|
|
2440
|
+
});
|
|
2441
|
+
} else {
|
|
2442
|
+
dummyD3root.selectAll(".venn-intersection text").style("font-size", `${48 * scale2}px`).style("fill", (e) => {
|
|
2443
|
+
const data = e;
|
|
2444
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2445
|
+
return styleByKey.get(setsKey)?.color ?? themeVariables.vennSetTextColor ?? defaultTextColor;
|
|
2446
|
+
});
|
|
2447
|
+
dummyD3root.selectAll(".venn-intersection path").style("fill-opacity", (e) => {
|
|
2448
|
+
const data = e;
|
|
2449
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2450
|
+
return styleByKey.get(setsKey)?.fill ? 1 : 0;
|
|
2451
|
+
}).style("fill", (e) => {
|
|
2452
|
+
const data = e;
|
|
2453
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2454
|
+
return styleByKey.get(setsKey)?.fill ?? "transparent";
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
const vennGroup = svg.append("g").attr("transform", `translate(0, ${titleHeight})`);
|
|
2458
|
+
const dummySvg = dummyD3root.select("svg").node();
|
|
2459
|
+
if (dummySvg && "childNodes" in dummySvg) {
|
|
2460
|
+
for (const child of [...dummySvg.childNodes]) {
|
|
2461
|
+
vennGroup.node()?.appendChild(child);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
configureSvgSize(svg, svgHeight, svgWidth, config?.useMaxWidth ?? true);
|
|
2465
|
+
}, "draw");
|
|
2466
|
+
function stableSetsKey(setIds) {
|
|
2467
|
+
return setIds.join("|");
|
|
2468
|
+
}
|
|
2469
|
+
__name(stableSetsKey, "stableSetsKey");
|
|
2470
|
+
function renderTextNodes(config, layoutByKey, dummyD3root, textNodes2, scale2, styleByKey) {
|
|
2471
|
+
const useDebugLayout = config?.useDebugLayout ?? false;
|
|
2472
|
+
const vennSvg = dummyD3root.select("svg");
|
|
2473
|
+
const textGroup = vennSvg.append("g").attr("class", "venn-text-nodes");
|
|
2474
|
+
const nodesByArea = /* @__PURE__ */ new Map();
|
|
2475
|
+
for (const node of textNodes2) {
|
|
2476
|
+
const key = stableSetsKey(node.sets);
|
|
2477
|
+
const existing = nodesByArea.get(key);
|
|
2478
|
+
if (existing) {
|
|
2479
|
+
existing.push(node);
|
|
2480
|
+
} else {
|
|
2481
|
+
nodesByArea.set(key, [node]);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
for (const [key, nodes] of nodesByArea.entries()) {
|
|
2485
|
+
const area = layoutByKey.get(key);
|
|
2486
|
+
if (!area?.text) {
|
|
2487
|
+
continue;
|
|
2488
|
+
}
|
|
2489
|
+
const centerX = area.text.x;
|
|
2490
|
+
const centerY = area.text.y;
|
|
2491
|
+
const minCircleRadius = Math.min(...area.circles.map((c) => c.radius));
|
|
2492
|
+
const innerRadiusRaw = Math.min(
|
|
2493
|
+
...area.circles.map((c) => c.radius - Math.hypot(centerX - c.x, centerY - c.y))
|
|
2494
|
+
);
|
|
2495
|
+
let innerRadius = Number.isFinite(innerRadiusRaw) ? Math.max(0, innerRadiusRaw) : 0;
|
|
2496
|
+
if (innerRadius === 0 && Number.isFinite(minCircleRadius)) {
|
|
2497
|
+
innerRadius = minCircleRadius * 0.6;
|
|
2498
|
+
}
|
|
2499
|
+
const areaGroup = textGroup.append("g").attr("class", "venn-text-area").attr("font-size", `${40 * scale2}px`);
|
|
2500
|
+
if (useDebugLayout) {
|
|
2501
|
+
areaGroup.append("circle").attr("class", "venn-text-debug-circle").attr("cx", centerX).attr("cy", centerY).attr("r", innerRadius).attr("fill", "none").attr("stroke", "purple").attr("stroke-width", 1.5 * scale2).attr("stroke-dasharray", `${6 * scale2} ${4 * scale2}`);
|
|
2502
|
+
}
|
|
2503
|
+
const innerWidth = Math.max(80 * scale2, innerRadius * 2 * 0.95);
|
|
2504
|
+
const innerHeight = Math.max(60 * scale2, innerRadius * 2 * 0.95);
|
|
2505
|
+
const hasLabel = area.data.label && area.data.label.length > 0;
|
|
2506
|
+
const labelOffsetBase = hasLabel ? Math.min(32 * scale2, innerRadius * 0.25) : 0;
|
|
2507
|
+
const labelOffset = labelOffsetBase + (nodes.length <= 2 ? 30 * scale2 : 0);
|
|
2508
|
+
const startX = centerX - innerWidth / 2;
|
|
2509
|
+
const startY = centerY - innerHeight / 2 + labelOffset;
|
|
2510
|
+
const cols = Math.max(1, Math.ceil(Math.sqrt(nodes.length)));
|
|
2511
|
+
const rows = Math.max(1, Math.ceil(nodes.length / cols));
|
|
2512
|
+
const cellWidth = innerWidth / cols;
|
|
2513
|
+
const cellHeight = innerHeight / rows;
|
|
2514
|
+
for (const [i, node] of nodes.entries()) {
|
|
2515
|
+
const col = i % cols;
|
|
2516
|
+
const row = Math.floor(i / cols);
|
|
2517
|
+
const x = startX + cellWidth * (col + 0.5);
|
|
2518
|
+
const y = startY + cellHeight * (row + 0.5);
|
|
2519
|
+
if (useDebugLayout) {
|
|
2520
|
+
areaGroup.append("rect").attr("class", "venn-text-debug-cell").attr("x", startX + cellWidth * col).attr("y", startY + cellHeight * row).attr("width", cellWidth).attr("height", cellHeight).attr("fill", "none").attr("stroke", "teal").attr("stroke-width", 1 * scale2).attr("stroke-dasharray", `${4 * scale2} ${3 * scale2}`);
|
|
2521
|
+
}
|
|
2522
|
+
const boxWidth = cellWidth * 0.9;
|
|
2523
|
+
const boxHeight = cellHeight * 0.9;
|
|
2524
|
+
const container = areaGroup.append("foreignObject").attr("class", "venn-text-node-fo").attr("width", boxWidth).attr("height", boxHeight).attr("x", x - boxWidth / 2).attr("y", y - boxHeight / 2).attr("overflow", "visible");
|
|
2525
|
+
const textColor = styleByKey.get(node.id)?.color;
|
|
2526
|
+
const text = container.append("xhtml:span").attr("class", "venn-text-node").style("display", "flex").style("width", "100%").style("height", "100%").style("white-space", "normal").style("align-items", "center").style("justify-content", "center").style("text-align", "center").style("overflow-wrap", "normal").style("word-break", "normal").text(node.label ?? node.id);
|
|
2527
|
+
if (textColor) {
|
|
2528
|
+
text.style("color", textColor);
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
__name(renderTextNodes, "renderTextNodes");
|
|
2534
|
+
var renderer = { draw };
|
|
2535
|
+
var diagram = {
|
|
2536
|
+
parser: venn_default,
|
|
2537
|
+
db,
|
|
2538
|
+
renderer,
|
|
2539
|
+
styles: styles_default
|
|
2540
|
+
};
|
|
2541
|
+
export {
|
|
2542
|
+
diagram
|
|
2543
|
+
};
|
|
2544
|
+
//# sourceMappingURL=vennDiagram-DHZGUBPP-HEAOEXEZ.js.map
|