1 | import { p as parser, d as db, s as styles } from "./styles-38a11c49.js";
|
2 | import { c as getConfig, l as log, j as select, k as configureSvgSize } from "./mermaid-4b4b971d.js";
|
3 | import { G as Graph, l as layout } from "./layout-e57aec3f.js";
|
4 | import { s as svgDraw } from "./svgDraw-1b15aedc.js";
|
5 | import "./line-53c588d2.js";
|
6 | import "./array-b7dcf730.js";
|
7 | import "./constant-b644328d.js";
|
8 | let idCache = {};
|
9 | const padding = 20;
|
10 | const getGraphId = function(label) {
|
11 | const foundEntry = Object.entries(idCache).find((entry) => entry[1].label === label);
|
12 | if (foundEntry) {
|
13 | return foundEntry[0];
|
14 | }
|
15 | };
|
16 | const insertMarkers = function(elem) {
|
17 | elem.append("defs").append("marker").attr("id", "extensionStart").attr("class", "extension").attr("refX", 0).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 1,7 L18,13 V 1 Z");
|
18 | elem.append("defs").append("marker").attr("id", "extensionEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 1,1 V 13 L18,7 Z");
|
19 | elem.append("defs").append("marker").attr("id", "compositionStart").attr("class", "extension").attr("refX", 0).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
|
20 | elem.append("defs").append("marker").attr("id", "compositionEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
|
21 | elem.append("defs").append("marker").attr("id", "aggregationStart").attr("class", "extension").attr("refX", 0).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
|
22 | elem.append("defs").append("marker").attr("id", "aggregationEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
|
23 | elem.append("defs").append("marker").attr("id", "dependencyStart").attr("class", "extension").attr("refX", 0).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 5,7 L9,13 L1,7 L9,1 Z");
|
24 | elem.append("defs").append("marker").attr("id", "dependencyEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L14,7 L9,1 Z");
|
25 | };
|
26 | const draw = function(text, id, _version, diagObj) {
|
27 | const conf = getConfig().class;
|
28 | idCache = {};
|
29 | log.info("Rendering diagram " + text);
|
30 | const securityLevel = getConfig().securityLevel;
|
31 | let sandboxElement;
|
32 | if (securityLevel === "sandbox") {
|
33 | sandboxElement = select("#i" + id);
|
34 | }
|
35 | const root = securityLevel === "sandbox" ? select(sandboxElement.nodes()[0].contentDocument.body) : select("body");
|
36 | const diagram2 = root.select(`[id='${id}']`);
|
37 | insertMarkers(diagram2);
|
38 | const g = new Graph({
|
39 | multigraph: true
|
40 | });
|
41 | g.setGraph({
|
42 | isMultiGraph: true
|
43 | });
|
44 | g.setDefaultEdgeLabel(function() {
|
45 | return {};
|
46 | });
|
47 | const classes = diagObj.db.getClasses();
|
48 | const keys = Object.keys(classes);
|
49 | for (const key of keys) {
|
50 | const classDef = classes[key];
|
51 | const node = svgDraw.drawClass(diagram2, classDef, conf, diagObj);
|
52 | idCache[node.id] = node;
|
53 | g.setNode(node.id, node);
|
54 | log.info("Org height: " + node.height);
|
55 | }
|
56 | const relations = diagObj.db.getRelations();
|
57 | relations.forEach(function(relation) {
|
58 | log.info(
|
59 | "tjoho" + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation)
|
60 | );
|
61 | g.setEdge(
|
62 | getGraphId(relation.id1),
|
63 | getGraphId(relation.id2),
|
64 | {
|
65 | relation
|
66 | },
|
67 | relation.title || "DEFAULT"
|
68 | );
|
69 | });
|
70 | const notes = diagObj.db.getNotes();
|
71 | notes.forEach(function(note) {
|
72 | log.debug(`Adding note: ${JSON.stringify(note)}`);
|
73 | const node = svgDraw.drawNote(diagram2, note, conf, diagObj);
|
74 | idCache[node.id] = node;
|
75 | g.setNode(node.id, node);
|
76 | if (note.class && note.class in classes) {
|
77 | g.setEdge(
|
78 | note.id,
|
79 | getGraphId(note.class),
|
80 | {
|
81 | relation: {
|
82 | id1: note.id,
|
83 | id2: note.class,
|
84 | relation: {
|
85 | type1: "none",
|
86 | type2: "none",
|
87 | lineType: 10
|
88 | }
|
89 | }
|
90 | },
|
91 | "DEFAULT"
|
92 | );
|
93 | }
|
94 | });
|
95 | layout(g);
|
96 | g.nodes().forEach(function(v) {
|
97 | if (v !== void 0 && g.node(v) !== void 0) {
|
98 | log.debug("Node " + v + ": " + JSON.stringify(g.node(v)));
|
99 | root.select("#" + (diagObj.db.lookUpDomId(v) || v)).attr(
|
100 | "transform",
|
101 | "translate(" + (g.node(v).x - g.node(v).width / 2) + "," + (g.node(v).y - g.node(v).height / 2) + " )"
|
102 | );
|
103 | }
|
104 | });
|
105 | g.edges().forEach(function(e) {
|
106 | if (e !== void 0 && g.edge(e) !== void 0) {
|
107 | log.debug("Edge " + e.v + " -> " + e.w + ": " + JSON.stringify(g.edge(e)));
|
108 | svgDraw.drawEdge(diagram2, g.edge(e), g.edge(e).relation, conf, diagObj);
|
109 | }
|
110 | });
|
111 | const svgBounds = diagram2.node().getBBox();
|
112 | const width = svgBounds.width + padding * 2;
|
113 | const height = svgBounds.height + padding * 2;
|
114 | configureSvgSize(diagram2, height, width, conf.useMaxWidth);
|
115 | const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`;
|
116 | log.debug(`viewBox ${vBox}`);
|
117 | diagram2.attr("viewBox", vBox);
|
118 | };
|
119 | const renderer = {
|
120 | draw
|
121 | };
|
122 | const diagram = {
|
123 | parser,
|
124 | db,
|
125 | renderer,
|
126 | styles,
|
127 | init: (cnf) => {
|
128 | if (!cnf.class) {
|
129 | cnf.class = {};
|
130 | }
|
131 | cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
132 | db.clear();
|
133 | }
|
134 | };
|
135 | export {
|
136 | diagram
|
137 | };
|