@legionworks/facet 1.9.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-APACHE +202 -0
- package/LICENSE-MIT +23 -0
- package/README.md +158 -0
- package/dist/gallery/chunk-4g8rem85.css +656 -0
- package/dist/gallery/chunk-c6s9k9ty.js +5970 -0
- package/dist/gallery/frame/artifact.css +8424 -0
- package/dist/gallery/frame/chunks/abnfDiagram-N423BO3Z-jj74szbm.js +155 -0
- package/dist/gallery/frame/chunks/architecture-TIHT7OUA-cvdjn7dt.js +10 -0
- package/dist/gallery/frame/chunks/architectureDiagram-T3A2C74G-n4z77eg6.js +8675 -0
- package/dist/gallery/frame/chunks/blockDiagram-VBNYF7ZC-7xsqzrd1.js +3529 -0
- package/dist/gallery/frame/chunks/c4Diagram-5PPSVZJV-z2zjs7wx.js +2413 -0
- package/dist/gallery/frame/chunks/classDiagram-JCYQIIEL-ve8rngqp.js +47 -0
- package/dist/gallery/frame/chunks/classDiagram-v2-OCEON4UE-8cfaxb8z.js +47 -0
- package/dist/gallery/frame/chunks/cose-bilkent-JH36ORCC-sn92qexx.js +4822 -0
- package/dist/gallery/frame/chunks/cynefin-VYW2F7L2-tqjv913d.js +10 -0
- package/dist/gallery/frame/chunks/cynefinDiagram-MW4NZA55-c1c0dj12.js +500 -0
- package/dist/gallery/frame/chunks/dagre-VZM6K2ZE-7tyg4yt2.js +476 -0
- package/dist/gallery/frame/chunks/diagram-7IWD3JNH-y4eng9sc.js +526 -0
- package/dist/gallery/frame/chunks/diagram-B4RE2ZJO-rn3p7j5h.js +673 -0
- package/dist/gallery/frame/chunks/diagram-LBJQPF4R-w4a2cm9q.js +255 -0
- package/dist/gallery/frame/chunks/diagram-Q27KOJAE-aqc2v7wy.js +575 -0
- package/dist/gallery/frame/chunks/diagram-UB23O5K3-xncy8nyd.js +355 -0
- package/dist/gallery/frame/chunks/ebnfDiagram-BXEA7PRR-acwgxz16.js +175 -0
- package/dist/gallery/frame/chunks/erDiagram-JOGREHBK-mzp5nswt.js +1332 -0
- package/dist/gallery/frame/chunks/eventmodeling-45OFAUF4-sg07qr0c.js +10 -0
- package/dist/gallery/frame/chunks/flowDiagram-UKHOOZJN-2e5ygs44.js +29 -0
- package/dist/gallery/frame/chunks/ganttDiagram-PKOTCBZU-p2hhh7hr.js +2620 -0
- package/dist/gallery/frame/chunks/gitGraph-TEB2WS4Q-j6kw0naa.js +10 -0
- package/dist/gallery/frame/chunks/gitGraphDiagram-DS77QQ5N-4z9z8wjm.js +1347 -0
- package/dist/gallery/frame/chunks/info-DKCQHKI2-mpt80jd3.js +10 -0
- package/dist/gallery/frame/chunks/infoDiagram-6WML65LV-5rqm3mgg.js +65 -0
- package/dist/gallery/frame/chunks/ishikawaDiagram-WSZJBQD7-b51z96jy.js +975 -0
- package/dist/gallery/frame/chunks/journeyDiagram-NVQOT4AX-9jbfp0pk.js +1272 -0
- package/dist/gallery/frame/chunks/kanban-definition-27J2QSJJ-4x0vx4se.js +1116 -0
- package/dist/gallery/frame/chunks/katex-xfgk95tv.js +14034 -0
- package/dist/gallery/frame/chunks/markdown-1s5vwkf2.js +9 -0
- package/dist/gallery/frame/chunks/markdown-2h6bwsms.js +3239 -0
- package/dist/gallery/frame/chunks/markdown-2x113yh8.js +107 -0
- package/dist/gallery/frame/chunks/markdown-30b7rwmp.js +1943 -0
- package/dist/gallery/frame/chunks/markdown-356bfj4g.js +2031 -0
- package/dist/gallery/frame/chunks/markdown-44n9ea69.js +2406 -0
- package/dist/gallery/frame/chunks/markdown-56enrf2r.js +39 -0
- package/dist/gallery/frame/chunks/markdown-5avymm8t.js +725 -0
- package/dist/gallery/frame/chunks/markdown-6r4svars.js +33 -0
- package/dist/gallery/frame/chunks/markdown-6zz8efx2.js +24 -0
- package/dist/gallery/frame/chunks/markdown-7jp6prnb.js +19 -0
- package/dist/gallery/frame/chunks/markdown-809k7q41.js +55 -0
- package/dist/gallery/frame/chunks/markdown-82xmzhzd.js +1076 -0
- package/dist/gallery/frame/chunks/markdown-92n37gd4.js +7627 -0
- package/dist/gallery/frame/chunks/markdown-ag2sssf8.js +36 -0
- package/dist/gallery/frame/chunks/markdown-b4s7ntq2.js +19 -0
- package/dist/gallery/frame/chunks/markdown-c9k0fvp1.js +100 -0
- package/dist/gallery/frame/chunks/markdown-ceefymn8.js +125 -0
- package/dist/gallery/frame/chunks/markdown-d1wfbs70.js +243 -0
- package/dist/gallery/frame/chunks/markdown-dy5sgjhc.js +11022 -0
- package/dist/gallery/frame/chunks/markdown-dz3z5w30.js +30868 -0
- package/dist/gallery/frame/chunks/markdown-eg6ngz7y.js +30340 -0
- package/dist/gallery/frame/chunks/markdown-ff5wvb43.js +1149 -0
- package/dist/gallery/frame/chunks/markdown-ffg06nfz.js +86 -0
- package/dist/gallery/frame/chunks/markdown-fvfncadf.js +472 -0
- package/dist/gallery/frame/chunks/markdown-gvyszqpv.js +19 -0
- package/dist/gallery/frame/chunks/markdown-gx1p0ew0.js +88 -0
- package/dist/gallery/frame/chunks/markdown-gxye5frz.js +65 -0
- package/dist/gallery/frame/chunks/markdown-h7pzv34e.js +105 -0
- package/dist/gallery/frame/chunks/markdown-hab789t9.js +47 -0
- package/dist/gallery/frame/chunks/markdown-hjp6sj8t.js +125 -0
- package/dist/gallery/frame/chunks/markdown-jka64qgp.js +1993 -0
- package/dist/gallery/frame/chunks/markdown-k8xkn8mw.js +56 -0
- package/dist/gallery/frame/chunks/markdown-m7frq8x8.js +112 -0
- package/dist/gallery/frame/chunks/markdown-p740v4qm.js +36 -0
- package/dist/gallery/frame/chunks/markdown-pxfeh231.js +57 -0
- package/dist/gallery/frame/chunks/markdown-pzgd8z3s.js +87 -0
- package/dist/gallery/frame/chunks/markdown-qx3cngz2.js +1673 -0
- package/dist/gallery/frame/chunks/markdown-rawhfvvc.js +85 -0
- package/dist/gallery/frame/chunks/markdown-rd8w0ng9.js +49 -0
- package/dist/gallery/frame/chunks/markdown-rm2yxfjj.js +2773 -0
- package/dist/gallery/frame/chunks/markdown-s1jatrnk.js +993 -0
- package/dist/gallery/frame/chunks/markdown-sgfg5vvq.js +59 -0
- package/dist/gallery/frame/chunks/markdown-t4ethv9d.js +409 -0
- package/dist/gallery/frame/chunks/markdown-tnmabqvz.js +36 -0
- package/dist/gallery/frame/chunks/markdown-tvdpppw8.js +5292 -0
- package/dist/gallery/frame/chunks/markdown-v0x27twr.js +22 -0
- package/dist/gallery/frame/chunks/markdown-v14td68x.js +36 -0
- package/dist/gallery/frame/chunks/markdown-w6sgd54z.js +36 -0
- package/dist/gallery/frame/chunks/markdown-xw8dsk8b.js +2125 -0
- package/dist/gallery/frame/chunks/markdown-y18mve73.js +85 -0
- package/dist/gallery/frame/chunks/markdown-yengsms5.js +427 -0
- package/dist/gallery/frame/chunks/markdown-z1wc0v0d.js +1826 -0
- package/dist/gallery/frame/chunks/markdown-zazx9h4n.js +329 -0
- package/dist/gallery/frame/chunks/mermaid-de7p4v0x.js +30 -0
- package/dist/gallery/frame/chunks/mindmap-definition-FAOFIHXS-ra44cbem.js +1216 -0
- package/dist/gallery/frame/chunks/packet-7NZHBO7P-xppm5913.js +10 -0
- package/dist/gallery/frame/chunks/pegDiagram-VL7TDLO6-a2a4wg03.js +163 -0
- package/dist/gallery/frame/chunks/pie-RZYD4A2V-hnbxk152.js +10 -0
- package/dist/gallery/frame/chunks/pieDiagram-7S7Q4E2Y-f1vxjtmx.js +311 -0
- package/dist/gallery/frame/chunks/quadrantDiagram-CIZ2JOQS-ywafa6kh.js +1390 -0
- package/dist/gallery/frame/chunks/radar-I7S5WNFK-ewqd27se.js +10 -0
- package/dist/gallery/frame/chunks/railroad-3IZDKUUU-5hy4bdx3.js +10 -0
- package/dist/gallery/frame/chunks/railroad-abnf-AHOZXSZD-bh5sxz0d.js +10 -0
- package/dist/gallery/frame/chunks/railroad-ebnf-EBAXGLYW-6b9c3zeh.js +10 -0
- package/dist/gallery/frame/chunks/railroad-peg-LSFZ7HO6-avc8v39s.js +10 -0
- package/dist/gallery/frame/chunks/railroadDiagram-AXF67PYL-qc61wax4.js +131 -0
- package/dist/gallery/frame/chunks/requirementDiagram-LRYGKXZP-9bs4786c.js +1295 -0
- package/dist/gallery/frame/chunks/sankeyDiagram-W5VNT64P-awt1em8b.js +1339 -0
- package/dist/gallery/frame/chunks/sequenceDiagram-SI44F4Z6-qaf9mz3t.js +4324 -0
- package/dist/gallery/frame/chunks/sizeCapture-X5ZJPWSS-9fq685xd.js +64 -0
- package/dist/gallery/frame/chunks/stateDiagram-OKZ733FA-vx7a7hh0.js +456 -0
- package/dist/gallery/frame/chunks/stateDiagram-v2-UEYNNEHI-x4m6ws5t.js +46 -0
- package/dist/gallery/frame/chunks/swimlanes-SLNWSIFB-e4mxm1gh.js +8287 -0
- package/dist/gallery/frame/chunks/swimlanesDiagram-ULZ7WXOC-0h93e2qq.js +42 -0
- package/dist/gallery/frame/chunks/timeline-definition-Z64GVDOM-wp0bhbzg.js +1549 -0
- package/dist/gallery/frame/chunks/treeView-QDETBFTQ-hcx7n0vt.js +10 -0
- package/dist/gallery/frame/chunks/treemap-6X3UGDF4-av02skdw.js +10 -0
- package/dist/gallery/frame/chunks/vennDiagram-T6HMQDX7-pmvk1p7n.js +2566 -0
- package/dist/gallery/frame/chunks/wardley-OPB4EBWU-njsp6e40.js +10 -0
- package/dist/gallery/frame/chunks/wardleyDiagram-T6FBY63Y-eggmnv4z.js +979 -0
- package/dist/gallery/frame/chunks/xychartDiagram-ELKLHX3M-q40tnpe5.js +1954 -0
- package/dist/gallery/frame/frame.css +183 -0
- package/dist/gallery/frame/runtime/chart.js +42744 -0
- package/dist/gallery/frame/runtime/html.js +14 -0
- package/dist/gallery/frame/runtime/markdown.js +1403 -0
- package/dist/gallery/frame/runtime/mermaid.js +32 -0
- package/dist/gallery/frame/runtime/svg.js +14 -0
- package/dist/gallery/frame/runtime/tsx.js +52 -0
- package/dist/gallery/index.html +104 -0
- package/docs/reference/cli.md +163 -0
- package/docs/reference/export.md +106 -0
- package/docs/reference/html.md +215 -0
- package/docs/reference/http.md +85 -0
- package/docs/reference/mcp.md +78 -0
- package/docs/reference/security.md +119 -0
- package/docs/reference/storage.md +93 -0
- package/docs/reference/tsx.md +101 -0
- package/docs/reference/validation.md +212 -0
- package/package.json +89 -0
- package/scripts/build-gallery.ts +127 -0
- package/scripts/launch-netns.sh +67 -0
- package/skills/facet/SKILL.md +100 -0
- package/src/cli/client.ts +311 -0
- package/src/cli/commands/create.ts +49 -0
- package/src/cli/commands/doctor.ts +249 -0
- package/src/cli/commands/export.ts +179 -0
- package/src/cli/commands/instantiate.ts +35 -0
- package/src/cli/commands/list.ts +49 -0
- package/src/cli/commands/open.ts +75 -0
- package/src/cli/commands/pin.ts +39 -0
- package/src/cli/commands/promote.ts +49 -0
- package/src/cli/commands/publish.ts +122 -0
- package/src/cli/commands/read-back.ts +56 -0
- package/src/cli/commands/status.ts +114 -0
- package/src/cli/commands/watch.ts +146 -0
- package/src/cli/main.ts +522 -0
- package/src/cli/output.ts +106 -0
- package/src/cli/parser.ts +376 -0
- package/src/cli/presenter.ts +212 -0
- package/src/cli/service-metadata.ts +134 -0
- package/src/cli/spawn-service.ts +326 -0
- package/src/css.d.ts +4 -0
- package/src/gallery-web/app.ts +1581 -0
- package/src/gallery-web/export-menu.ts +121 -0
- package/src/gallery-web/export.ts +112 -0
- package/src/gallery-web/favicon.ts +54 -0
- package/src/gallery-web/frame/entries/chart.ts +6 -0
- package/src/gallery-web/frame/entries/html.ts +6 -0
- package/src/gallery-web/frame/entries/markdown.ts +6 -0
- package/src/gallery-web/frame/entries/mermaid.ts +6 -0
- package/src/gallery-web/frame/entries/svg.ts +6 -0
- package/src/gallery-web/frame/entries/tsx.ts +6 -0
- package/src/gallery-web/frame/frame-payload.ts +91 -0
- package/src/gallery-web/frame/renderer-validation.ts +13 -0
- package/src/gallery-web/frame/renderers/chart.ts +182 -0
- package/src/gallery-web/frame/renderers/dompurify-shim.ts +112 -0
- package/src/gallery-web/frame/renderers/html.ts +48 -0
- package/src/gallery-web/frame/renderers/markdown.ts +81 -0
- package/src/gallery-web/frame/renderers/mermaid.ts +120 -0
- package/src/gallery-web/frame/renderers/registry.ts +260 -0
- package/src/gallery-web/frame/renderers/svg.ts +393 -0
- package/src/gallery-web/frame/renderers/tsx.ts +61 -0
- package/src/gallery-web/frame/runtime.ts +501 -0
- package/src/gallery-web/frame/styles/artifact.css +8424 -0
- package/src/gallery-web/frame/styles/frame.css +183 -0
- package/src/gallery-web/frame/styles/html-source.css +23 -0
- package/src/gallery-web/frame/view-box.ts +33 -0
- package/src/gallery-web/frame-html.ts +72 -0
- package/src/gallery-web/index.html +104 -0
- package/src/gallery-web/session.ts +107 -0
- package/src/gallery-web/sse-client.ts +212 -0
- package/src/gallery-web/styles/app.css +420 -0
- package/src/gallery-web/styles/tokens.css +112 -0
- package/src/gallery-web/styles/verdict.css +186 -0
- package/src/gallery-web/swap.ts +64 -0
- package/src/gallery-web/theme.ts +40 -0
- package/src/gallery-web/view-state.ts +93 -0
- package/src/harness-adapters/claude-code/README.md +10 -0
- package/src/harness-adapters/claude-code/facet.sh +4 -0
- package/src/harness-adapters/codex/README.md +10 -0
- package/src/harness-adapters/codex/facet.sh +4 -0
- package/src/harness-adapters/mcp/README.md +13 -0
- package/src/harness-adapters/mcp/cli-bridge.ts +216 -0
- package/src/harness-adapters/mcp/main.ts +15 -0
- package/src/harness-adapters/mcp/server.ts +164 -0
- package/src/harness-adapters/mcp/tool-schemas.ts +53 -0
- package/src/harness-adapters/opencode/README.md +10 -0
- package/src/harness-adapters/opencode/facet.sh +4 -0
- package/src/runtime/compiled-entrypoints.ts +69 -0
- package/src/service/dispatcher.ts +717 -0
- package/src/service/export.ts +218 -0
- package/src/service/http-utils.ts +55 -0
- package/src/service/lexical/expectations.ts +210 -0
- package/src/service/lifecycle/idle-controller.ts +125 -0
- package/src/service/lifecycle/orphan-cleanup.ts +128 -0
- package/src/service/lifecycle/process-lock.ts +235 -0
- package/src/service/main.ts +136 -0
- package/src/service/process.ts +240 -0
- package/src/service/router-guards.ts +239 -0
- package/src/service/router.ts +627 -0
- package/src/service/security/auth.ts +168 -0
- package/src/service/security/host-origin.ts +138 -0
- package/src/service/security/http-guards.ts +13 -0
- package/src/service/security/leases.ts +182 -0
- package/src/service/security/token-store.ts +138 -0
- package/src/service/server.ts +356 -0
- package/src/service/store/database.ts +61 -0
- package/src/service/store/evidence-retention.ts +234 -0
- package/src/service/store/migrations.ts +167 -0
- package/src/service/store/repository-lifecycle.ts +121 -0
- package/src/service/store/repository.ts +732 -0
- package/src/service/store/schema.ts +218 -0
- package/src/service/stored-verdict.ts +97 -0
- package/src/service/stream.ts +301 -0
- package/src/service/verdict-enrichment.ts +45 -0
- package/src/shared/build/frame-bundle-plugins.ts +61 -0
- package/src/shared/build-mode.ts +28 -0
- package/src/shared/config/evidence-read.ts +98 -0
- package/src/shared/config/limits.ts +56 -0
- package/src/shared/config/paths.ts +96 -0
- package/src/shared/contracts/artifact-types.ts +2 -0
- package/src/shared/contracts/artifact.ts +98 -0
- package/src/shared/contracts/commands/_shared.ts +59 -0
- package/src/shared/contracts/commands/guards.ts +86 -0
- package/src/shared/contracts/commands/index.ts +204 -0
- package/src/shared/contracts/commands/names.ts +35 -0
- package/src/shared/contracts/commands/requests.ts +149 -0
- package/src/shared/contracts/commands/results.ts +200 -0
- package/src/shared/contracts/envelope.ts +140 -0
- package/src/shared/contracts/events.ts +41 -0
- package/src/shared/contracts/observed-counts.ts +19 -0
- package/src/shared/contracts/renderers.ts +6 -0
- package/src/shared/contracts/validation.ts +296 -0
- package/src/shared/errors/facet-error.ts +127 -0
- package/src/shared/errors/store-error.ts +68 -0
- package/src/shared/evidence-image.ts +37 -0
- package/src/shared/export.ts +31 -0
- package/src/shared/html/policy.ts +108 -0
- package/src/shared/html/style-vocabulary.ts +352 -0
- package/src/shared/logging/logger.ts +108 -0
- package/src/shared/logging/redact.ts +49 -0
- package/src/shared/security/frozen-csp.ts +13 -0
- package/src/shared/storage-version.ts +2 -0
- package/src/shared/tsx/execution.ts +29 -0
- package/src/shared/tsx/import-policy.ts +94 -0
- package/src/shared/util/dir-permissions.ts +94 -0
- package/src/shared/util/mermaid-nodes.ts +230 -0
- package/src/shared/util/process.ts +67 -0
- package/src/shared/util/time.ts +21 -0
- package/src/shared/version.ts +3 -0
- package/src/validation/sandbox/limits.ts +41 -0
- package/src/validation/sandbox/netns.ts +177 -0
- package/src/validation/tier0/chart.ts +177 -0
- package/src/validation/tier0/dom-shim.ts +54 -0
- package/src/validation/tier0/html.ts +408 -0
- package/src/validation/tier0/markdown.ts +285 -0
- package/src/validation/tier0/mermaid.ts +98 -0
- package/src/validation/tier0/runner.ts +504 -0
- package/src/validation/tier0/svg.ts +321 -0
- package/src/validation/tier0/tsx/allowlist-resolver.ts +77 -0
- package/src/validation/tier0/tsx/ast-policy-capabilities.ts +238 -0
- package/src/validation/tier0/tsx/ast-policy-shared.ts +71 -0
- package/src/validation/tier0/tsx/ast-policy.ts +181 -0
- package/src/validation/tier0/tsx/compiler.ts +156 -0
- package/src/validation/tier0/worker-dispatch.ts +211 -0
- package/src/validation/tier0/worker-entry.ts +96 -0
- package/src/validation/tier0/worker-input.ts +75 -0
- package/src/validation/tier1/browser-process.ts +147 -0
- package/src/validation/tier1/cdp-pipe.ts +281 -0
- package/src/validation/tier1/entries/chart.ts +5 -0
- package/src/validation/tier1/entries/html.ts +6 -0
- package/src/validation/tier1/entries/markdown.ts +5 -0
- package/src/validation/tier1/entries/mermaid.ts +5 -0
- package/src/validation/tier1/entries/svg.ts +5 -0
- package/src/validation/tier1/entries/tsx.ts +5 -0
- package/src/validation/tier1/frame-target.ts +162 -0
- package/src/validation/tier1/harness-entry.ts +261 -0
- package/src/validation/tier1/harness.ts +215 -0
- package/src/validation/tier1/isolated-probe.ts +94 -0
- package/src/validation/tier1/launcher.ts +177 -0
- package/src/validation/tier1/limits.ts +80 -0
- package/src/validation/tier1/nonce.ts +17 -0
- package/src/validation/tier1/protocol-probe.ts +519 -0
- package/src/validation/tier1/runner.ts +1122 -0
- package/src/validation/tier1/verdict.ts +246 -0
- package/src/validation/tier1/webp.ts +69 -0
- package/templates/README.md +88 -0
- package/templates/bar-compare.vl.json +63 -0
- package/templates/capacity-report.tsx +102 -0
- package/templates/decision-record.md +24 -0
- package/templates/deployment-state.mmd +40 -0
- package/templates/exemplar.md +91 -0
- package/templates/facet-story.tsx +799 -0
- package/templates/fleet-dashboard.html +141 -0
- package/templates/html-release-ledger.html +91 -0
- package/templates/html-status-report.html +114 -0
- package/templates/incident-console.tsx +147 -0
- package/templates/legion-boundaries.mmd +23 -0
- package/templates/legion-flow.mmd +15 -0
- package/templates/legion-sequence.mmd +14 -0
- package/templates/legion-state.mmd +7 -0
- package/templates/metric-card.svg +29 -0
- package/templates/observability-map.svg +101 -0
- package/templates/pipeline-audit.md +108 -0
- package/templates/release-metrics.vl.json +98 -0
- package/templates/service-topology.mmd +47 -0
- package/templates/status-report.md +32 -0
- package/templates/system-map.svg +53 -0
- package/templates/timeseries.vl.json +71 -0
- package/templates/tsx-interactive-counter.tsx +19 -0
- package/templates/tsx-status-report.tsx +31 -0
|
@@ -0,0 +1,2566 @@
|
|
|
1
|
+
import {
|
|
2
|
+
selectSvgElement
|
|
3
|
+
} from "./markdown-6zz8efx2.js";
|
|
4
|
+
import {
|
|
5
|
+
at
|
|
6
|
+
} from "./markdown-82xmzhzd.js";
|
|
7
|
+
import {
|
|
8
|
+
cleanAndMerge
|
|
9
|
+
} from "./markdown-ff5wvb43.js";
|
|
10
|
+
import"./markdown-pzgd8z3s.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 "./markdown-92n37gd4.js";
|
|
27
|
+
import {
|
|
28
|
+
select_default
|
|
29
|
+
} from "./markdown-xw8dsk8b.js";
|
|
30
|
+
import {
|
|
31
|
+
__name
|
|
32
|
+
} from "./markdown-1s5vwkf2.js";
|
|
33
|
+
import"./markdown-dy5sgjhc.js";
|
|
34
|
+
import"./markdown-809k7q41.js";
|
|
35
|
+
|
|
36
|
+
// node_modules/@upsetjs/venn.js/build/venn.esm.js
|
|
37
|
+
var SMALL$1 = 0.0000000001;
|
|
38
|
+
function intersectionArea(circles, stats) {
|
|
39
|
+
const intersectionPoints = getIntersectionPoints(circles);
|
|
40
|
+
const innerPoints = intersectionPoints.filter((p) => containedInCircles(p, circles));
|
|
41
|
+
let arcArea = 0;
|
|
42
|
+
let polygonArea = 0;
|
|
43
|
+
const arcs = [];
|
|
44
|
+
if (innerPoints.length > 1) {
|
|
45
|
+
const center = getCenter(innerPoints);
|
|
46
|
+
for (let i = 0;i < innerPoints.length; ++i) {
|
|
47
|
+
const p = innerPoints[i];
|
|
48
|
+
p.angle = Math.atan2(p.x - center.x, p.y - center.y);
|
|
49
|
+
}
|
|
50
|
+
innerPoints.sort((a, b) => b.angle - a.angle);
|
|
51
|
+
let p2 = innerPoints[innerPoints.length - 1];
|
|
52
|
+
for (let i = 0;i < innerPoints.length; ++i) {
|
|
53
|
+
const p1 = innerPoints[i];
|
|
54
|
+
polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
|
|
55
|
+
const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
56
|
+
let arc = null;
|
|
57
|
+
for (let j = 0;j < p1.parentIndex.length; ++j) {
|
|
58
|
+
if (p2.parentIndex.includes(p1.parentIndex[j])) {
|
|
59
|
+
const circle = circles[p1.parentIndex[j]];
|
|
60
|
+
const a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y);
|
|
61
|
+
const a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
|
|
62
|
+
let angleDiff = a2 - a1;
|
|
63
|
+
if (angleDiff < 0) {
|
|
64
|
+
angleDiff += 2 * Math.PI;
|
|
65
|
+
}
|
|
66
|
+
const a = a2 - angleDiff / 2;
|
|
67
|
+
let width = distance(midPoint, {
|
|
68
|
+
x: circle.x + circle.radius * Math.sin(a),
|
|
69
|
+
y: circle.y + circle.radius * Math.cos(a)
|
|
70
|
+
});
|
|
71
|
+
if (width > circle.radius * 2) {
|
|
72
|
+
width = circle.radius * 2;
|
|
73
|
+
}
|
|
74
|
+
if (arc == null || arc.width > width) {
|
|
75
|
+
arc = { circle, width, p1, p2, large: width > circle.radius, sweep: true };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (arc != null) {
|
|
80
|
+
arcs.push(arc);
|
|
81
|
+
arcArea += circleArea(arc.circle.radius, arc.width);
|
|
82
|
+
p2 = p1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
let smallest = circles[0];
|
|
87
|
+
for (let i = 1;i < circles.length; ++i) {
|
|
88
|
+
if (circles[i].radius < smallest.radius) {
|
|
89
|
+
smallest = circles[i];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let disjoint = false;
|
|
93
|
+
for (let i = 0;i < circles.length; ++i) {
|
|
94
|
+
if (distance(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
|
|
95
|
+
disjoint = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (disjoint) {
|
|
100
|
+
arcArea = polygonArea = 0;
|
|
101
|
+
} else {
|
|
102
|
+
arcArea = smallest.radius * smallest.radius * Math.PI;
|
|
103
|
+
arcs.push({
|
|
104
|
+
circle: smallest,
|
|
105
|
+
p1: { x: smallest.x, y: smallest.y + smallest.radius },
|
|
106
|
+
p2: { x: smallest.x - SMALL$1, y: smallest.y + smallest.radius },
|
|
107
|
+
width: smallest.radius * 2,
|
|
108
|
+
large: true,
|
|
109
|
+
sweep: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
polygonArea /= 2;
|
|
114
|
+
if (stats) {
|
|
115
|
+
stats.area = arcArea + polygonArea;
|
|
116
|
+
stats.arcArea = arcArea;
|
|
117
|
+
stats.polygonArea = polygonArea;
|
|
118
|
+
stats.arcs = arcs;
|
|
119
|
+
stats.innerPoints = innerPoints;
|
|
120
|
+
stats.intersectionPoints = intersectionPoints;
|
|
121
|
+
}
|
|
122
|
+
return arcArea + polygonArea;
|
|
123
|
+
}
|
|
124
|
+
function containedInCircles(point, circles) {
|
|
125
|
+
return circles.every((circle) => distance(point, circle) < circle.radius + SMALL$1);
|
|
126
|
+
}
|
|
127
|
+
function getIntersectionPoints(circles) {
|
|
128
|
+
const ret = [];
|
|
129
|
+
for (let i = 0;i < circles.length; ++i) {
|
|
130
|
+
for (let j = i + 1;j < circles.length; ++j) {
|
|
131
|
+
const intersect = circleCircleIntersection(circles[i], circles[j]);
|
|
132
|
+
for (const p of intersect) {
|
|
133
|
+
p.parentIndex = [i, j];
|
|
134
|
+
ret.push(p);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return ret;
|
|
139
|
+
}
|
|
140
|
+
function circleArea(r, width) {
|
|
141
|
+
return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
|
|
142
|
+
}
|
|
143
|
+
function distance(p1, p2) {
|
|
144
|
+
return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
|
|
145
|
+
}
|
|
146
|
+
function circleOverlap(r1, r2, d) {
|
|
147
|
+
if (d >= r1 + r2) {
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
if (d <= Math.abs(r1 - r2)) {
|
|
151
|
+
return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
|
|
152
|
+
}
|
|
153
|
+
const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d);
|
|
154
|
+
const w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
|
|
155
|
+
return circleArea(r1, w1) + circleArea(r2, w2);
|
|
156
|
+
}
|
|
157
|
+
function circleCircleIntersection(p1, p2) {
|
|
158
|
+
const d = distance(p1, p2);
|
|
159
|
+
const r1 = p1.radius;
|
|
160
|
+
const r2 = p2.radius;
|
|
161
|
+
if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
|
|
165
|
+
const h = Math.sqrt(r1 * r1 - a * a);
|
|
166
|
+
const x0 = p1.x + a * (p2.x - p1.x) / d;
|
|
167
|
+
const y0 = p1.y + a * (p2.y - p1.y) / d;
|
|
168
|
+
const rx = -(p2.y - p1.y) * (h / d);
|
|
169
|
+
const ry = -(p2.x - p1.x) * (h / d);
|
|
170
|
+
return [
|
|
171
|
+
{ x: x0 + rx, y: y0 - ry },
|
|
172
|
+
{ x: x0 - rx, y: y0 + ry }
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
function getCenter(points) {
|
|
176
|
+
const center = { x: 0, y: 0 };
|
|
177
|
+
for (const point of points) {
|
|
178
|
+
center.x += point.x;
|
|
179
|
+
center.y += point.y;
|
|
180
|
+
}
|
|
181
|
+
center.x /= points.length;
|
|
182
|
+
center.y /= points.length;
|
|
183
|
+
return center;
|
|
184
|
+
}
|
|
185
|
+
function bisect(f, a, b, parameters) {
|
|
186
|
+
parameters = parameters || {};
|
|
187
|
+
const maxIterations = parameters.maxIterations || 100;
|
|
188
|
+
const tolerance = parameters.tolerance || 0.0000000001;
|
|
189
|
+
const fA = f(a);
|
|
190
|
+
const fB = f(b);
|
|
191
|
+
let delta = b - a;
|
|
192
|
+
if (fA * fB > 0) {
|
|
193
|
+
throw "Initial bisect points must have opposite signs";
|
|
194
|
+
}
|
|
195
|
+
if (fA === 0)
|
|
196
|
+
return a;
|
|
197
|
+
if (fB === 0)
|
|
198
|
+
return b;
|
|
199
|
+
for (let i = 0;i < maxIterations; ++i) {
|
|
200
|
+
delta /= 2;
|
|
201
|
+
const mid = a + delta;
|
|
202
|
+
const fMid = f(mid);
|
|
203
|
+
if (fMid * fA >= 0) {
|
|
204
|
+
a = mid;
|
|
205
|
+
}
|
|
206
|
+
if (Math.abs(delta) < tolerance || fMid === 0) {
|
|
207
|
+
return mid;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return a + delta;
|
|
211
|
+
}
|
|
212
|
+
function zeros(x) {
|
|
213
|
+
const r = new Array(x);
|
|
214
|
+
for (let i = 0;i < x; ++i) {
|
|
215
|
+
r[i] = 0;
|
|
216
|
+
}
|
|
217
|
+
return r;
|
|
218
|
+
}
|
|
219
|
+
function zerosM(x, y) {
|
|
220
|
+
return zeros(x).map(() => zeros(y));
|
|
221
|
+
}
|
|
222
|
+
function dot(a, b) {
|
|
223
|
+
let ret = 0;
|
|
224
|
+
for (let i = 0;i < a.length; ++i) {
|
|
225
|
+
ret += a[i] * b[i];
|
|
226
|
+
}
|
|
227
|
+
return ret;
|
|
228
|
+
}
|
|
229
|
+
function norm2(a) {
|
|
230
|
+
return Math.sqrt(dot(a, a));
|
|
231
|
+
}
|
|
232
|
+
function scale(ret, value, c) {
|
|
233
|
+
for (let i = 0;i < value.length; ++i) {
|
|
234
|
+
ret[i] = value[i] * c;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function weightedSum(ret, w1, v1, w2, v2) {
|
|
238
|
+
for (let j = 0;j < ret.length; ++j) {
|
|
239
|
+
ret[j] = w1 * v1[j] + w2 * v2[j];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function nelderMead(f, x0, parameters) {
|
|
243
|
+
parameters = parameters || {};
|
|
244
|
+
const maxIterations = parameters.maxIterations || x0.length * 200;
|
|
245
|
+
const nonZeroDelta = parameters.nonZeroDelta || 1.05;
|
|
246
|
+
const zeroDelta = parameters.zeroDelta || 0.001;
|
|
247
|
+
const minErrorDelta = parameters.minErrorDelta || 0.000001;
|
|
248
|
+
const minTolerance = parameters.minErrorDelta || 0.00001;
|
|
249
|
+
const rho = parameters.rho !== undefined ? parameters.rho : 1;
|
|
250
|
+
const chi = parameters.chi !== undefined ? parameters.chi : 2;
|
|
251
|
+
const psi = parameters.psi !== undefined ? parameters.psi : -0.5;
|
|
252
|
+
const sigma = parameters.sigma !== undefined ? parameters.sigma : 0.5;
|
|
253
|
+
let maxDiff;
|
|
254
|
+
const N = x0.length;
|
|
255
|
+
const simplex = new Array(N + 1);
|
|
256
|
+
simplex[0] = x0;
|
|
257
|
+
simplex[0].fx = f(x0);
|
|
258
|
+
simplex[0].id = 0;
|
|
259
|
+
for (let i = 0;i < N; ++i) {
|
|
260
|
+
const point = x0.slice();
|
|
261
|
+
point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta;
|
|
262
|
+
simplex[i + 1] = point;
|
|
263
|
+
simplex[i + 1].fx = f(point);
|
|
264
|
+
simplex[i + 1].id = i + 1;
|
|
265
|
+
}
|
|
266
|
+
function updateSimplex(value) {
|
|
267
|
+
for (let i = 0;i < value.length; i++) {
|
|
268
|
+
simplex[N][i] = value[i];
|
|
269
|
+
}
|
|
270
|
+
simplex[N].fx = value.fx;
|
|
271
|
+
}
|
|
272
|
+
const sortOrder = (a, b) => a.fx - b.fx;
|
|
273
|
+
const centroid = x0.slice();
|
|
274
|
+
const reflected = x0.slice();
|
|
275
|
+
const contracted = x0.slice();
|
|
276
|
+
const expanded = x0.slice();
|
|
277
|
+
for (let iteration = 0;iteration < maxIterations; ++iteration) {
|
|
278
|
+
simplex.sort(sortOrder);
|
|
279
|
+
if (parameters.history) {
|
|
280
|
+
const sortedSimplex = simplex.map((x) => {
|
|
281
|
+
const state = x.slice();
|
|
282
|
+
state.fx = x.fx;
|
|
283
|
+
state.id = x.id;
|
|
284
|
+
return state;
|
|
285
|
+
});
|
|
286
|
+
sortedSimplex.sort((a, b) => a.id - b.id);
|
|
287
|
+
parameters.history.push({
|
|
288
|
+
x: simplex[0].slice(),
|
|
289
|
+
fx: simplex[0].fx,
|
|
290
|
+
simplex: sortedSimplex
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
maxDiff = 0;
|
|
294
|
+
for (let i = 0;i < N; ++i) {
|
|
295
|
+
maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));
|
|
296
|
+
}
|
|
297
|
+
if (Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta && maxDiff < minTolerance) {
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
for (let i = 0;i < N; ++i) {
|
|
301
|
+
centroid[i] = 0;
|
|
302
|
+
for (let j = 0;j < N; ++j) {
|
|
303
|
+
centroid[i] += simplex[j][i];
|
|
304
|
+
}
|
|
305
|
+
centroid[i] /= N;
|
|
306
|
+
}
|
|
307
|
+
const worst = simplex[N];
|
|
308
|
+
weightedSum(reflected, 1 + rho, centroid, -rho, worst);
|
|
309
|
+
reflected.fx = f(reflected);
|
|
310
|
+
if (reflected.fx < simplex[0].fx) {
|
|
311
|
+
weightedSum(expanded, 1 + chi, centroid, -chi, worst);
|
|
312
|
+
expanded.fx = f(expanded);
|
|
313
|
+
if (expanded.fx < reflected.fx) {
|
|
314
|
+
updateSimplex(expanded);
|
|
315
|
+
} else {
|
|
316
|
+
updateSimplex(reflected);
|
|
317
|
+
}
|
|
318
|
+
} else if (reflected.fx >= simplex[N - 1].fx) {
|
|
319
|
+
let shouldReduce = false;
|
|
320
|
+
if (reflected.fx > worst.fx) {
|
|
321
|
+
weightedSum(contracted, 1 + psi, centroid, -psi, worst);
|
|
322
|
+
contracted.fx = f(contracted);
|
|
323
|
+
if (contracted.fx < worst.fx) {
|
|
324
|
+
updateSimplex(contracted);
|
|
325
|
+
} else {
|
|
326
|
+
shouldReduce = true;
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
weightedSum(contracted, 1 - psi * rho, centroid, psi * rho, worst);
|
|
330
|
+
contracted.fx = f(contracted);
|
|
331
|
+
if (contracted.fx < reflected.fx) {
|
|
332
|
+
updateSimplex(contracted);
|
|
333
|
+
} else {
|
|
334
|
+
shouldReduce = true;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (shouldReduce) {
|
|
338
|
+
if (sigma >= 1)
|
|
339
|
+
break;
|
|
340
|
+
for (let i = 1;i < simplex.length; ++i) {
|
|
341
|
+
weightedSum(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]);
|
|
342
|
+
simplex[i].fx = f(simplex[i]);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
updateSimplex(reflected);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
simplex.sort(sortOrder);
|
|
350
|
+
return { fx: simplex[0].fx, x: simplex[0] };
|
|
351
|
+
}
|
|
352
|
+
function wolfeLineSearch(f, pk, current, next, a, c1, c2) {
|
|
353
|
+
const phi0 = current.fx;
|
|
354
|
+
const phiPrime0 = dot(current.fxprime, pk);
|
|
355
|
+
let phi = phi0;
|
|
356
|
+
let phi_old = phi0;
|
|
357
|
+
let phiPrime = phiPrime0;
|
|
358
|
+
let a0 = 0;
|
|
359
|
+
a = a || 1;
|
|
360
|
+
c1 = c1 || 0.000001;
|
|
361
|
+
c2 = c2 || 0.1;
|
|
362
|
+
function zoom(a_lo, a_high, phi_lo) {
|
|
363
|
+
for (let iteration = 0;iteration < 16; ++iteration) {
|
|
364
|
+
a = (a_lo + a_high) / 2;
|
|
365
|
+
weightedSum(next.x, 1, current.x, a, pk);
|
|
366
|
+
phi = next.fx = f(next.x, next.fxprime);
|
|
367
|
+
phiPrime = dot(next.fxprime, pk);
|
|
368
|
+
if (phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) {
|
|
369
|
+
a_high = a;
|
|
370
|
+
} else {
|
|
371
|
+
if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
|
|
372
|
+
return a;
|
|
373
|
+
}
|
|
374
|
+
if (phiPrime * (a_high - a_lo) >= 0) {
|
|
375
|
+
a_high = a_lo;
|
|
376
|
+
}
|
|
377
|
+
a_lo = a;
|
|
378
|
+
phi_lo = phi;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return 0;
|
|
382
|
+
}
|
|
383
|
+
for (let iteration = 0;iteration < 10; ++iteration) {
|
|
384
|
+
weightedSum(next.x, 1, current.x, a, pk);
|
|
385
|
+
phi = next.fx = f(next.x, next.fxprime);
|
|
386
|
+
phiPrime = dot(next.fxprime, pk);
|
|
387
|
+
if (phi > phi0 + c1 * a * phiPrime0 || iteration && phi >= phi_old) {
|
|
388
|
+
return zoom(a0, a, phi_old);
|
|
389
|
+
}
|
|
390
|
+
if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
|
|
391
|
+
return a;
|
|
392
|
+
}
|
|
393
|
+
if (phiPrime >= 0) {
|
|
394
|
+
return zoom(a, a0, phi);
|
|
395
|
+
}
|
|
396
|
+
phi_old = phi;
|
|
397
|
+
a0 = a;
|
|
398
|
+
a *= 2;
|
|
399
|
+
}
|
|
400
|
+
return a;
|
|
401
|
+
}
|
|
402
|
+
function conjugateGradient(f, initial, params) {
|
|
403
|
+
let current = { x: initial.slice(), fx: 0, fxprime: initial.slice() };
|
|
404
|
+
let next = { x: initial.slice(), fx: 0, fxprime: initial.slice() };
|
|
405
|
+
const yk = initial.slice();
|
|
406
|
+
let pk;
|
|
407
|
+
let temp;
|
|
408
|
+
let a = 1;
|
|
409
|
+
let maxIterations;
|
|
410
|
+
params = params || {};
|
|
411
|
+
maxIterations = params.maxIterations || initial.length * 20;
|
|
412
|
+
current.fx = f(current.x, current.fxprime);
|
|
413
|
+
pk = current.fxprime.slice();
|
|
414
|
+
scale(pk, current.fxprime, -1);
|
|
415
|
+
for (let i = 0;i < maxIterations; ++i) {
|
|
416
|
+
a = wolfeLineSearch(f, pk, current, next, a);
|
|
417
|
+
if (params.history) {
|
|
418
|
+
params.history.push({
|
|
419
|
+
x: current.x.slice(),
|
|
420
|
+
fx: current.fx,
|
|
421
|
+
fxprime: current.fxprime.slice(),
|
|
422
|
+
alpha: a
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
if (!a) {
|
|
426
|
+
scale(pk, current.fxprime, -1);
|
|
427
|
+
} else {
|
|
428
|
+
weightedSum(yk, 1, next.fxprime, -1, current.fxprime);
|
|
429
|
+
const delta_k = dot(current.fxprime, current.fxprime);
|
|
430
|
+
const beta_k = Math.max(0, dot(yk, next.fxprime) / delta_k);
|
|
431
|
+
weightedSum(pk, beta_k, pk, -1, next.fxprime);
|
|
432
|
+
temp = current;
|
|
433
|
+
current = next;
|
|
434
|
+
next = temp;
|
|
435
|
+
}
|
|
436
|
+
if (norm2(current.fxprime) <= 0.00001) {
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (params.history) {
|
|
441
|
+
params.history.push({
|
|
442
|
+
x: current.x.slice(),
|
|
443
|
+
fx: current.fx,
|
|
444
|
+
fxprime: current.fxprime.slice(),
|
|
445
|
+
alpha: a
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
return current;
|
|
449
|
+
}
|
|
450
|
+
function venn(sets, parameters = {}) {
|
|
451
|
+
parameters.maxIterations = parameters.maxIterations || 500;
|
|
452
|
+
const initialLayout = parameters.initialLayout || bestInitialLayout;
|
|
453
|
+
const loss = parameters.lossFunction || lossFunction;
|
|
454
|
+
const areas = addMissingAreas(sets, parameters);
|
|
455
|
+
const circles = initialLayout(areas, parameters);
|
|
456
|
+
const setids = Object.keys(circles);
|
|
457
|
+
const initial = [];
|
|
458
|
+
for (const setid of setids) {
|
|
459
|
+
initial.push(circles[setid].x);
|
|
460
|
+
initial.push(circles[setid].y);
|
|
461
|
+
}
|
|
462
|
+
const solution = nelderMead((values) => {
|
|
463
|
+
const current = {};
|
|
464
|
+
for (let i = 0;i < setids.length; ++i) {
|
|
465
|
+
const setid = setids[i];
|
|
466
|
+
current[setid] = {
|
|
467
|
+
x: values[2 * i],
|
|
468
|
+
y: values[2 * i + 1],
|
|
469
|
+
radius: circles[setid].radius
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return loss(current, areas);
|
|
473
|
+
}, initial, parameters);
|
|
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 = 0.0000000001;
|
|
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 = 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 = 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 + 0.0000000001 >= Math.min(sets[left].size, sets[right].size)) {
|
|
552
|
+
c = 1;
|
|
553
|
+
} else if (current.size <= 0.0000000001) {
|
|
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 + 0.00000001 < 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: 10000000000,
|
|
649
|
+
y: 10000000000,
|
|
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({ x: p1.x, y: p1.y, radius: d1 }, { x: p2.x, y: p2.y, radius: d2 });
|
|
710
|
+
points.push(...extraPoints);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
let bestLoss = 100000000000000000000000000000000000000000000000000;
|
|
714
|
+
let bestPoint = points[0];
|
|
715
|
+
for (const point of points) {
|
|
716
|
+
circles[setIndex].x = point.x;
|
|
717
|
+
circles[setIndex].y = point.y;
|
|
718
|
+
const localLoss = loss(circles, areas);
|
|
719
|
+
if (localLoss < bestLoss) {
|
|
720
|
+
bestLoss = localLoss;
|
|
721
|
+
bestPoint = point;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
positionSet(bestPoint, setIndex);
|
|
725
|
+
}
|
|
726
|
+
return circles;
|
|
727
|
+
}
|
|
728
|
+
function lossFunction(circles, overlaps) {
|
|
729
|
+
let output = 0;
|
|
730
|
+
for (const area of overlaps) {
|
|
731
|
+
if (area.sets.length === 1) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
let overlap;
|
|
735
|
+
if (area.sets.length === 2) {
|
|
736
|
+
const left = circles[area.sets[0]];
|
|
737
|
+
const right = circles[area.sets[1]];
|
|
738
|
+
overlap = circleOverlap(left.radius, right.radius, distance(left, right));
|
|
739
|
+
} else {
|
|
740
|
+
overlap = intersectionArea(area.sets.map((d) => circles[d]));
|
|
741
|
+
}
|
|
742
|
+
const weight = area.weight != null ? area.weight : 1;
|
|
743
|
+
output += weight * (overlap - area.size) * (overlap - area.size);
|
|
744
|
+
}
|
|
745
|
+
return output;
|
|
746
|
+
}
|
|
747
|
+
function logRatioLossFunction(circles, overlaps) {
|
|
748
|
+
let output = 0;
|
|
749
|
+
for (const area of overlaps) {
|
|
750
|
+
if (area.sets.length === 1) {
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
let overlap;
|
|
754
|
+
if (area.sets.length === 2) {
|
|
755
|
+
const left = circles[area.sets[0]];
|
|
756
|
+
const right = circles[area.sets[1]];
|
|
757
|
+
overlap = circleOverlap(left.radius, right.radius, distance(left, right));
|
|
758
|
+
} else {
|
|
759
|
+
overlap = intersectionArea(area.sets.map((d) => circles[d]));
|
|
760
|
+
}
|
|
761
|
+
const weight = area.weight != null ? area.weight : 1;
|
|
762
|
+
const differenceFromIdeal = Math.log((overlap + 1) / (area.size + 1));
|
|
763
|
+
output += weight * differenceFromIdeal * differenceFromIdeal;
|
|
764
|
+
}
|
|
765
|
+
return output;
|
|
766
|
+
}
|
|
767
|
+
function orientateCircles(circles, orientation, orientationOrder) {
|
|
768
|
+
if (orientationOrder == null) {
|
|
769
|
+
circles.sort((a, b) => b.radius - a.radius);
|
|
770
|
+
} else {
|
|
771
|
+
circles.sort(orientationOrder);
|
|
772
|
+
}
|
|
773
|
+
if (circles.length > 0) {
|
|
774
|
+
const largestX = circles[0].x;
|
|
775
|
+
const largestY = circles[0].y;
|
|
776
|
+
for (const circle of circles) {
|
|
777
|
+
circle.x -= largestX;
|
|
778
|
+
circle.y -= largestY;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
if (circles.length === 2) {
|
|
782
|
+
const dist = distance(circles[0], circles[1]);
|
|
783
|
+
if (dist < Math.abs(circles[1].radius - circles[0].radius)) {
|
|
784
|
+
circles[1].x = circles[0].x + circles[0].radius - circles[1].radius - 0.0000000001;
|
|
785
|
+
circles[1].y = circles[0].y;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (circles.length > 1) {
|
|
789
|
+
const rotation = Math.atan2(circles[1].x, circles[1].y) - orientation;
|
|
790
|
+
const c = Math.cos(rotation);
|
|
791
|
+
const s = Math.sin(rotation);
|
|
792
|
+
for (const circle of circles) {
|
|
793
|
+
const x = circle.x;
|
|
794
|
+
const y = circle.y;
|
|
795
|
+
circle.x = c * x - s * y;
|
|
796
|
+
circle.y = s * x + c * y;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (circles.length > 2) {
|
|
800
|
+
let angle = Math.atan2(circles[2].x, circles[2].y) - orientation;
|
|
801
|
+
while (angle < 0) {
|
|
802
|
+
angle += 2 * Math.PI;
|
|
803
|
+
}
|
|
804
|
+
while (angle > 2 * Math.PI) {
|
|
805
|
+
angle -= 2 * Math.PI;
|
|
806
|
+
}
|
|
807
|
+
if (angle > Math.PI) {
|
|
808
|
+
const slope = circles[1].y / (0.0000000001 + circles[1].x);
|
|
809
|
+
for (const circle of circles) {
|
|
810
|
+
var d = (circle.x + slope * circle.y) / (1 + slope * slope);
|
|
811
|
+
circle.x = 2 * d - circle.x;
|
|
812
|
+
circle.y = 2 * d * slope - circle.y;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function disjointCluster(circles) {
|
|
818
|
+
circles.forEach((circle) => {
|
|
819
|
+
circle.parent = circle;
|
|
820
|
+
});
|
|
821
|
+
function find(circle) {
|
|
822
|
+
if (circle.parent !== circle) {
|
|
823
|
+
circle.parent = find(circle.parent);
|
|
824
|
+
}
|
|
825
|
+
return circle.parent;
|
|
826
|
+
}
|
|
827
|
+
function union(x, y) {
|
|
828
|
+
const xRoot = find(x);
|
|
829
|
+
const yRoot = find(y);
|
|
830
|
+
xRoot.parent = yRoot;
|
|
831
|
+
}
|
|
832
|
+
for (let i = 0;i < circles.length; ++i) {
|
|
833
|
+
for (let j = i + 1;j < circles.length; ++j) {
|
|
834
|
+
const maxDistance = circles[i].radius + circles[j].radius;
|
|
835
|
+
if (distance(circles[i], circles[j]) + 0.0000000001 < maxDistance) {
|
|
836
|
+
union(circles[j], circles[i]);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
const disjointClusters = new Map;
|
|
841
|
+
for (let i = 0;i < circles.length; ++i) {
|
|
842
|
+
const setid = find(circles[i]).parent.setid;
|
|
843
|
+
if (!disjointClusters.has(setid)) {
|
|
844
|
+
disjointClusters.set(setid, []);
|
|
845
|
+
}
|
|
846
|
+
disjointClusters.get(setid).push(circles[i]);
|
|
847
|
+
}
|
|
848
|
+
circles.forEach((circle) => {
|
|
849
|
+
delete circle.parent;
|
|
850
|
+
});
|
|
851
|
+
return Array.from(disjointClusters.values());
|
|
852
|
+
}
|
|
853
|
+
function getBoundingBox(circles) {
|
|
854
|
+
const minMax = (d) => {
|
|
855
|
+
const hi = circles.reduce((acc, c) => Math.max(acc, c[d] + c.radius), Number.NEGATIVE_INFINITY);
|
|
856
|
+
const lo = circles.reduce((acc, c) => Math.min(acc, c[d] - c.radius), Number.POSITIVE_INFINITY);
|
|
857
|
+
return { max: hi, min: lo };
|
|
858
|
+
};
|
|
859
|
+
return { xRange: minMax("x"), yRange: minMax("y") };
|
|
860
|
+
}
|
|
861
|
+
function normalizeSolution(solution, orientation, orientationOrder) {
|
|
862
|
+
if (orientation == null) {
|
|
863
|
+
orientation = Math.PI / 2;
|
|
864
|
+
}
|
|
865
|
+
let circles = fromObjectNotation(solution).map((d) => Object.assign({}, d));
|
|
866
|
+
const clusters = disjointCluster(circles);
|
|
867
|
+
for (const cluster of clusters) {
|
|
868
|
+
orientateCircles(cluster, orientation, orientationOrder);
|
|
869
|
+
const bounds = getBoundingBox(cluster);
|
|
870
|
+
cluster.size = (bounds.xRange.max - bounds.xRange.min) * (bounds.yRange.max - bounds.yRange.min);
|
|
871
|
+
cluster.bounds = bounds;
|
|
872
|
+
}
|
|
873
|
+
clusters.sort((a, b) => b.size - a.size);
|
|
874
|
+
circles = clusters[0];
|
|
875
|
+
let returnBounds = circles.bounds;
|
|
876
|
+
const spacing = (returnBounds.xRange.max - returnBounds.xRange.min) / 50;
|
|
877
|
+
function addCluster(cluster, right, bottom) {
|
|
878
|
+
if (!cluster) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
const bounds = cluster.bounds;
|
|
882
|
+
let xOffset;
|
|
883
|
+
let yOffset;
|
|
884
|
+
if (right) {
|
|
885
|
+
xOffset = returnBounds.xRange.max - bounds.xRange.min + spacing;
|
|
886
|
+
} else {
|
|
887
|
+
xOffset = returnBounds.xRange.max - bounds.xRange.max;
|
|
888
|
+
const centreing = (bounds.xRange.max - bounds.xRange.min) / 2 - (returnBounds.xRange.max - returnBounds.xRange.min) / 2;
|
|
889
|
+
if (centreing < 0) {
|
|
890
|
+
xOffset += centreing;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (bottom) {
|
|
894
|
+
yOffset = returnBounds.yRange.max - bounds.yRange.min + spacing;
|
|
895
|
+
} else {
|
|
896
|
+
yOffset = returnBounds.yRange.max - bounds.yRange.max;
|
|
897
|
+
const centreing = (bounds.yRange.max - bounds.yRange.min) / 2 - (returnBounds.yRange.max - returnBounds.yRange.min) / 2;
|
|
898
|
+
if (centreing < 0) {
|
|
899
|
+
yOffset += centreing;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
for (const c of cluster) {
|
|
903
|
+
c.x += xOffset;
|
|
904
|
+
c.y += yOffset;
|
|
905
|
+
circles.push(c);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
let index = 1;
|
|
909
|
+
while (index < clusters.length) {
|
|
910
|
+
addCluster(clusters[index], true, false);
|
|
911
|
+
addCluster(clusters[index + 1], false, true);
|
|
912
|
+
addCluster(clusters[index + 2], true, true);
|
|
913
|
+
index += 3;
|
|
914
|
+
returnBounds = getBoundingBox(circles);
|
|
915
|
+
}
|
|
916
|
+
return toObjectNotation(circles);
|
|
917
|
+
}
|
|
918
|
+
function scaleSolution(solution, width, height, padding, scaleToFit) {
|
|
919
|
+
const circles = fromObjectNotation(solution);
|
|
920
|
+
width -= 2 * padding;
|
|
921
|
+
height -= 2 * padding;
|
|
922
|
+
const { xRange, yRange } = getBoundingBox(circles);
|
|
923
|
+
if (xRange.max === xRange.min || yRange.max === yRange.min) {
|
|
924
|
+
console.log("not scaling solution: zero size detected");
|
|
925
|
+
return solution;
|
|
926
|
+
}
|
|
927
|
+
let xScaling;
|
|
928
|
+
let yScaling;
|
|
929
|
+
if (scaleToFit) {
|
|
930
|
+
const toScaleDiameter = Math.sqrt(scaleToFit / Math.PI) * 2;
|
|
931
|
+
xScaling = width / toScaleDiameter;
|
|
932
|
+
yScaling = height / toScaleDiameter;
|
|
933
|
+
} else {
|
|
934
|
+
xScaling = width / (xRange.max - xRange.min);
|
|
935
|
+
yScaling = height / (yRange.max - yRange.min);
|
|
936
|
+
}
|
|
937
|
+
const scaling = Math.min(yScaling, xScaling);
|
|
938
|
+
const xOffset = (width - (xRange.max - xRange.min) * scaling) / 2;
|
|
939
|
+
const yOffset = (height - (yRange.max - yRange.min) * scaling) / 2;
|
|
940
|
+
return toObjectNotation(circles.map((circle) => ({
|
|
941
|
+
radius: scaling * circle.radius,
|
|
942
|
+
x: padding + xOffset + (circle.x - xRange.min) * scaling,
|
|
943
|
+
y: padding + yOffset + (circle.y - yRange.min) * scaling,
|
|
944
|
+
setid: circle.setid
|
|
945
|
+
})));
|
|
946
|
+
}
|
|
947
|
+
function toObjectNotation(circles) {
|
|
948
|
+
const r = {};
|
|
949
|
+
for (const circle of circles) {
|
|
950
|
+
r[circle.setid] = circle;
|
|
951
|
+
}
|
|
952
|
+
return r;
|
|
953
|
+
}
|
|
954
|
+
function fromObjectNotation(solution) {
|
|
955
|
+
const setids = Object.keys(solution);
|
|
956
|
+
return setids.map((id) => Object.assign(solution[id], { setid: id }));
|
|
957
|
+
}
|
|
958
|
+
function VennDiagram(options = {}) {
|
|
959
|
+
let useViewBox = false, width = 600, height = 350, padding = 15, duration = 1000, 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 : [
|
|
960
|
+
"#1f77b4",
|
|
961
|
+
"#ff7f0e",
|
|
962
|
+
"#2ca02c",
|
|
963
|
+
"#d62728",
|
|
964
|
+
"#9467bd",
|
|
965
|
+
"#8c564b",
|
|
966
|
+
"#e377c2",
|
|
967
|
+
"#7f7f7f",
|
|
968
|
+
"#bcbd22",
|
|
969
|
+
"#17becf"
|
|
970
|
+
], colourIndex = 0, colours = function(key) {
|
|
971
|
+
if (key in colourMap) {
|
|
972
|
+
return colourMap[key];
|
|
973
|
+
}
|
|
974
|
+
var ret = colourMap[key] = colourScheme[colourIndex];
|
|
975
|
+
colourIndex += 1;
|
|
976
|
+
if (colourIndex >= colourScheme.length) {
|
|
977
|
+
colourIndex = 0;
|
|
978
|
+
}
|
|
979
|
+
return ret;
|
|
980
|
+
}, layoutFunction = venn, loss = lossFunction;
|
|
981
|
+
function chart(selection) {
|
|
982
|
+
let data = selection.datum();
|
|
983
|
+
const toRemove = new Set;
|
|
984
|
+
data.forEach((datum) => {
|
|
985
|
+
if (datum.size == 0 && datum.sets.length == 1) {
|
|
986
|
+
toRemove.add(datum.sets[0]);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
data = data.filter((datum) => !datum.sets.some((set) => toRemove.has(set)));
|
|
990
|
+
let circles = {};
|
|
991
|
+
let textCentres = {};
|
|
992
|
+
if (data.length > 0) {
|
|
993
|
+
let solution = layoutFunction(data, { lossFunction: loss, distinct });
|
|
994
|
+
if (normalize) {
|
|
995
|
+
solution = normalizeSolution(solution, orientation, orientationOrder);
|
|
996
|
+
}
|
|
997
|
+
circles = scaleSolution(solution, width, height, padding, scaleToFit);
|
|
998
|
+
textCentres = computeTextCentres(circles, data, symmetricalTextCentre);
|
|
999
|
+
}
|
|
1000
|
+
const labels = {};
|
|
1001
|
+
data.forEach((datum) => {
|
|
1002
|
+
if (datum.label) {
|
|
1003
|
+
labels[datum.sets] = datum.label;
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
function label(d) {
|
|
1007
|
+
if (d.sets in labels) {
|
|
1008
|
+
return labels[d.sets];
|
|
1009
|
+
}
|
|
1010
|
+
if (d.sets.length == 1) {
|
|
1011
|
+
return "" + d.sets[0];
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
selection.selectAll("svg").data([circles]).enter().append("svg");
|
|
1015
|
+
const svg = selection.select("svg");
|
|
1016
|
+
if (useViewBox) {
|
|
1017
|
+
svg.attr("viewBox", `0 0 ${width} ${height}`);
|
|
1018
|
+
} else {
|
|
1019
|
+
svg.attr("width", width).attr("height", height);
|
|
1020
|
+
}
|
|
1021
|
+
const previous = {};
|
|
1022
|
+
let hasPrevious = false;
|
|
1023
|
+
svg.selectAll(".venn-area path").each(function(d) {
|
|
1024
|
+
const path = this.getAttribute("d");
|
|
1025
|
+
if (d.sets.length == 1 && path && !distinct) {
|
|
1026
|
+
hasPrevious = true;
|
|
1027
|
+
previous[d.sets[0]] = circleFromPath(path);
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
function pathTween(d) {
|
|
1031
|
+
return (t) => {
|
|
1032
|
+
const c = d.sets.map((set) => {
|
|
1033
|
+
let start = previous[set];
|
|
1034
|
+
let end = circles[set];
|
|
1035
|
+
if (!start) {
|
|
1036
|
+
start = { x: width / 2, y: height / 2, radius: 1 };
|
|
1037
|
+
}
|
|
1038
|
+
if (!end) {
|
|
1039
|
+
end = { x: width / 2, y: height / 2, radius: 1 };
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
x: start.x * (1 - t) + end.x * t,
|
|
1043
|
+
y: start.y * (1 - t) + end.y * t,
|
|
1044
|
+
radius: start.radius * (1 - t) + end.radius * t
|
|
1045
|
+
};
|
|
1046
|
+
});
|
|
1047
|
+
return intersectionAreaPath(c, round);
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
const nodes = svg.selectAll(".venn-area").data(data, (d) => d.sets);
|
|
1051
|
+
const enter = nodes.enter().append("g").attr("class", (d) => `venn-area venn-${d.sets.length == 1 ? "circle" : "intersection"}${d.colour || d.color ? " venn-coloured" : ""}`).attr("data-venn-sets", (d) => d.sets.join("_"));
|
|
1052
|
+
const enterPath = enter.append("path");
|
|
1053
|
+
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);
|
|
1054
|
+
if (styled) {
|
|
1055
|
+
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");
|
|
1056
|
+
enterText.style("fill", (d) => {
|
|
1057
|
+
if (d.colour || d.color) {
|
|
1058
|
+
return "#FFF";
|
|
1059
|
+
}
|
|
1060
|
+
if (options.textFill) {
|
|
1061
|
+
return options.textFill;
|
|
1062
|
+
}
|
|
1063
|
+
return d.sets.length == 1 ? colours(d.sets) : "#444";
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
function asTransition(s) {
|
|
1067
|
+
if (typeof s.transition === "function") {
|
|
1068
|
+
return s.transition("venn").duration(duration);
|
|
1069
|
+
}
|
|
1070
|
+
return s;
|
|
1071
|
+
}
|
|
1072
|
+
let update = selection;
|
|
1073
|
+
if (hasPrevious && typeof update.transition === "function") {
|
|
1074
|
+
update = asTransition(selection);
|
|
1075
|
+
update.selectAll("path").attrTween("d", pathTween);
|
|
1076
|
+
} else {
|
|
1077
|
+
update.selectAll("path").attr("d", (d) => intersectionAreaPath(d.sets.map((set) => circles[set])), round);
|
|
1078
|
+
}
|
|
1079
|
+
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));
|
|
1080
|
+
if (wrap) {
|
|
1081
|
+
if (hasPrevious) {
|
|
1082
|
+
if ("on" in updateText) {
|
|
1083
|
+
updateText.on("end", wrapText(circles, label));
|
|
1084
|
+
} else {
|
|
1085
|
+
updateText.each("end", wrapText(circles, label));
|
|
1086
|
+
}
|
|
1087
|
+
} else {
|
|
1088
|
+
updateText.each(wrapText(circles, label));
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
const exit = asTransition(nodes.exit()).remove();
|
|
1092
|
+
if (typeof nodes.transition === "function") {
|
|
1093
|
+
exit.selectAll("path").attrTween("d", pathTween);
|
|
1094
|
+
}
|
|
1095
|
+
const exitText = exit.selectAll("text").attr("x", width / 2).attr("y", height / 2);
|
|
1096
|
+
if (fontSize !== null) {
|
|
1097
|
+
enterText.style("font-size", "0px");
|
|
1098
|
+
updateText.style("font-size", fontSize);
|
|
1099
|
+
exitText.style("font-size", "0px");
|
|
1100
|
+
}
|
|
1101
|
+
return { circles, textCentres, nodes, enter, update, exit };
|
|
1102
|
+
}
|
|
1103
|
+
chart.wrap = function(_) {
|
|
1104
|
+
if (!arguments.length)
|
|
1105
|
+
return wrap;
|
|
1106
|
+
wrap = _;
|
|
1107
|
+
return chart;
|
|
1108
|
+
};
|
|
1109
|
+
chart.useViewBox = function() {
|
|
1110
|
+
useViewBox = true;
|
|
1111
|
+
return chart;
|
|
1112
|
+
};
|
|
1113
|
+
chart.width = function(_) {
|
|
1114
|
+
if (!arguments.length)
|
|
1115
|
+
return width;
|
|
1116
|
+
width = _;
|
|
1117
|
+
return chart;
|
|
1118
|
+
};
|
|
1119
|
+
chart.height = function(_) {
|
|
1120
|
+
if (!arguments.length)
|
|
1121
|
+
return height;
|
|
1122
|
+
height = _;
|
|
1123
|
+
return chart;
|
|
1124
|
+
};
|
|
1125
|
+
chart.padding = function(_) {
|
|
1126
|
+
if (!arguments.length)
|
|
1127
|
+
return padding;
|
|
1128
|
+
padding = _;
|
|
1129
|
+
return chart;
|
|
1130
|
+
};
|
|
1131
|
+
chart.distinct = function(_) {
|
|
1132
|
+
if (!arguments.length)
|
|
1133
|
+
return distinct;
|
|
1134
|
+
distinct = _;
|
|
1135
|
+
return chart;
|
|
1136
|
+
};
|
|
1137
|
+
chart.colours = function(_) {
|
|
1138
|
+
if (!arguments.length)
|
|
1139
|
+
return colours;
|
|
1140
|
+
colours = _;
|
|
1141
|
+
return chart;
|
|
1142
|
+
};
|
|
1143
|
+
chart.colors = function(_) {
|
|
1144
|
+
if (!arguments.length)
|
|
1145
|
+
return colours;
|
|
1146
|
+
colours = _;
|
|
1147
|
+
return chart;
|
|
1148
|
+
};
|
|
1149
|
+
chart.fontSize = function(_) {
|
|
1150
|
+
if (!arguments.length)
|
|
1151
|
+
return fontSize;
|
|
1152
|
+
fontSize = _;
|
|
1153
|
+
return chart;
|
|
1154
|
+
};
|
|
1155
|
+
chart.round = function(_) {
|
|
1156
|
+
if (!arguments.length)
|
|
1157
|
+
return round;
|
|
1158
|
+
round = _;
|
|
1159
|
+
return chart;
|
|
1160
|
+
};
|
|
1161
|
+
chart.duration = function(_) {
|
|
1162
|
+
if (!arguments.length)
|
|
1163
|
+
return duration;
|
|
1164
|
+
duration = _;
|
|
1165
|
+
return chart;
|
|
1166
|
+
};
|
|
1167
|
+
chart.layoutFunction = function(_) {
|
|
1168
|
+
if (!arguments.length)
|
|
1169
|
+
return layoutFunction;
|
|
1170
|
+
layoutFunction = _;
|
|
1171
|
+
return chart;
|
|
1172
|
+
};
|
|
1173
|
+
chart.normalize = function(_) {
|
|
1174
|
+
if (!arguments.length)
|
|
1175
|
+
return normalize;
|
|
1176
|
+
normalize = _;
|
|
1177
|
+
return chart;
|
|
1178
|
+
};
|
|
1179
|
+
chart.scaleToFit = function(_) {
|
|
1180
|
+
if (!arguments.length)
|
|
1181
|
+
return scaleToFit;
|
|
1182
|
+
scaleToFit = _;
|
|
1183
|
+
return chart;
|
|
1184
|
+
};
|
|
1185
|
+
chart.styled = function(_) {
|
|
1186
|
+
if (!arguments.length)
|
|
1187
|
+
return styled;
|
|
1188
|
+
styled = _;
|
|
1189
|
+
return chart;
|
|
1190
|
+
};
|
|
1191
|
+
chart.orientation = function(_) {
|
|
1192
|
+
if (!arguments.length)
|
|
1193
|
+
return orientation;
|
|
1194
|
+
orientation = _;
|
|
1195
|
+
return chart;
|
|
1196
|
+
};
|
|
1197
|
+
chart.orientationOrder = function(_) {
|
|
1198
|
+
if (!arguments.length)
|
|
1199
|
+
return orientationOrder;
|
|
1200
|
+
orientationOrder = _;
|
|
1201
|
+
return chart;
|
|
1202
|
+
};
|
|
1203
|
+
chart.lossFunction = function(_) {
|
|
1204
|
+
if (!arguments.length)
|
|
1205
|
+
return loss;
|
|
1206
|
+
loss = _ === "default" ? lossFunction : _ === "logRatio" ? logRatioLossFunction : _;
|
|
1207
|
+
return chart;
|
|
1208
|
+
};
|
|
1209
|
+
return chart;
|
|
1210
|
+
}
|
|
1211
|
+
function wrapText(circles, labeller) {
|
|
1212
|
+
return function(data) {
|
|
1213
|
+
const text = this;
|
|
1214
|
+
const width = circles[data.sets[0]].radius || 50;
|
|
1215
|
+
const label = labeller(data) || "";
|
|
1216
|
+
const words = label.split(/\s+/).reverse();
|
|
1217
|
+
const maxLines = 3;
|
|
1218
|
+
const minChars = (label.length + words.length) / maxLines;
|
|
1219
|
+
let word = words.pop();
|
|
1220
|
+
let line = [word];
|
|
1221
|
+
let lineNumber = 0;
|
|
1222
|
+
const lineHeight = 1.1;
|
|
1223
|
+
text.textContent = null;
|
|
1224
|
+
const tspans = [];
|
|
1225
|
+
function append(word2) {
|
|
1226
|
+
const tspan2 = text.ownerDocument.createElementNS(text.namespaceURI, "tspan");
|
|
1227
|
+
tspan2.textContent = word2;
|
|
1228
|
+
tspans.push(tspan2);
|
|
1229
|
+
text.append(tspan2);
|
|
1230
|
+
return tspan2;
|
|
1231
|
+
}
|
|
1232
|
+
let tspan = append(word);
|
|
1233
|
+
while (true) {
|
|
1234
|
+
word = words.pop();
|
|
1235
|
+
if (!word) {
|
|
1236
|
+
break;
|
|
1237
|
+
}
|
|
1238
|
+
line.push(word);
|
|
1239
|
+
const joined = line.join(" ");
|
|
1240
|
+
tspan.textContent = joined;
|
|
1241
|
+
if (joined.length > minChars && tspan.getComputedTextLength() > width) {
|
|
1242
|
+
line.pop();
|
|
1243
|
+
tspan.textContent = line.join(" ");
|
|
1244
|
+
line = [word];
|
|
1245
|
+
tspan = append(word);
|
|
1246
|
+
lineNumber++;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
const initial = 0.35 - lineNumber * lineHeight / 2;
|
|
1250
|
+
const x = text.getAttribute("x");
|
|
1251
|
+
const y = text.getAttribute("y");
|
|
1252
|
+
tspans.forEach((t, i) => {
|
|
1253
|
+
t.setAttribute("x", x);
|
|
1254
|
+
t.setAttribute("y", y);
|
|
1255
|
+
t.setAttribute("dy", `${initial + i * lineHeight}em`);
|
|
1256
|
+
});
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
function circleMargin(current, interior, exterior) {
|
|
1260
|
+
let margin = interior[0].radius - distance(interior[0], current);
|
|
1261
|
+
for (let i = 1;i < interior.length; ++i) {
|
|
1262
|
+
const m = interior[i].radius - distance(interior[i], current);
|
|
1263
|
+
if (m <= margin) {
|
|
1264
|
+
margin = m;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
for (let i = 0;i < exterior.length; ++i) {
|
|
1268
|
+
const m = distance(exterior[i], current) - exterior[i].radius;
|
|
1269
|
+
if (m <= margin) {
|
|
1270
|
+
margin = m;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
return margin;
|
|
1274
|
+
}
|
|
1275
|
+
function computeTextCentre(interior, exterior, symmetricalTextCentre) {
|
|
1276
|
+
const points = [];
|
|
1277
|
+
for (const c of interior) {
|
|
1278
|
+
points.push({ x: c.x, y: c.y });
|
|
1279
|
+
points.push({ x: c.x + c.radius / 2, y: c.y });
|
|
1280
|
+
points.push({ x: c.x - c.radius / 2, y: c.y });
|
|
1281
|
+
points.push({ x: c.x, y: c.y + c.radius / 2 });
|
|
1282
|
+
points.push({ x: c.x, y: c.y - c.radius / 2 });
|
|
1283
|
+
}
|
|
1284
|
+
let initial = points[0];
|
|
1285
|
+
let margin = circleMargin(points[0], interior, exterior);
|
|
1286
|
+
for (let i = 1;i < points.length; ++i) {
|
|
1287
|
+
const m = circleMargin(points[i], interior, exterior);
|
|
1288
|
+
if (m >= margin) {
|
|
1289
|
+
initial = points[i];
|
|
1290
|
+
margin = m;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
const solution = nelderMead((p) => -1 * circleMargin({ x: p[0], y: p[1] }, interior, exterior), [initial.x, initial.y], { maxIterations: 500, minErrorDelta: 0.0000000001 }).x;
|
|
1294
|
+
const ret = { x: symmetricalTextCentre ? 0 : solution[0], y: solution[1] };
|
|
1295
|
+
let valid = true;
|
|
1296
|
+
for (const i of interior) {
|
|
1297
|
+
if (distance(ret, i) > i.radius) {
|
|
1298
|
+
valid = false;
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
for (const e of exterior) {
|
|
1303
|
+
if (distance(ret, e) < e.radius) {
|
|
1304
|
+
valid = false;
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
if (valid) {
|
|
1309
|
+
return ret;
|
|
1310
|
+
}
|
|
1311
|
+
if (interior.length == 1) {
|
|
1312
|
+
return { x: interior[0].x, y: interior[0].y };
|
|
1313
|
+
}
|
|
1314
|
+
const areaStats = {};
|
|
1315
|
+
intersectionArea(interior, areaStats);
|
|
1316
|
+
if (areaStats.arcs.length === 0) {
|
|
1317
|
+
return { x: 0, y: -1000, disjoint: true };
|
|
1318
|
+
}
|
|
1319
|
+
if (areaStats.arcs.length == 1) {
|
|
1320
|
+
return { x: areaStats.arcs[0].circle.x, y: areaStats.arcs[0].circle.y };
|
|
1321
|
+
}
|
|
1322
|
+
if (exterior.length) {
|
|
1323
|
+
return computeTextCentre(interior, []);
|
|
1324
|
+
}
|
|
1325
|
+
return getCenter(areaStats.arcs.map((a) => a.p1));
|
|
1326
|
+
}
|
|
1327
|
+
function getOverlappingCircles(circles) {
|
|
1328
|
+
const ret = {};
|
|
1329
|
+
const circleids = Object.keys(circles);
|
|
1330
|
+
for (const circleid of circleids) {
|
|
1331
|
+
ret[circleid] = [];
|
|
1332
|
+
}
|
|
1333
|
+
for (let i = 0;i < circleids.length; i++) {
|
|
1334
|
+
const ci = circleids[i];
|
|
1335
|
+
const a = circles[ci];
|
|
1336
|
+
for (let j = i + 1;j < circleids.length; ++j) {
|
|
1337
|
+
const cj = circleids[j];
|
|
1338
|
+
const b = circles[cj];
|
|
1339
|
+
const d = distance(a, b);
|
|
1340
|
+
if (d + b.radius <= a.radius + 0.0000000001) {
|
|
1341
|
+
ret[cj].push(ci);
|
|
1342
|
+
} else if (d + a.radius <= b.radius + 0.0000000001) {
|
|
1343
|
+
ret[ci].push(cj);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
return ret;
|
|
1348
|
+
}
|
|
1349
|
+
function computeTextCentres(circles, areas, symmetricalTextCentre) {
|
|
1350
|
+
const ret = {};
|
|
1351
|
+
const overlapped = getOverlappingCircles(circles);
|
|
1352
|
+
for (let i = 0;i < areas.length; ++i) {
|
|
1353
|
+
const area = areas[i].sets;
|
|
1354
|
+
const areaids = {};
|
|
1355
|
+
const exclude = {};
|
|
1356
|
+
for (let j = 0;j < area.length; ++j) {
|
|
1357
|
+
areaids[area[j]] = true;
|
|
1358
|
+
const overlaps = overlapped[area[j]];
|
|
1359
|
+
for (let k = 0;k < overlaps.length; ++k) {
|
|
1360
|
+
exclude[overlaps[k]] = true;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
const interior = [];
|
|
1364
|
+
const exterior = [];
|
|
1365
|
+
for (let setid in circles) {
|
|
1366
|
+
if (setid in areaids) {
|
|
1367
|
+
interior.push(circles[setid]);
|
|
1368
|
+
} else if (!(setid in exclude)) {
|
|
1369
|
+
exterior.push(circles[setid]);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
const centre = computeTextCentre(interior, exterior, symmetricalTextCentre);
|
|
1373
|
+
ret[area] = centre;
|
|
1374
|
+
if (centre.disjoint && areas[i].size > 0) {
|
|
1375
|
+
console.log("WARNING: area " + area + " not represented on screen");
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return ret;
|
|
1379
|
+
}
|
|
1380
|
+
function circlePath(x, y, r) {
|
|
1381
|
+
const ret = [];
|
|
1382
|
+
ret.push(`
|
|
1383
|
+
M`, x, y);
|
|
1384
|
+
ret.push(`
|
|
1385
|
+
m`, -r, 0);
|
|
1386
|
+
ret.push(`
|
|
1387
|
+
a`, r, r, 0, 1, 0, r * 2, 0);
|
|
1388
|
+
ret.push(`
|
|
1389
|
+
a`, r, r, 0, 1, 0, -r * 2, 0);
|
|
1390
|
+
return ret.join(" ");
|
|
1391
|
+
}
|
|
1392
|
+
function circleFromPath(path) {
|
|
1393
|
+
const tokens = path.split(" ");
|
|
1394
|
+
return { x: Number.parseFloat(tokens[1]), y: Number.parseFloat(tokens[2]), radius: -Number.parseFloat(tokens[4]) };
|
|
1395
|
+
}
|
|
1396
|
+
function intersectionAreaArcs(circles) {
|
|
1397
|
+
if (circles.length === 0) {
|
|
1398
|
+
return [];
|
|
1399
|
+
}
|
|
1400
|
+
const stats = {};
|
|
1401
|
+
intersectionArea(circles, stats);
|
|
1402
|
+
return stats.arcs;
|
|
1403
|
+
}
|
|
1404
|
+
function arcsToPath(arcs, round) {
|
|
1405
|
+
if (arcs.length === 0) {
|
|
1406
|
+
return "M 0 0";
|
|
1407
|
+
}
|
|
1408
|
+
const rFactor = Math.pow(10, round || 0);
|
|
1409
|
+
const r = round != null ? (v) => Math.round(v * rFactor) / rFactor : (v) => v;
|
|
1410
|
+
if (arcs.length == 1) {
|
|
1411
|
+
const circle = arcs[0].circle;
|
|
1412
|
+
return circlePath(r(circle.x), r(circle.y), r(circle.radius));
|
|
1413
|
+
}
|
|
1414
|
+
const ret = [`
|
|
1415
|
+
M`, r(arcs[0].p2.x), r(arcs[0].p2.y)];
|
|
1416
|
+
for (const arc of arcs) {
|
|
1417
|
+
const radius = r(arc.circle.radius);
|
|
1418
|
+
ret.push(`
|
|
1419
|
+
A`, radius, radius, 0, arc.large ? 1 : 0, arc.sweep ? 1 : 0, r(arc.p1.x), r(arc.p1.y));
|
|
1420
|
+
}
|
|
1421
|
+
return ret.join(" ");
|
|
1422
|
+
}
|
|
1423
|
+
function intersectionAreaPath(circles, round) {
|
|
1424
|
+
return arcsToPath(intersectionAreaArcs(circles), round);
|
|
1425
|
+
}
|
|
1426
|
+
function layout(data, options = {}) {
|
|
1427
|
+
const {
|
|
1428
|
+
lossFunction: loss,
|
|
1429
|
+
layoutFunction: layout2 = venn,
|
|
1430
|
+
normalize = true,
|
|
1431
|
+
orientation = Math.PI / 2,
|
|
1432
|
+
orientationOrder,
|
|
1433
|
+
width = 600,
|
|
1434
|
+
height = 350,
|
|
1435
|
+
padding = 15,
|
|
1436
|
+
scaleToFit = false,
|
|
1437
|
+
symmetricalTextCentre = false,
|
|
1438
|
+
distinct,
|
|
1439
|
+
round = 2
|
|
1440
|
+
} = options;
|
|
1441
|
+
let solution = layout2(data, {
|
|
1442
|
+
lossFunction: loss === "default" || !loss ? lossFunction : loss === "logRatio" ? logRatioLossFunction : loss,
|
|
1443
|
+
distinct
|
|
1444
|
+
});
|
|
1445
|
+
if (normalize) {
|
|
1446
|
+
solution = normalizeSolution(solution, orientation, orientationOrder);
|
|
1447
|
+
}
|
|
1448
|
+
const circles = scaleSolution(solution, width, height, padding, scaleToFit);
|
|
1449
|
+
const textCentres = computeTextCentres(circles, data, symmetricalTextCentre);
|
|
1450
|
+
const circleLookup = new Map(Object.keys(circles).map((set) => [
|
|
1451
|
+
set,
|
|
1452
|
+
{
|
|
1453
|
+
set,
|
|
1454
|
+
x: circles[set].x,
|
|
1455
|
+
y: circles[set].y,
|
|
1456
|
+
radius: circles[set].radius
|
|
1457
|
+
}
|
|
1458
|
+
]));
|
|
1459
|
+
const helpers = data.map((area) => {
|
|
1460
|
+
const circles2 = area.sets.map((s) => circleLookup.get(s));
|
|
1461
|
+
const arcs = intersectionAreaArcs(circles2);
|
|
1462
|
+
const path = arcsToPath(arcs, round);
|
|
1463
|
+
return { circles: circles2, arcs, path, area, has: new Set(area.sets) };
|
|
1464
|
+
});
|
|
1465
|
+
function genDistinctPath(sets) {
|
|
1466
|
+
let r = "";
|
|
1467
|
+
for (const e of helpers) {
|
|
1468
|
+
if (e.has.size > sets.length && sets.every((s) => e.has.has(s))) {
|
|
1469
|
+
r += " " + e.path;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return r;
|
|
1473
|
+
}
|
|
1474
|
+
return helpers.map(({ circles: circles2, arcs, path, area }) => {
|
|
1475
|
+
return {
|
|
1476
|
+
data: area,
|
|
1477
|
+
text: textCentres[area.sets],
|
|
1478
|
+
circles: circles2,
|
|
1479
|
+
arcs,
|
|
1480
|
+
path,
|
|
1481
|
+
distinctPath: path + genDistinctPath(area.sets)
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
// node_modules/mermaid/dist/chunks/mermaid.core/vennDiagram-T6HMQDX7.mjs
|
|
1487
|
+
var parser = function() {
|
|
1488
|
+
var o = /* @__PURE__ */ __name(function(k, v, o2, l) {
|
|
1489
|
+
for (o2 = o2 || {}, l = k.length;l--; o2[k[l]] = v)
|
|
1490
|
+
;
|
|
1491
|
+
return o2;
|
|
1492
|
+
}, "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];
|
|
1493
|
+
var parser2 = {
|
|
1494
|
+
trace: /* @__PURE__ */ __name(function trace() {}, "trace"),
|
|
1495
|
+
yy: {},
|
|
1496
|
+
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 },
|
|
1497
|
+
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" },
|
|
1498
|
+
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]],
|
|
1499
|
+
performAction: /* @__PURE__ */ __name(function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
|
|
1500
|
+
var $0 = $$.length - 1;
|
|
1501
|
+
switch (yystate) {
|
|
1502
|
+
case 1:
|
|
1503
|
+
return $$[$0 - 1];
|
|
1504
|
+
break;
|
|
1505
|
+
case 2:
|
|
1506
|
+
case 3:
|
|
1507
|
+
case 4:
|
|
1508
|
+
this.$ = [];
|
|
1509
|
+
break;
|
|
1510
|
+
case 5:
|
|
1511
|
+
$$[$0 - 1].push($$[$0]);
|
|
1512
|
+
this.$ = $$[$0 - 1];
|
|
1513
|
+
break;
|
|
1514
|
+
case 6:
|
|
1515
|
+
this.$ = [];
|
|
1516
|
+
break;
|
|
1517
|
+
case 7:
|
|
1518
|
+
case 22:
|
|
1519
|
+
case 32:
|
|
1520
|
+
case 36:
|
|
1521
|
+
case 37:
|
|
1522
|
+
case 38:
|
|
1523
|
+
case 39:
|
|
1524
|
+
case 40:
|
|
1525
|
+
this.$ = $$[$0];
|
|
1526
|
+
break;
|
|
1527
|
+
case 8:
|
|
1528
|
+
yy.setDiagramTitle($$[$0].substr(6));
|
|
1529
|
+
this.$ = $$[$0].substr(6);
|
|
1530
|
+
break;
|
|
1531
|
+
case 9:
|
|
1532
|
+
yy.addSubsetData([$$[$0]], undefined, undefined);
|
|
1533
|
+
if (yy.setIndentMode) {
|
|
1534
|
+
yy.setIndentMode(true);
|
|
1535
|
+
}
|
|
1536
|
+
break;
|
|
1537
|
+
case 10:
|
|
1538
|
+
yy.addSubsetData([$$[$0 - 1]], $$[$0], undefined);
|
|
1539
|
+
if (yy.setIndentMode) {
|
|
1540
|
+
yy.setIndentMode(true);
|
|
1541
|
+
}
|
|
1542
|
+
break;
|
|
1543
|
+
case 11:
|
|
1544
|
+
yy.addSubsetData([$$[$0 - 2]], undefined, parseFloat($$[$0]));
|
|
1545
|
+
if (yy.setIndentMode) {
|
|
1546
|
+
yy.setIndentMode(true);
|
|
1547
|
+
}
|
|
1548
|
+
break;
|
|
1549
|
+
case 12:
|
|
1550
|
+
yy.addSubsetData([$$[$0 - 3]], $$[$0 - 2], parseFloat($$[$0]));
|
|
1551
|
+
if (yy.setIndentMode) {
|
|
1552
|
+
yy.setIndentMode(true);
|
|
1553
|
+
}
|
|
1554
|
+
break;
|
|
1555
|
+
case 13:
|
|
1556
|
+
if ($$[$0].length < 2) {
|
|
1557
|
+
throw new Error("union requires multiple identifiers");
|
|
1558
|
+
}
|
|
1559
|
+
if (yy.validateUnionIdentifiers) {
|
|
1560
|
+
yy.validateUnionIdentifiers($$[$0]);
|
|
1561
|
+
}
|
|
1562
|
+
yy.addSubsetData($$[$0], undefined, undefined);
|
|
1563
|
+
if (yy.setIndentMode) {
|
|
1564
|
+
yy.setIndentMode(true);
|
|
1565
|
+
}
|
|
1566
|
+
break;
|
|
1567
|
+
case 14:
|
|
1568
|
+
if ($$[$0 - 1].length < 2) {
|
|
1569
|
+
throw new Error("union requires multiple identifiers");
|
|
1570
|
+
}
|
|
1571
|
+
if (yy.validateUnionIdentifiers) {
|
|
1572
|
+
yy.validateUnionIdentifiers($$[$0 - 1]);
|
|
1573
|
+
}
|
|
1574
|
+
yy.addSubsetData($$[$0 - 1], $$[$0], undefined);
|
|
1575
|
+
if (yy.setIndentMode) {
|
|
1576
|
+
yy.setIndentMode(true);
|
|
1577
|
+
}
|
|
1578
|
+
break;
|
|
1579
|
+
case 15:
|
|
1580
|
+
if ($$[$0 - 2].length < 2) {
|
|
1581
|
+
throw new Error("union requires multiple identifiers");
|
|
1582
|
+
}
|
|
1583
|
+
if (yy.validateUnionIdentifiers) {
|
|
1584
|
+
yy.validateUnionIdentifiers($$[$0 - 2]);
|
|
1585
|
+
}
|
|
1586
|
+
yy.addSubsetData($$[$0 - 2], undefined, parseFloat($$[$0]));
|
|
1587
|
+
if (yy.setIndentMode) {
|
|
1588
|
+
yy.setIndentMode(true);
|
|
1589
|
+
}
|
|
1590
|
+
break;
|
|
1591
|
+
case 16:
|
|
1592
|
+
if ($$[$0 - 3].length < 2) {
|
|
1593
|
+
throw new Error("union requires multiple identifiers");
|
|
1594
|
+
}
|
|
1595
|
+
if (yy.validateUnionIdentifiers) {
|
|
1596
|
+
yy.validateUnionIdentifiers($$[$0 - 3]);
|
|
1597
|
+
}
|
|
1598
|
+
yy.addSubsetData($$[$0 - 3], $$[$0 - 2], parseFloat($$[$0]));
|
|
1599
|
+
if (yy.setIndentMode) {
|
|
1600
|
+
yy.setIndentMode(true);
|
|
1601
|
+
}
|
|
1602
|
+
break;
|
|
1603
|
+
case 17:
|
|
1604
|
+
case 18:
|
|
1605
|
+
case 19:
|
|
1606
|
+
yy.addTextData($$[$0 - 1], $$[$0], undefined);
|
|
1607
|
+
break;
|
|
1608
|
+
case 20:
|
|
1609
|
+
case 21:
|
|
1610
|
+
yy.addTextData($$[$0 - 2], $$[$0 - 1], $$[$0]);
|
|
1611
|
+
break;
|
|
1612
|
+
case 23:
|
|
1613
|
+
yy.addStyleData($$[$0 - 1], $$[$0]);
|
|
1614
|
+
break;
|
|
1615
|
+
case 24:
|
|
1616
|
+
case 25:
|
|
1617
|
+
case 26:
|
|
1618
|
+
var cs = yy.getCurrentSets();
|
|
1619
|
+
if (!cs)
|
|
1620
|
+
throw new Error("text requires set");
|
|
1621
|
+
yy.addTextData(cs, $$[$0], undefined);
|
|
1622
|
+
break;
|
|
1623
|
+
case 27:
|
|
1624
|
+
case 28:
|
|
1625
|
+
var cs = yy.getCurrentSets();
|
|
1626
|
+
if (!cs)
|
|
1627
|
+
throw new Error("text requires set");
|
|
1628
|
+
yy.addTextData(cs, $$[$0 - 1], $$[$0]);
|
|
1629
|
+
break;
|
|
1630
|
+
case 29:
|
|
1631
|
+
case 41:
|
|
1632
|
+
this.$ = [$$[$0]];
|
|
1633
|
+
break;
|
|
1634
|
+
case 30:
|
|
1635
|
+
case 42:
|
|
1636
|
+
this.$ = [...$$[$0 - 2], $$[$0]];
|
|
1637
|
+
break;
|
|
1638
|
+
case 31:
|
|
1639
|
+
this.$ = [$$[$0 - 2], $$[$0]];
|
|
1640
|
+
break;
|
|
1641
|
+
case 33:
|
|
1642
|
+
this.$ = $$[$0].join(" ");
|
|
1643
|
+
break;
|
|
1644
|
+
case 34:
|
|
1645
|
+
this.$ = [$$[$0]];
|
|
1646
|
+
break;
|
|
1647
|
+
case 35:
|
|
1648
|
+
$$[$0 - 1].push($$[$0]);
|
|
1649
|
+
this.$ = $$[$0 - 1];
|
|
1650
|
+
break;
|
|
1651
|
+
case 43:
|
|
1652
|
+
case 44:
|
|
1653
|
+
this.$ = $$[$0];
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
}, "anonymous"),
|
|
1657
|
+
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])],
|
|
1658
|
+
defaultActions: { 6: [2, 1] },
|
|
1659
|
+
parseError: /* @__PURE__ */ __name(function parseError(str, hash) {
|
|
1660
|
+
if (hash.recoverable) {
|
|
1661
|
+
this.trace(str);
|
|
1662
|
+
} else {
|
|
1663
|
+
var error = new Error(str);
|
|
1664
|
+
error.hash = hash;
|
|
1665
|
+
throw error;
|
|
1666
|
+
}
|
|
1667
|
+
}, "parseError"),
|
|
1668
|
+
parse: /* @__PURE__ */ __name(function parse(input) {
|
|
1669
|
+
var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
|
|
1670
|
+
var args = lstack.slice.call(arguments, 1);
|
|
1671
|
+
var lexer2 = Object.create(this.lexer);
|
|
1672
|
+
var sharedState = { yy: {} };
|
|
1673
|
+
for (var k in this.yy) {
|
|
1674
|
+
if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
|
|
1675
|
+
sharedState.yy[k] = this.yy[k];
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
lexer2.setInput(input, sharedState.yy);
|
|
1679
|
+
sharedState.yy.lexer = lexer2;
|
|
1680
|
+
sharedState.yy.parser = this;
|
|
1681
|
+
if (typeof lexer2.yylloc == "undefined") {
|
|
1682
|
+
lexer2.yylloc = {};
|
|
1683
|
+
}
|
|
1684
|
+
var yyloc = lexer2.yylloc;
|
|
1685
|
+
lstack.push(yyloc);
|
|
1686
|
+
var ranges = lexer2.options && lexer2.options.ranges;
|
|
1687
|
+
if (typeof sharedState.yy.parseError === "function") {
|
|
1688
|
+
this.parseError = sharedState.yy.parseError;
|
|
1689
|
+
} else {
|
|
1690
|
+
this.parseError = Object.getPrototypeOf(this).parseError;
|
|
1691
|
+
}
|
|
1692
|
+
function popStack(n) {
|
|
1693
|
+
stack.length = stack.length - 2 * n;
|
|
1694
|
+
vstack.length = vstack.length - n;
|
|
1695
|
+
lstack.length = lstack.length - n;
|
|
1696
|
+
}
|
|
1697
|
+
__name(popStack, "popStack");
|
|
1698
|
+
function lex() {
|
|
1699
|
+
var token;
|
|
1700
|
+
token = tstack.pop() || lexer2.lex() || EOF;
|
|
1701
|
+
if (typeof token !== "number") {
|
|
1702
|
+
if (token instanceof Array) {
|
|
1703
|
+
tstack = token;
|
|
1704
|
+
token = tstack.pop();
|
|
1705
|
+
}
|
|
1706
|
+
token = self.symbols_[token] || token;
|
|
1707
|
+
}
|
|
1708
|
+
return token;
|
|
1709
|
+
}
|
|
1710
|
+
__name(lex, "lex");
|
|
1711
|
+
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
|
|
1712
|
+
while (true) {
|
|
1713
|
+
state = stack[stack.length - 1];
|
|
1714
|
+
if (this.defaultActions[state]) {
|
|
1715
|
+
action = this.defaultActions[state];
|
|
1716
|
+
} else {
|
|
1717
|
+
if (symbol === null || typeof symbol == "undefined") {
|
|
1718
|
+
symbol = lex();
|
|
1719
|
+
}
|
|
1720
|
+
action = table[state] && table[state][symbol];
|
|
1721
|
+
}
|
|
1722
|
+
if (typeof action === "undefined" || !action.length || !action[0]) {
|
|
1723
|
+
var errStr = "";
|
|
1724
|
+
expected = [];
|
|
1725
|
+
for (p in table[state]) {
|
|
1726
|
+
if (this.terminals_[p] && p > TERROR) {
|
|
1727
|
+
expected.push("'" + this.terminals_[p] + "'");
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
if (lexer2.showPosition) {
|
|
1731
|
+
errStr = "Parse error on line " + (yylineno + 1) + `:
|
|
1732
|
+
` + lexer2.showPosition() + `
|
|
1733
|
+
Expecting ` + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
|
|
1734
|
+
} else {
|
|
1735
|
+
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
|
|
1736
|
+
}
|
|
1737
|
+
this.parseError(errStr, {
|
|
1738
|
+
text: lexer2.match,
|
|
1739
|
+
token: this.terminals_[symbol] || symbol,
|
|
1740
|
+
line: lexer2.yylineno,
|
|
1741
|
+
loc: yyloc,
|
|
1742
|
+
expected
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
if (action[0] instanceof Array && action.length > 1) {
|
|
1746
|
+
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
|
|
1747
|
+
}
|
|
1748
|
+
switch (action[0]) {
|
|
1749
|
+
case 1:
|
|
1750
|
+
stack.push(symbol);
|
|
1751
|
+
vstack.push(lexer2.yytext);
|
|
1752
|
+
lstack.push(lexer2.yylloc);
|
|
1753
|
+
stack.push(action[1]);
|
|
1754
|
+
symbol = null;
|
|
1755
|
+
if (!preErrorSymbol) {
|
|
1756
|
+
yyleng = lexer2.yyleng;
|
|
1757
|
+
yytext = lexer2.yytext;
|
|
1758
|
+
yylineno = lexer2.yylineno;
|
|
1759
|
+
yyloc = lexer2.yylloc;
|
|
1760
|
+
if (recovering > 0) {
|
|
1761
|
+
recovering--;
|
|
1762
|
+
}
|
|
1763
|
+
} else {
|
|
1764
|
+
symbol = preErrorSymbol;
|
|
1765
|
+
preErrorSymbol = null;
|
|
1766
|
+
}
|
|
1767
|
+
break;
|
|
1768
|
+
case 2:
|
|
1769
|
+
len = this.productions_[action[1]][1];
|
|
1770
|
+
yyval.$ = vstack[vstack.length - len];
|
|
1771
|
+
yyval._$ = {
|
|
1772
|
+
first_line: lstack[lstack.length - (len || 1)].first_line,
|
|
1773
|
+
last_line: lstack[lstack.length - 1].last_line,
|
|
1774
|
+
first_column: lstack[lstack.length - (len || 1)].first_column,
|
|
1775
|
+
last_column: lstack[lstack.length - 1].last_column
|
|
1776
|
+
};
|
|
1777
|
+
if (ranges) {
|
|
1778
|
+
yyval._$.range = [
|
|
1779
|
+
lstack[lstack.length - (len || 1)].range[0],
|
|
1780
|
+
lstack[lstack.length - 1].range[1]
|
|
1781
|
+
];
|
|
1782
|
+
}
|
|
1783
|
+
r = this.performAction.apply(yyval, [
|
|
1784
|
+
yytext,
|
|
1785
|
+
yyleng,
|
|
1786
|
+
yylineno,
|
|
1787
|
+
sharedState.yy,
|
|
1788
|
+
action[1],
|
|
1789
|
+
vstack,
|
|
1790
|
+
lstack
|
|
1791
|
+
].concat(args));
|
|
1792
|
+
if (typeof r !== "undefined") {
|
|
1793
|
+
return r;
|
|
1794
|
+
}
|
|
1795
|
+
if (len) {
|
|
1796
|
+
stack = stack.slice(0, -1 * len * 2);
|
|
1797
|
+
vstack = vstack.slice(0, -1 * len);
|
|
1798
|
+
lstack = lstack.slice(0, -1 * len);
|
|
1799
|
+
}
|
|
1800
|
+
stack.push(this.productions_[action[1]][0]);
|
|
1801
|
+
vstack.push(yyval.$);
|
|
1802
|
+
lstack.push(yyval._$);
|
|
1803
|
+
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
|
|
1804
|
+
stack.push(newState);
|
|
1805
|
+
break;
|
|
1806
|
+
case 3:
|
|
1807
|
+
return true;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
return true;
|
|
1811
|
+
}, "parse")
|
|
1812
|
+
};
|
|
1813
|
+
var lexer = /* @__PURE__ */ function() {
|
|
1814
|
+
var lexer2 = {
|
|
1815
|
+
EOF: 1,
|
|
1816
|
+
parseError: /* @__PURE__ */ __name(function parseError(str, hash) {
|
|
1817
|
+
if (this.yy.parser) {
|
|
1818
|
+
this.yy.parser.parseError(str, hash);
|
|
1819
|
+
} else {
|
|
1820
|
+
throw new Error(str);
|
|
1821
|
+
}
|
|
1822
|
+
}, "parseError"),
|
|
1823
|
+
setInput: /* @__PURE__ */ __name(function(input, yy) {
|
|
1824
|
+
this.yy = yy || this.yy || {};
|
|
1825
|
+
this._input = input;
|
|
1826
|
+
this._more = this._backtrack = this.done = false;
|
|
1827
|
+
this.yylineno = this.yyleng = 0;
|
|
1828
|
+
this.yytext = this.matched = this.match = "";
|
|
1829
|
+
this.conditionStack = ["INITIAL"];
|
|
1830
|
+
this.yylloc = {
|
|
1831
|
+
first_line: 1,
|
|
1832
|
+
first_column: 0,
|
|
1833
|
+
last_line: 1,
|
|
1834
|
+
last_column: 0
|
|
1835
|
+
};
|
|
1836
|
+
if (this.options.ranges) {
|
|
1837
|
+
this.yylloc.range = [0, 0];
|
|
1838
|
+
}
|
|
1839
|
+
this.offset = 0;
|
|
1840
|
+
return this;
|
|
1841
|
+
}, "setInput"),
|
|
1842
|
+
input: /* @__PURE__ */ __name(function() {
|
|
1843
|
+
var ch = this._input[0];
|
|
1844
|
+
this.yytext += ch;
|
|
1845
|
+
this.yyleng++;
|
|
1846
|
+
this.offset++;
|
|
1847
|
+
this.match += ch;
|
|
1848
|
+
this.matched += ch;
|
|
1849
|
+
var lines = ch.match(/(?:\r\n?|\n).*/g);
|
|
1850
|
+
if (lines) {
|
|
1851
|
+
this.yylineno++;
|
|
1852
|
+
this.yylloc.last_line++;
|
|
1853
|
+
} else {
|
|
1854
|
+
this.yylloc.last_column++;
|
|
1855
|
+
}
|
|
1856
|
+
if (this.options.ranges) {
|
|
1857
|
+
this.yylloc.range[1]++;
|
|
1858
|
+
}
|
|
1859
|
+
this._input = this._input.slice(1);
|
|
1860
|
+
return ch;
|
|
1861
|
+
}, "input"),
|
|
1862
|
+
unput: /* @__PURE__ */ __name(function(ch) {
|
|
1863
|
+
var len = ch.length;
|
|
1864
|
+
var lines = ch.split(/(?:\r\n?|\n)/g);
|
|
1865
|
+
this._input = ch + this._input;
|
|
1866
|
+
this.yytext = this.yytext.substr(0, this.yytext.length - len);
|
|
1867
|
+
this.offset -= len;
|
|
1868
|
+
var oldLines = this.match.split(/(?:\r\n?|\n)/g);
|
|
1869
|
+
this.match = this.match.substr(0, this.match.length - 1);
|
|
1870
|
+
this.matched = this.matched.substr(0, this.matched.length - 1);
|
|
1871
|
+
if (lines.length - 1) {
|
|
1872
|
+
this.yylineno -= lines.length - 1;
|
|
1873
|
+
}
|
|
1874
|
+
var r = this.yylloc.range;
|
|
1875
|
+
this.yylloc = {
|
|
1876
|
+
first_line: this.yylloc.first_line,
|
|
1877
|
+
last_line: this.yylineno + 1,
|
|
1878
|
+
first_column: this.yylloc.first_column,
|
|
1879
|
+
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
|
|
1880
|
+
};
|
|
1881
|
+
if (this.options.ranges) {
|
|
1882
|
+
this.yylloc.range = [r[0], r[0] + this.yyleng - len];
|
|
1883
|
+
}
|
|
1884
|
+
this.yyleng = this.yytext.length;
|
|
1885
|
+
return this;
|
|
1886
|
+
}, "unput"),
|
|
1887
|
+
more: /* @__PURE__ */ __name(function() {
|
|
1888
|
+
this._more = true;
|
|
1889
|
+
return this;
|
|
1890
|
+
}, "more"),
|
|
1891
|
+
reject: /* @__PURE__ */ __name(function() {
|
|
1892
|
+
if (this.options.backtrack_lexer) {
|
|
1893
|
+
this._backtrack = true;
|
|
1894
|
+
} else {
|
|
1895
|
+
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).
|
|
1896
|
+
` + this.showPosition(), {
|
|
1897
|
+
text: "",
|
|
1898
|
+
token: null,
|
|
1899
|
+
line: this.yylineno
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
return this;
|
|
1903
|
+
}, "reject"),
|
|
1904
|
+
less: /* @__PURE__ */ __name(function(n) {
|
|
1905
|
+
this.unput(this.match.slice(n));
|
|
1906
|
+
}, "less"),
|
|
1907
|
+
pastInput: /* @__PURE__ */ __name(function() {
|
|
1908
|
+
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
|
1909
|
+
return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
|
|
1910
|
+
}, "pastInput"),
|
|
1911
|
+
upcomingInput: /* @__PURE__ */ __name(function() {
|
|
1912
|
+
var next = this.match;
|
|
1913
|
+
if (next.length < 20) {
|
|
1914
|
+
next += this._input.substr(0, 20 - next.length);
|
|
1915
|
+
}
|
|
1916
|
+
return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
|
|
1917
|
+
}, "upcomingInput"),
|
|
1918
|
+
showPosition: /* @__PURE__ */ __name(function() {
|
|
1919
|
+
var pre = this.pastInput();
|
|
1920
|
+
var c = new Array(pre.length + 1).join("-");
|
|
1921
|
+
return pre + this.upcomingInput() + `
|
|
1922
|
+
` + c + "^";
|
|
1923
|
+
}, "showPosition"),
|
|
1924
|
+
test_match: /* @__PURE__ */ __name(function(match, indexed_rule) {
|
|
1925
|
+
var token, lines, backup;
|
|
1926
|
+
if (this.options.backtrack_lexer) {
|
|
1927
|
+
backup = {
|
|
1928
|
+
yylineno: this.yylineno,
|
|
1929
|
+
yylloc: {
|
|
1930
|
+
first_line: this.yylloc.first_line,
|
|
1931
|
+
last_line: this.last_line,
|
|
1932
|
+
first_column: this.yylloc.first_column,
|
|
1933
|
+
last_column: this.yylloc.last_column
|
|
1934
|
+
},
|
|
1935
|
+
yytext: this.yytext,
|
|
1936
|
+
match: this.match,
|
|
1937
|
+
matches: this.matches,
|
|
1938
|
+
matched: this.matched,
|
|
1939
|
+
yyleng: this.yyleng,
|
|
1940
|
+
offset: this.offset,
|
|
1941
|
+
_more: this._more,
|
|
1942
|
+
_input: this._input,
|
|
1943
|
+
yy: this.yy,
|
|
1944
|
+
conditionStack: this.conditionStack.slice(0),
|
|
1945
|
+
done: this.done
|
|
1946
|
+
};
|
|
1947
|
+
if (this.options.ranges) {
|
|
1948
|
+
backup.yylloc.range = this.yylloc.range.slice(0);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
lines = match[0].match(/(?:\r\n?|\n).*/g);
|
|
1952
|
+
if (lines) {
|
|
1953
|
+
this.yylineno += lines.length;
|
|
1954
|
+
}
|
|
1955
|
+
this.yylloc = {
|
|
1956
|
+
first_line: this.yylloc.last_line,
|
|
1957
|
+
last_line: this.yylineno + 1,
|
|
1958
|
+
first_column: this.yylloc.last_column,
|
|
1959
|
+
last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
|
|
1960
|
+
};
|
|
1961
|
+
this.yytext += match[0];
|
|
1962
|
+
this.match += match[0];
|
|
1963
|
+
this.matches = match;
|
|
1964
|
+
this.yyleng = this.yytext.length;
|
|
1965
|
+
if (this.options.ranges) {
|
|
1966
|
+
this.yylloc.range = [this.offset, this.offset += this.yyleng];
|
|
1967
|
+
}
|
|
1968
|
+
this._more = false;
|
|
1969
|
+
this._backtrack = false;
|
|
1970
|
+
this._input = this._input.slice(match[0].length);
|
|
1971
|
+
this.matched += match[0];
|
|
1972
|
+
token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
|
|
1973
|
+
if (this.done && this._input) {
|
|
1974
|
+
this.done = false;
|
|
1975
|
+
}
|
|
1976
|
+
if (token) {
|
|
1977
|
+
return token;
|
|
1978
|
+
} else if (this._backtrack) {
|
|
1979
|
+
for (var k in backup) {
|
|
1980
|
+
this[k] = backup[k];
|
|
1981
|
+
}
|
|
1982
|
+
return false;
|
|
1983
|
+
}
|
|
1984
|
+
return false;
|
|
1985
|
+
}, "test_match"),
|
|
1986
|
+
next: /* @__PURE__ */ __name(function() {
|
|
1987
|
+
if (this.done) {
|
|
1988
|
+
return this.EOF;
|
|
1989
|
+
}
|
|
1990
|
+
if (!this._input) {
|
|
1991
|
+
this.done = true;
|
|
1992
|
+
}
|
|
1993
|
+
var token, match, tempMatch, index;
|
|
1994
|
+
if (!this._more) {
|
|
1995
|
+
this.yytext = "";
|
|
1996
|
+
this.match = "";
|
|
1997
|
+
}
|
|
1998
|
+
var rules = this._currentRules();
|
|
1999
|
+
for (var i = 0;i < rules.length; i++) {
|
|
2000
|
+
tempMatch = this._input.match(this.rules[rules[i]]);
|
|
2001
|
+
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
|
2002
|
+
match = tempMatch;
|
|
2003
|
+
index = i;
|
|
2004
|
+
if (this.options.backtrack_lexer) {
|
|
2005
|
+
token = this.test_match(tempMatch, rules[i]);
|
|
2006
|
+
if (token !== false) {
|
|
2007
|
+
return token;
|
|
2008
|
+
} else if (this._backtrack) {
|
|
2009
|
+
match = false;
|
|
2010
|
+
continue;
|
|
2011
|
+
} else {
|
|
2012
|
+
return false;
|
|
2013
|
+
}
|
|
2014
|
+
} else if (!this.options.flex) {
|
|
2015
|
+
break;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
if (match) {
|
|
2020
|
+
token = this.test_match(match, rules[index]);
|
|
2021
|
+
if (token !== false) {
|
|
2022
|
+
return token;
|
|
2023
|
+
}
|
|
2024
|
+
return false;
|
|
2025
|
+
}
|
|
2026
|
+
if (this._input === "") {
|
|
2027
|
+
return this.EOF;
|
|
2028
|
+
} else {
|
|
2029
|
+
return this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
|
|
2030
|
+
` + this.showPosition(), {
|
|
2031
|
+
text: "",
|
|
2032
|
+
token: null,
|
|
2033
|
+
line: this.yylineno
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
}, "next"),
|
|
2037
|
+
lex: /* @__PURE__ */ __name(function lex() {
|
|
2038
|
+
var r = this.next();
|
|
2039
|
+
if (r) {
|
|
2040
|
+
return r;
|
|
2041
|
+
} else {
|
|
2042
|
+
return this.lex();
|
|
2043
|
+
}
|
|
2044
|
+
}, "lex"),
|
|
2045
|
+
begin: /* @__PURE__ */ __name(function begin(condition) {
|
|
2046
|
+
this.conditionStack.push(condition);
|
|
2047
|
+
}, "begin"),
|
|
2048
|
+
popState: /* @__PURE__ */ __name(function popState() {
|
|
2049
|
+
var n = this.conditionStack.length - 1;
|
|
2050
|
+
if (n > 0) {
|
|
2051
|
+
return this.conditionStack.pop();
|
|
2052
|
+
} else {
|
|
2053
|
+
return this.conditionStack[0];
|
|
2054
|
+
}
|
|
2055
|
+
}, "popState"),
|
|
2056
|
+
_currentRules: /* @__PURE__ */ __name(function _currentRules() {
|
|
2057
|
+
if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
|
|
2058
|
+
return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
|
|
2059
|
+
} else {
|
|
2060
|
+
return this.conditions["INITIAL"].rules;
|
|
2061
|
+
}
|
|
2062
|
+
}, "_currentRules"),
|
|
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
|
+
pushState: /* @__PURE__ */ __name(function pushState(condition) {
|
|
2072
|
+
this.begin(condition);
|
|
2073
|
+
}, "pushState"),
|
|
2074
|
+
stateStackSize: /* @__PURE__ */ __name(function stateStackSize() {
|
|
2075
|
+
return this.conditionStack.length;
|
|
2076
|
+
}, "stateStackSize"),
|
|
2077
|
+
options: { "case-insensitive": true },
|
|
2078
|
+
performAction: /* @__PURE__ */ __name(function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
|
|
2079
|
+
var YYSTATE = YY_START;
|
|
2080
|
+
switch ($avoiding_name_collisions) {
|
|
2081
|
+
case 0:
|
|
2082
|
+
break;
|
|
2083
|
+
case 1:
|
|
2084
|
+
break;
|
|
2085
|
+
case 2:
|
|
2086
|
+
break;
|
|
2087
|
+
case 3:
|
|
2088
|
+
if (yy.getIndentMode && yy.getIndentMode()) {
|
|
2089
|
+
yy.consumeIndentText = true;
|
|
2090
|
+
this.begin("INITIAL");
|
|
2091
|
+
return 22;
|
|
2092
|
+
}
|
|
2093
|
+
break;
|
|
2094
|
+
case 4:
|
|
2095
|
+
break;
|
|
2096
|
+
case 5:
|
|
2097
|
+
if (yy.setIndentMode) {
|
|
2098
|
+
yy.setIndentMode(false);
|
|
2099
|
+
}
|
|
2100
|
+
this.begin("INITIAL");
|
|
2101
|
+
this.unput(yy_.yytext);
|
|
2102
|
+
break;
|
|
2103
|
+
case 6:
|
|
2104
|
+
this.begin("bol");
|
|
2105
|
+
return 8;
|
|
2106
|
+
break;
|
|
2107
|
+
case 7:
|
|
2108
|
+
break;
|
|
2109
|
+
case 8:
|
|
2110
|
+
break;
|
|
2111
|
+
case 9:
|
|
2112
|
+
return 7;
|
|
2113
|
+
break;
|
|
2114
|
+
case 10:
|
|
2115
|
+
return 11;
|
|
2116
|
+
break;
|
|
2117
|
+
case 11:
|
|
2118
|
+
return 5;
|
|
2119
|
+
break;
|
|
2120
|
+
case 12:
|
|
2121
|
+
return 12;
|
|
2122
|
+
break;
|
|
2123
|
+
case 13:
|
|
2124
|
+
return 17;
|
|
2125
|
+
break;
|
|
2126
|
+
case 14:
|
|
2127
|
+
if (yy.consumeIndentText) {
|
|
2128
|
+
yy.consumeIndentText = false;
|
|
2129
|
+
} else {
|
|
2130
|
+
return 19;
|
|
2131
|
+
}
|
|
2132
|
+
break;
|
|
2133
|
+
case 15:
|
|
2134
|
+
return 24;
|
|
2135
|
+
break;
|
|
2136
|
+
case 16:
|
|
2137
|
+
yy_.yytext = yy_.yytext.slice(2, -2);
|
|
2138
|
+
return 14;
|
|
2139
|
+
break;
|
|
2140
|
+
case 17:
|
|
2141
|
+
yy_.yytext = yy_.yytext.slice(1, -1).trim();
|
|
2142
|
+
return 14;
|
|
2143
|
+
break;
|
|
2144
|
+
case 18:
|
|
2145
|
+
return 16;
|
|
2146
|
+
break;
|
|
2147
|
+
case 19:
|
|
2148
|
+
return 31;
|
|
2149
|
+
break;
|
|
2150
|
+
case 20:
|
|
2151
|
+
return 33;
|
|
2152
|
+
break;
|
|
2153
|
+
case 21:
|
|
2154
|
+
return 32;
|
|
2155
|
+
break;
|
|
2156
|
+
case 22:
|
|
2157
|
+
return 20;
|
|
2158
|
+
break;
|
|
2159
|
+
case 23:
|
|
2160
|
+
return 21;
|
|
2161
|
+
break;
|
|
2162
|
+
case 24:
|
|
2163
|
+
return 27;
|
|
2164
|
+
break;
|
|
2165
|
+
case 25:
|
|
2166
|
+
return 15;
|
|
2167
|
+
break;
|
|
2168
|
+
}
|
|
2169
|
+
}, "anonymous"),
|
|
2170
|
+
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],
|
|
2171
|
+
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 } }
|
|
2172
|
+
};
|
|
2173
|
+
return lexer2;
|
|
2174
|
+
}();
|
|
2175
|
+
parser2.lexer = lexer;
|
|
2176
|
+
function Parser() {
|
|
2177
|
+
this.yy = {};
|
|
2178
|
+
}
|
|
2179
|
+
__name(Parser, "Parser");
|
|
2180
|
+
Parser.prototype = parser2;
|
|
2181
|
+
parser2.Parser = Parser;
|
|
2182
|
+
return new Parser;
|
|
2183
|
+
}();
|
|
2184
|
+
parser.parser = parser;
|
|
2185
|
+
var venn_default = parser;
|
|
2186
|
+
var subsets = [];
|
|
2187
|
+
var textNodes = [];
|
|
2188
|
+
var styleEntries = [];
|
|
2189
|
+
var knownSets = /* @__PURE__ */ new Set;
|
|
2190
|
+
var currentSets;
|
|
2191
|
+
var indentMode = false;
|
|
2192
|
+
var addSubsetData = /* @__PURE__ */ __name((identifierList, label, size) => {
|
|
2193
|
+
const sets = normalizeIdentifierList(identifierList).sort();
|
|
2194
|
+
const resolvedSize = size ?? 10 / Math.pow(identifierList.length, 2);
|
|
2195
|
+
currentSets = sets;
|
|
2196
|
+
if (sets.length === 1) {
|
|
2197
|
+
knownSets.add(sets[0]);
|
|
2198
|
+
}
|
|
2199
|
+
subsets.push({
|
|
2200
|
+
sets,
|
|
2201
|
+
size: resolvedSize,
|
|
2202
|
+
label: label ? normalizeText(label) : undefined
|
|
2203
|
+
});
|
|
2204
|
+
}, "addSubsetData");
|
|
2205
|
+
var getSubsetData = /* @__PURE__ */ __name(() => {
|
|
2206
|
+
return subsets;
|
|
2207
|
+
}, "getSubsetData");
|
|
2208
|
+
var normalizeText = /* @__PURE__ */ __name((text) => {
|
|
2209
|
+
const trimmed = text.trim();
|
|
2210
|
+
if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
2211
|
+
return trimmed.slice(1, -1);
|
|
2212
|
+
}
|
|
2213
|
+
return trimmed;
|
|
2214
|
+
}, "normalizeText");
|
|
2215
|
+
var normalizeStyleValue = /* @__PURE__ */ __name((value) => {
|
|
2216
|
+
return value ? normalizeText(value) : value;
|
|
2217
|
+
}, "normalizeStyleValue");
|
|
2218
|
+
var addTextData = /* @__PURE__ */ __name((identifierList, id, label) => {
|
|
2219
|
+
const normalizedId = normalizeText(id);
|
|
2220
|
+
textNodes.push({
|
|
2221
|
+
sets: normalizeIdentifierList(identifierList).sort(),
|
|
2222
|
+
id: normalizedId,
|
|
2223
|
+
label: label ? normalizeText(label) : undefined
|
|
2224
|
+
});
|
|
2225
|
+
}, "addTextData");
|
|
2226
|
+
var addStyleData = /* @__PURE__ */ __name((identifierList, data) => {
|
|
2227
|
+
const targets = normalizeIdentifierList(identifierList).sort();
|
|
2228
|
+
const styles = {};
|
|
2229
|
+
for (const [key, value] of data) {
|
|
2230
|
+
styles[key] = normalizeStyleValue(value) ?? value;
|
|
2231
|
+
}
|
|
2232
|
+
styleEntries.push({ targets, styles });
|
|
2233
|
+
}, "addStyleData");
|
|
2234
|
+
var getStyleData = /* @__PURE__ */ __name(() => {
|
|
2235
|
+
return styleEntries;
|
|
2236
|
+
}, "getStyleData");
|
|
2237
|
+
var normalizeIdentifierList = /* @__PURE__ */ __name((identifierList) => {
|
|
2238
|
+
return identifierList.map((identifier) => normalizeText(identifier));
|
|
2239
|
+
}, "normalizeIdentifierList");
|
|
2240
|
+
var validateUnionIdentifiers = /* @__PURE__ */ __name((identifierList) => {
|
|
2241
|
+
const normalized = normalizeIdentifierList(identifierList);
|
|
2242
|
+
const unknown = normalized.filter((identifier) => !knownSets.has(identifier));
|
|
2243
|
+
if (unknown.length > 0) {
|
|
2244
|
+
throw new Error(`unknown set identifier: ${unknown.join(", ")}`);
|
|
2245
|
+
}
|
|
2246
|
+
}, "validateUnionIdentifiers");
|
|
2247
|
+
var getTextData = /* @__PURE__ */ __name(() => {
|
|
2248
|
+
return textNodes;
|
|
2249
|
+
}, "getTextData");
|
|
2250
|
+
var getCurrentSets = /* @__PURE__ */ __name(() => currentSets, "getCurrentSets");
|
|
2251
|
+
var getIndentMode = /* @__PURE__ */ __name(() => indentMode, "getIndentMode");
|
|
2252
|
+
var setIndentMode = /* @__PURE__ */ __name((enabled) => {
|
|
2253
|
+
indentMode = enabled;
|
|
2254
|
+
}, "setIndentMode");
|
|
2255
|
+
var DEFAULT_VENN_CONFIG = defaultConfig_default.venn;
|
|
2256
|
+
function getConfig2() {
|
|
2257
|
+
return cleanAndMerge(DEFAULT_VENN_CONFIG, getConfig().venn);
|
|
2258
|
+
}
|
|
2259
|
+
__name(getConfig2, "getConfig");
|
|
2260
|
+
var customClear = /* @__PURE__ */ __name(() => {
|
|
2261
|
+
clear();
|
|
2262
|
+
subsets.length = 0;
|
|
2263
|
+
textNodes.length = 0;
|
|
2264
|
+
styleEntries.length = 0;
|
|
2265
|
+
knownSets.clear();
|
|
2266
|
+
currentSets = undefined;
|
|
2267
|
+
indentMode = false;
|
|
2268
|
+
}, "customClear");
|
|
2269
|
+
var db = {
|
|
2270
|
+
getConfig: getConfig2,
|
|
2271
|
+
clear: customClear,
|
|
2272
|
+
setAccTitle,
|
|
2273
|
+
getAccTitle,
|
|
2274
|
+
setDiagramTitle,
|
|
2275
|
+
getDiagramTitle,
|
|
2276
|
+
getAccDescription,
|
|
2277
|
+
setAccDescription,
|
|
2278
|
+
addSubsetData,
|
|
2279
|
+
getSubsetData,
|
|
2280
|
+
addTextData,
|
|
2281
|
+
addStyleData,
|
|
2282
|
+
validateUnionIdentifiers,
|
|
2283
|
+
getTextData,
|
|
2284
|
+
getStyleData,
|
|
2285
|
+
getCurrentSets,
|
|
2286
|
+
getIndentMode,
|
|
2287
|
+
setIndentMode
|
|
2288
|
+
};
|
|
2289
|
+
var getStyles = /* @__PURE__ */ __name((options) => `
|
|
2290
|
+
.venn-title {
|
|
2291
|
+
font-size: 32px;
|
|
2292
|
+
fill: ${options.vennTitleTextColor};
|
|
2293
|
+
font-family: ${options.fontFamily};
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
.venn-circle text {
|
|
2297
|
+
font-size: 48px;
|
|
2298
|
+
font-family: ${options.fontFamily};
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
.venn-intersection text {
|
|
2302
|
+
font-size: 48px;
|
|
2303
|
+
fill: ${options.vennSetTextColor};
|
|
2304
|
+
font-family: ${options.fontFamily};
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
.venn-text-node {
|
|
2308
|
+
font-family: ${options.fontFamily};
|
|
2309
|
+
color: ${options.vennSetTextColor};
|
|
2310
|
+
}
|
|
2311
|
+
`, "getStyles");
|
|
2312
|
+
var styles_default = getStyles;
|
|
2313
|
+
function buildStyleByKey(styleData) {
|
|
2314
|
+
const map = /* @__PURE__ */ new Map;
|
|
2315
|
+
for (const entry of styleData) {
|
|
2316
|
+
const key = entry.targets.join("|");
|
|
2317
|
+
const existing = map.get(key);
|
|
2318
|
+
if (existing) {
|
|
2319
|
+
Object.assign(existing, entry.styles);
|
|
2320
|
+
} else {
|
|
2321
|
+
map.set(key, { ...entry.styles });
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
return map;
|
|
2325
|
+
}
|
|
2326
|
+
__name(buildStyleByKey, "buildStyleByKey");
|
|
2327
|
+
var draw = /* @__PURE__ */ __name((_text, id, _version, diagObj) => {
|
|
2328
|
+
const db2 = diagObj.db;
|
|
2329
|
+
const config = db2.getConfig?.();
|
|
2330
|
+
const { themeVariables, look, handDrawnSeed } = getConfig();
|
|
2331
|
+
const isHandDrawn = look === "handDrawn";
|
|
2332
|
+
const themeColors = [
|
|
2333
|
+
themeVariables.venn1,
|
|
2334
|
+
themeVariables.venn2,
|
|
2335
|
+
themeVariables.venn3,
|
|
2336
|
+
themeVariables.venn4,
|
|
2337
|
+
themeVariables.venn5,
|
|
2338
|
+
themeVariables.venn6,
|
|
2339
|
+
themeVariables.venn7,
|
|
2340
|
+
themeVariables.venn8
|
|
2341
|
+
].filter(Boolean);
|
|
2342
|
+
const title = db2.getDiagramTitle?.();
|
|
2343
|
+
const sets = db2.getSubsetData();
|
|
2344
|
+
const textNodes2 = db2.getTextData();
|
|
2345
|
+
const styleByKey = buildStyleByKey(db2.getStyleData());
|
|
2346
|
+
const renderSets = ensurePairwiseSubsets(sets);
|
|
2347
|
+
const svgWidth = config?.width ?? 800;
|
|
2348
|
+
const svgHeight = config?.height ?? 450;
|
|
2349
|
+
const REFERENCE_WIDTH = 1600;
|
|
2350
|
+
const scale2 = svgWidth / REFERENCE_WIDTH;
|
|
2351
|
+
const titleHeight = title ? 48 * scale2 : 0;
|
|
2352
|
+
const defaultTextColor = themeVariables.primaryTextColor ?? themeVariables.textColor;
|
|
2353
|
+
const svg = selectSvgElement(id);
|
|
2354
|
+
svg.attr("viewBox", `0 0 ${svgWidth} ${svgHeight}`);
|
|
2355
|
+
if (title) {
|
|
2356
|
+
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);
|
|
2357
|
+
}
|
|
2358
|
+
const dummyD3root = select_default(document.createElement("div"));
|
|
2359
|
+
const vennDiagram = VennDiagram().width(svgWidth).height(svgHeight - titleHeight);
|
|
2360
|
+
dummyD3root.datum(renderSets).call(vennDiagram);
|
|
2361
|
+
const roughSvg = isHandDrawn ? at.svg(dummyD3root.select("svg").node()) : undefined;
|
|
2362
|
+
const layoutAreas = layout(renderSets, {
|
|
2363
|
+
width: svgWidth,
|
|
2364
|
+
height: svgHeight - titleHeight,
|
|
2365
|
+
padding: config?.padding ?? 15
|
|
2366
|
+
});
|
|
2367
|
+
const layoutByKey = /* @__PURE__ */ new Map;
|
|
2368
|
+
for (const area of layoutAreas) {
|
|
2369
|
+
const key = stableSetsKey([...area.data.sets].sort());
|
|
2370
|
+
layoutByKey.set(key, area);
|
|
2371
|
+
}
|
|
2372
|
+
if (textNodes2.length > 0) {
|
|
2373
|
+
renderTextNodes(config, layoutByKey, dummyD3root, textNodes2, scale2, styleByKey);
|
|
2374
|
+
}
|
|
2375
|
+
const themeDark = is_dark_default(themeVariables.background || "#f4f4f4");
|
|
2376
|
+
dummyD3root.selectAll(".venn-circle").each(function(d, i) {
|
|
2377
|
+
const group = select_default(this);
|
|
2378
|
+
const data = d;
|
|
2379
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2380
|
+
const customStyle = styleByKey.get(setsKey);
|
|
2381
|
+
const baseColor = customStyle?.fill || themeColors[i % themeColors.length] || themeVariables.primaryColor;
|
|
2382
|
+
group.classed(`venn-set-${i % 8}`, true);
|
|
2383
|
+
const fillOpacity = customStyle?.["fill-opacity"] ?? 0.1;
|
|
2384
|
+
const strokeColor = customStyle?.stroke || baseColor;
|
|
2385
|
+
const strokeWidthVal = customStyle?.["stroke-width"] || `${5 * scale2}`;
|
|
2386
|
+
if (isHandDrawn && roughSvg) {
|
|
2387
|
+
const layoutArea = layoutByKey.get(setsKey);
|
|
2388
|
+
if (layoutArea && layoutArea.circles.length > 0) {
|
|
2389
|
+
const c = layoutArea.circles[0];
|
|
2390
|
+
const roughNode = roughSvg.circle(c.x, c.y, c.radius * 2, {
|
|
2391
|
+
roughness: 0.7,
|
|
2392
|
+
seed: handDrawnSeed,
|
|
2393
|
+
fill: transparentize_default(baseColor, 0.7),
|
|
2394
|
+
fillStyle: "hachure",
|
|
2395
|
+
fillWeight: 2,
|
|
2396
|
+
hachureGap: 8,
|
|
2397
|
+
hachureAngle: -41 + i * 60,
|
|
2398
|
+
stroke: strokeColor,
|
|
2399
|
+
strokeWidth: parseFloat(String(strokeWidthVal))
|
|
2400
|
+
});
|
|
2401
|
+
group.select("path").remove();
|
|
2402
|
+
group.node()?.insertBefore(roughNode, group.select("text").node());
|
|
2403
|
+
}
|
|
2404
|
+
} else {
|
|
2405
|
+
group.select("path").style("fill", baseColor).style("fill-opacity", fillOpacity).style("stroke", strokeColor).style("stroke-width", strokeWidthVal).style("stroke-opacity", 0.95);
|
|
2406
|
+
}
|
|
2407
|
+
const textColor = customStyle?.color || (themeDark ? lighten_default(baseColor, 30) : darken_default(baseColor, 30));
|
|
2408
|
+
group.select("text").style("font-size", `${48 * scale2}px`).style("fill", textColor);
|
|
2409
|
+
});
|
|
2410
|
+
if (isHandDrawn && roughSvg) {
|
|
2411
|
+
dummyD3root.selectAll(".venn-intersection").each(function(d) {
|
|
2412
|
+
const group = select_default(this);
|
|
2413
|
+
const data = d;
|
|
2414
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2415
|
+
const customStyle = styleByKey.get(setsKey);
|
|
2416
|
+
const customFill = customStyle?.fill;
|
|
2417
|
+
if (customFill) {
|
|
2418
|
+
const pathEl = group.select("path");
|
|
2419
|
+
const pathD = pathEl.attr("d");
|
|
2420
|
+
if (pathD) {
|
|
2421
|
+
const roughNode = roughSvg.path(pathD, {
|
|
2422
|
+
roughness: 0.7,
|
|
2423
|
+
seed: handDrawnSeed,
|
|
2424
|
+
fill: transparentize_default(customFill, 0.3),
|
|
2425
|
+
fillStyle: "cross-hatch",
|
|
2426
|
+
fillWeight: 2,
|
|
2427
|
+
hachureGap: 6,
|
|
2428
|
+
hachureAngle: 60,
|
|
2429
|
+
stroke: "none"
|
|
2430
|
+
});
|
|
2431
|
+
const existingPath = pathEl.node();
|
|
2432
|
+
existingPath?.parentNode?.insertBefore(roughNode, existingPath);
|
|
2433
|
+
pathEl.remove();
|
|
2434
|
+
}
|
|
2435
|
+
} else {
|
|
2436
|
+
group.select("path").style("fill-opacity", 0);
|
|
2437
|
+
}
|
|
2438
|
+
group.select("text").style("font-size", `${48 * scale2}px`).style("fill", customStyle?.color ?? themeVariables.vennSetTextColor ?? defaultTextColor);
|
|
2439
|
+
});
|
|
2440
|
+
} else {
|
|
2441
|
+
dummyD3root.selectAll(".venn-intersection text").style("font-size", `${48 * scale2}px`).style("fill", (e) => {
|
|
2442
|
+
const data = e;
|
|
2443
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2444
|
+
return styleByKey.get(setsKey)?.color ?? themeVariables.vennSetTextColor ?? defaultTextColor;
|
|
2445
|
+
});
|
|
2446
|
+
dummyD3root.selectAll(".venn-intersection path").style("fill-opacity", (e) => {
|
|
2447
|
+
const data = e;
|
|
2448
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2449
|
+
return styleByKey.get(setsKey)?.fill ? 1 : 0;
|
|
2450
|
+
}).style("fill", (e) => {
|
|
2451
|
+
const data = e;
|
|
2452
|
+
const setsKey = stableSetsKey([...data.sets].sort());
|
|
2453
|
+
return styleByKey.get(setsKey)?.fill ?? "transparent";
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
const vennGroup = svg.append("g").attr("transform", `translate(0, ${titleHeight})`);
|
|
2457
|
+
const dummySvg = dummyD3root.select("svg").node();
|
|
2458
|
+
if (dummySvg && "childNodes" in dummySvg) {
|
|
2459
|
+
for (const child of [...dummySvg.childNodes]) {
|
|
2460
|
+
vennGroup.node()?.appendChild(child);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
configureSvgSize(svg, svgHeight, svgWidth, config?.useMaxWidth ?? true);
|
|
2464
|
+
}, "draw");
|
|
2465
|
+
function stableSetsKey(setIds) {
|
|
2466
|
+
return setIds.join("|");
|
|
2467
|
+
}
|
|
2468
|
+
__name(stableSetsKey, "stableSetsKey");
|
|
2469
|
+
function renderTextNodes(config, layoutByKey, dummyD3root, textNodes2, scale2, styleByKey) {
|
|
2470
|
+
const useDebugLayout = config?.useDebugLayout ?? false;
|
|
2471
|
+
const vennSvg = dummyD3root.select("svg");
|
|
2472
|
+
const textGroup = vennSvg.append("g").attr("class", "venn-text-nodes");
|
|
2473
|
+
const nodesByArea = /* @__PURE__ */ new Map;
|
|
2474
|
+
for (const node of textNodes2) {
|
|
2475
|
+
const key = stableSetsKey(node.sets);
|
|
2476
|
+
const existing = nodesByArea.get(key);
|
|
2477
|
+
if (existing) {
|
|
2478
|
+
existing.push(node);
|
|
2479
|
+
} else {
|
|
2480
|
+
nodesByArea.set(key, [node]);
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
for (const [key, nodes] of nodesByArea.entries()) {
|
|
2484
|
+
const area = layoutByKey.get(key);
|
|
2485
|
+
if (!area?.text) {
|
|
2486
|
+
continue;
|
|
2487
|
+
}
|
|
2488
|
+
const centerX = area.text.x;
|
|
2489
|
+
const centerY = area.text.y;
|
|
2490
|
+
const minCircleRadius = Math.min(...area.circles.map((c) => c.radius));
|
|
2491
|
+
const innerRadiusRaw = Math.min(...area.circles.map((c) => c.radius - Math.hypot(centerX - c.x, centerY - c.y)));
|
|
2492
|
+
let innerRadius = Number.isFinite(innerRadiusRaw) ? Math.max(0, innerRadiusRaw) : 0;
|
|
2493
|
+
if (innerRadius === 0 && Number.isFinite(minCircleRadius)) {
|
|
2494
|
+
innerRadius = minCircleRadius * 0.6;
|
|
2495
|
+
}
|
|
2496
|
+
const areaGroup = textGroup.append("g").attr("class", "venn-text-area").attr("font-size", `${40 * scale2}px`);
|
|
2497
|
+
if (useDebugLayout) {
|
|
2498
|
+
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}`);
|
|
2499
|
+
}
|
|
2500
|
+
const innerWidth = Math.max(80 * scale2, innerRadius * 2 * 0.95);
|
|
2501
|
+
const innerHeight = Math.max(60 * scale2, innerRadius * 2 * 0.95);
|
|
2502
|
+
const hasLabel = area.data.label && area.data.label.length > 0;
|
|
2503
|
+
const labelOffsetBase = hasLabel ? Math.min(32 * scale2, innerRadius * 0.25) : 0;
|
|
2504
|
+
const labelOffset = labelOffsetBase + (nodes.length <= 2 ? 30 * scale2 : 0);
|
|
2505
|
+
const startX = centerX - innerWidth / 2;
|
|
2506
|
+
const startY = centerY - innerHeight / 2 + labelOffset;
|
|
2507
|
+
const cols = Math.max(1, Math.ceil(Math.sqrt(nodes.length)));
|
|
2508
|
+
const rows = Math.max(1, Math.ceil(nodes.length / cols));
|
|
2509
|
+
const cellWidth = innerWidth / cols;
|
|
2510
|
+
const cellHeight = innerHeight / rows;
|
|
2511
|
+
for (const [i, node] of nodes.entries()) {
|
|
2512
|
+
const col = i % cols;
|
|
2513
|
+
const row = Math.floor(i / cols);
|
|
2514
|
+
const x = startX + cellWidth * (col + 0.5);
|
|
2515
|
+
const y = startY + cellHeight * (row + 0.5);
|
|
2516
|
+
if (useDebugLayout) {
|
|
2517
|
+
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}`);
|
|
2518
|
+
}
|
|
2519
|
+
const boxWidth = cellWidth * 0.9;
|
|
2520
|
+
const boxHeight = cellHeight * 0.9;
|
|
2521
|
+
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");
|
|
2522
|
+
const textColor = styleByKey.get(node.id)?.color;
|
|
2523
|
+
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);
|
|
2524
|
+
if (textColor) {
|
|
2525
|
+
text.style("color", textColor);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
__name(renderTextNodes, "renderTextNodes");
|
|
2531
|
+
function ensurePairwiseSubsets(subsets2) {
|
|
2532
|
+
const existingKeys = new Set(subsets2.map((s) => [...s.sets].sort().join("|")));
|
|
2533
|
+
const individualSetSizes = new Map(subsets2.filter((s) => s.sets.length === 1 && s.size !== undefined).map((s) => [s.sets[0], s.size]));
|
|
2534
|
+
const synthetic = [];
|
|
2535
|
+
for (const subset of subsets2) {
|
|
2536
|
+
if (subset.sets.length < 3) {
|
|
2537
|
+
continue;
|
|
2538
|
+
}
|
|
2539
|
+
const members = [...subset.sets].sort();
|
|
2540
|
+
for (let i = 0;i < members.length - 1; i++) {
|
|
2541
|
+
for (let j = i + 1;j < members.length; j++) {
|
|
2542
|
+
const pair = [members[i], members[j]];
|
|
2543
|
+
const key = pair.join("|");
|
|
2544
|
+
if (!existingKeys.has(key)) {
|
|
2545
|
+
existingKeys.add(key);
|
|
2546
|
+
const sizeA = individualSetSizes.get(pair[0]);
|
|
2547
|
+
const sizeB = individualSetSizes.get(pair[1]);
|
|
2548
|
+
const pairSize = sizeA !== undefined && sizeB !== undefined ? Math.min(sizeA, sizeB) / 4 : 2.5;
|
|
2549
|
+
synthetic.push({ sets: pair, size: pairSize, label: "" });
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
return synthetic.length > 0 ? [...subsets2, ...synthetic] : subsets2;
|
|
2555
|
+
}
|
|
2556
|
+
__name(ensurePairwiseSubsets, "ensurePairwiseSubsets");
|
|
2557
|
+
var renderer = { draw };
|
|
2558
|
+
var diagram = {
|
|
2559
|
+
parser: venn_default,
|
|
2560
|
+
db,
|
|
2561
|
+
renderer,
|
|
2562
|
+
styles: styles_default
|
|
2563
|
+
};
|
|
2564
|
+
export {
|
|
2565
|
+
diagram
|
|
2566
|
+
};
|