UNPKG

17.1 kBJavaScriptView Raw
1import { G as Graph } from "./graph-fe24fab6.js";
2import { S as Selection, v as root, x as array, y as isPlainObject, z as isFunction, o as getStylesFromArray, l as log, p as evaluate, c as getConfig, f as common, r as renderKatex, q as interpolateToCurve, n as curveLinear, j as d3select, A as utils, t as setupGraphViewbox, B as rgba } from "./mermaid-dcacb631.js";
3import { r as render } from "./index-fc479858.js";
4import { c as channel } from "./channel-f9001828.js";
5function selectAll(selector) {
6 return typeof selector === "string" ? new Selection([document.querySelectorAll(selector)], [document.documentElement]) : new Selection([array(selector)], root);
7}
8function isSubgraph(g, v) {
9 return !!g.children(v).length;
10}
11function edgeToId(e) {
12 return escapeId(e.v) + ":" + escapeId(e.w) + ":" + escapeId(e.name);
13}
14var ID_DELIM = /:/g;
15function escapeId(str) {
16 return str ? String(str).replace(ID_DELIM, "\\:") : "";
17}
18function applyStyle(dom, styleFn) {
19 if (styleFn) {
20 dom.attr("style", styleFn);
21 }
22}
23function applyClass(dom, classFn, otherClasses) {
24 if (classFn) {
25 dom.attr("class", classFn).attr("class", otherClasses + " " + dom.attr("class"));
26 }
27}
28function applyTransition(selection, g) {
29 var graph = g.graph();
30 if (isPlainObject(graph)) {
31 var transition = graph.transition;
32 if (isFunction(transition)) {
33 return transition(selection);
34 }
35 }
36 return selection;
37}
38function addHtmlLabel(root2, node) {
39 var fo = root2.append("foreignObject").attr("width", "100000");
40 var div = fo.append("xhtml:div");
41 div.attr("xmlns", "http://www.w3.org/1999/xhtml");
42 var label = node.label;
43 switch (typeof label) {
44 case "function":
45 div.insert(label);
46 break;
47 case "object":
48 div.insert(function() {
49 return label;
50 });
51 break;
52 default:
53 div.html(label);
54 }
55 applyStyle(div, node.labelStyle);
56 div.style("display", "inline-block");
57 div.style("white-space", "nowrap");
58 var client = div.node().getBoundingClientRect();
59 fo.attr("width", client.width).attr("height", client.height);
60 return fo;
61}
62const conf = {};
63const setConf = function(cnf) {
64 const keys = Object.keys(cnf);
65 for (const key of keys) {
66 conf[key] = cnf[key];
67 }
68};
69const addVertices = async function(vert, g, svgId, root2, doc, diagObj) {
70 const svg = root2.select(`[id="${svgId}"]`);
71 const keys = Object.keys(vert);
72 for (const id of keys) {
73 const vertex = vert[id];
74 let classStr = "default";
75 if (vertex.classes.length > 0) {
76 classStr = vertex.classes.join(" ");
77 }
78 classStr = classStr + " flowchart-label";
79 const styles = getStylesFromArray(vertex.styles);
80 let vertexText = vertex.text !== void 0 ? vertex.text : vertex.id;
81 let vertexNode;
82 log.info("vertex", vertex, vertex.labelType);
83 if (vertex.labelType === "markdown") {
84 log.info("vertex", vertex, vertex.labelType);
85 } else {
86 if (evaluate(getConfig().flowchart.htmlLabels)) {
87 const node = {
88 label: vertexText
89 };
90 vertexNode = addHtmlLabel(svg, node).node();
91 vertexNode.parentNode.removeChild(vertexNode);
92 } else {
93 const svgLabel = doc.createElementNS("http://www.w3.org/2000/svg", "text");
94 svgLabel.setAttribute("style", styles.labelStyle.replace("color:", "fill:"));
95 const rows = vertexText.split(common.lineBreakRegex);
96 for (const row of rows) {
97 const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
98 tspan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
99 tspan.setAttribute("dy", "1em");
100 tspan.setAttribute("x", "1");
101 tspan.textContent = row;
102 svgLabel.appendChild(tspan);
103 }
104 vertexNode = svgLabel;
105 }
106 }
107 let radius = 0;
108 let _shape = "";
109 switch (vertex.type) {
110 case "round":
111 radius = 5;
112 _shape = "rect";
113 break;
114 case "square":
115 _shape = "rect";
116 break;
117 case "diamond":
118 _shape = "question";
119 break;
120 case "hexagon":
121 _shape = "hexagon";
122 break;
123 case "odd":
124 _shape = "rect_left_inv_arrow";
125 break;
126 case "lean_right":
127 _shape = "lean_right";
128 break;
129 case "lean_left":
130 _shape = "lean_left";
131 break;
132 case "trapezoid":
133 _shape = "trapezoid";
134 break;
135 case "inv_trapezoid":
136 _shape = "inv_trapezoid";
137 break;
138 case "odd_right":
139 _shape = "rect_left_inv_arrow";
140 break;
141 case "circle":
142 _shape = "circle";
143 break;
144 case "ellipse":
145 _shape = "ellipse";
146 break;
147 case "stadium":
148 _shape = "stadium";
149 break;
150 case "subroutine":
151 _shape = "subroutine";
152 break;
153 case "cylinder":
154 _shape = "cylinder";
155 break;
156 case "group":
157 _shape = "rect";
158 break;
159 case "doublecircle":
160 _shape = "doublecircle";
161 break;
162 default:
163 _shape = "rect";
164 }
165 const labelText = await renderKatex(vertexText, getConfig());
166 g.setNode(vertex.id, {
167 labelStyle: styles.labelStyle,
168 shape: _shape,
169 labelText,
170 labelType: vertex.labelType,
171 rx: radius,
172 ry: radius,
173 class: classStr,
174 style: styles.style,
175 id: vertex.id,
176 link: vertex.link,
177 linkTarget: vertex.linkTarget,
178 tooltip: diagObj.db.getTooltip(vertex.id) || "",
179 domId: diagObj.db.lookUpDomId(vertex.id),
180 haveCallback: vertex.haveCallback,
181 width: vertex.type === "group" ? 500 : void 0,
182 dir: vertex.dir,
183 type: vertex.type,
184 props: vertex.props,
185 padding: getConfig().flowchart.padding
186 });
187 log.info("setNode", {
188 labelStyle: styles.labelStyle,
189 labelType: vertex.labelType,
190 shape: _shape,
191 labelText,
192 rx: radius,
193 ry: radius,
194 class: classStr,
195 style: styles.style,
196 id: vertex.id,
197 domId: diagObj.db.lookUpDomId(vertex.id),
198 width: vertex.type === "group" ? 500 : void 0,
199 type: vertex.type,
200 dir: vertex.dir,
201 props: vertex.props,
202 padding: getConfig().flowchart.padding
203 });
204 }
205};
206const addEdges = async function(edges, g, diagObj) {
207 log.info("abc78 edges = ", edges);
208 let cnt = 0;
209 let linkIdCnt = {};
210 let defaultStyle;
211 let defaultLabelStyle;
212 if (edges.defaultStyle !== void 0) {
213 const defaultStyles = getStylesFromArray(edges.defaultStyle);
214 defaultStyle = defaultStyles.style;
215 defaultLabelStyle = defaultStyles.labelStyle;
216 }
217 for (const edge of edges) {
218 cnt++;
219 const linkIdBase = "L-" + edge.start + "-" + edge.end;
220 if (linkIdCnt[linkIdBase] === void 0) {
221 linkIdCnt[linkIdBase] = 0;
222 log.info("abc78 new entry", linkIdBase, linkIdCnt[linkIdBase]);
223 } else {
224 linkIdCnt[linkIdBase]++;
225 log.info("abc78 new entry", linkIdBase, linkIdCnt[linkIdBase]);
226 }
227 let linkId = linkIdBase + "-" + linkIdCnt[linkIdBase];
228 log.info("abc78 new link id to be used is", linkIdBase, linkId, linkIdCnt[linkIdBase]);
229 const linkNameStart = "LS-" + edge.start;
230 const linkNameEnd = "LE-" + edge.end;
231 const edgeData = { style: "", labelStyle: "" };
232 edgeData.minlen = edge.length || 1;
233 if (edge.type === "arrow_open") {
234 edgeData.arrowhead = "none";
235 } else {
236 edgeData.arrowhead = "normal";
237 }
238 edgeData.arrowTypeStart = "arrow_open";
239 edgeData.arrowTypeEnd = "arrow_open";
240 switch (edge.type) {
241 case "double_arrow_cross":
242 edgeData.arrowTypeStart = "arrow_cross";
243 case "arrow_cross":
244 edgeData.arrowTypeEnd = "arrow_cross";
245 break;
246 case "double_arrow_point":
247 edgeData.arrowTypeStart = "arrow_point";
248 case "arrow_point":
249 edgeData.arrowTypeEnd = "arrow_point";
250 break;
251 case "double_arrow_circle":
252 edgeData.arrowTypeStart = "arrow_circle";
253 case "arrow_circle":
254 edgeData.arrowTypeEnd = "arrow_circle";
255 break;
256 }
257 let style = "";
258 let labelStyle = "";
259 switch (edge.stroke) {
260 case "normal":
261 style = "fill:none;";
262 if (defaultStyle !== void 0) {
263 style = defaultStyle;
264 }
265 if (defaultLabelStyle !== void 0) {
266 labelStyle = defaultLabelStyle;
267 }
268 edgeData.thickness = "normal";
269 edgeData.pattern = "solid";
270 break;
271 case "dotted":
272 edgeData.thickness = "normal";
273 edgeData.pattern = "dotted";
274 edgeData.style = "fill:none;stroke-width:2px;stroke-dasharray:3;";
275 break;
276 case "thick":
277 edgeData.thickness = "thick";
278 edgeData.pattern = "solid";
279 edgeData.style = "stroke-width: 3.5px;fill:none;";
280 break;
281 case "invisible":
282 edgeData.thickness = "invisible";
283 edgeData.pattern = "solid";
284 edgeData.style = "stroke-width: 0;fill:none;";
285 break;
286 }
287 if (edge.style !== void 0) {
288 const styles = getStylesFromArray(edge.style);
289 style = styles.style;
290 labelStyle = styles.labelStyle;
291 }
292 edgeData.style = edgeData.style += style;
293 edgeData.labelStyle = edgeData.labelStyle += labelStyle;
294 if (edge.interpolate !== void 0) {
295 edgeData.curve = interpolateToCurve(edge.interpolate, curveLinear);
296 } else if (edges.defaultInterpolate !== void 0) {
297 edgeData.curve = interpolateToCurve(edges.defaultInterpolate, curveLinear);
298 } else {
299 edgeData.curve = interpolateToCurve(conf.curve, curveLinear);
300 }
301 if (edge.text === void 0) {
302 if (edge.style !== void 0) {
303 edgeData.arrowheadStyle = "fill: #333";
304 }
305 } else {
306 edgeData.arrowheadStyle = "fill: #333";
307 edgeData.labelpos = "c";
308 }
309 edgeData.labelType = edge.labelType;
310 edgeData.label = await renderKatex(edge.text.replace(common.lineBreakRegex, "\n"), getConfig());
311 if (edge.style === void 0) {
312 edgeData.style = edgeData.style || "stroke: #333; stroke-width: 1.5px;fill:none;";
313 }
314 edgeData.labelStyle = edgeData.labelStyle.replace("color:", "fill:");
315 edgeData.id = linkId;
316 edgeData.classes = "flowchart-link " + linkNameStart + " " + linkNameEnd;
317 g.setEdge(edge.start, edge.end, edgeData, cnt);
318 }
319};
320const getClasses = function(text, diagObj) {
321 return diagObj.db.getClasses();
322};
323const draw = async function(text, id, _version, diagObj) {
324 log.info("Drawing flowchart");
325 let dir = diagObj.db.getDirection();
326 if (dir === void 0) {
327 dir = "TD";
328 }
329 const { securityLevel, flowchart: conf2 } = getConfig();
330 const nodeSpacing = conf2.nodeSpacing || 50;
331 const rankSpacing = conf2.rankSpacing || 50;
332 let sandboxElement;
333 if (securityLevel === "sandbox") {
334 sandboxElement = d3select("#i" + id);
335 }
336 const root2 = securityLevel === "sandbox" ? d3select(sandboxElement.nodes()[0].contentDocument.body) : d3select("body");
337 const doc = securityLevel === "sandbox" ? sandboxElement.nodes()[0].contentDocument : document;
338 const g = new Graph({
339 multigraph: true,
340 compound: true
341 }).setGraph({
342 rankdir: dir,
343 nodesep: nodeSpacing,
344 ranksep: rankSpacing,
345 marginx: 0,
346 marginy: 0
347 }).setDefaultEdgeLabel(function() {
348 return {};
349 });
350 let subG;
351 const subGraphs = diagObj.db.getSubGraphs();
352 log.info("Subgraphs - ", subGraphs);
353 for (let i2 = subGraphs.length - 1; i2 >= 0; i2--) {
354 subG = subGraphs[i2];
355 log.info("Subgraph - ", subG);
356 diagObj.db.addVertex(
357 subG.id,
358 { text: subG.title, type: subG.labelType },
359 "group",
360 void 0,
361 subG.classes,
362 subG.dir
363 );
364 }
365 const vert = diagObj.db.getVertices();
366 const edges = diagObj.db.getEdges();
367 log.info("Edges", edges);
368 let i = 0;
369 for (i = subGraphs.length - 1; i >= 0; i--) {
370 subG = subGraphs[i];
371 selectAll("cluster").append("text");
372 for (let j = 0; j < subG.nodes.length; j++) {
373 log.info("Setting up subgraphs", subG.nodes[j], subG.id);
374 g.setParent(subG.nodes[j], subG.id);
375 }
376 }
377 await addVertices(vert, g, id, root2, doc, diagObj);
378 await addEdges(edges, g);
379 const svg = root2.select(`[id="${id}"]`);
380 const element = root2.select("#" + id + " g");
381 await render(element, g, ["point", "circle", "cross"], "flowchart", id);
382 utils.insertTitle(svg, "flowchartTitleText", conf2.titleTopMargin, diagObj.db.getDiagramTitle());
383 setupGraphViewbox(g, svg, conf2.diagramPadding, conf2.useMaxWidth);
384 diagObj.db.indexNodes("subGraph" + i);
385 if (!conf2.htmlLabels) {
386 const labels = doc.querySelectorAll('[id="' + id + '"] .edgeLabel .label');
387 for (const label of labels) {
388 const dim = label.getBBox();
389 const rect = doc.createElementNS("http://www.w3.org/2000/svg", "rect");
390 rect.setAttribute("rx", 0);
391 rect.setAttribute("ry", 0);
392 rect.setAttribute("width", dim.width);
393 rect.setAttribute("height", dim.height);
394 label.insertBefore(rect, label.firstChild);
395 }
396 }
397 const keys = Object.keys(vert);
398 keys.forEach(function(key) {
399 const vertex = vert[key];
400 if (vertex.link) {
401 const node = d3select("#" + id + ' [id="' + key + '"]');
402 if (node) {
403 const link = doc.createElementNS("http://www.w3.org/2000/svg", "a");
404 link.setAttributeNS("http://www.w3.org/2000/svg", "class", vertex.classes.join(" "));
405 link.setAttributeNS("http://www.w3.org/2000/svg", "href", vertex.link);
406 link.setAttributeNS("http://www.w3.org/2000/svg", "rel", "noopener");
407 if (securityLevel === "sandbox") {
408 link.setAttributeNS("http://www.w3.org/2000/svg", "target", "_top");
409 } else if (vertex.linkTarget) {
410 link.setAttributeNS("http://www.w3.org/2000/svg", "target", vertex.linkTarget);
411 }
412 const linkNode = node.insert(function() {
413 return link;
414 }, ":first-child");
415 const shape = node.select(".label-container");
416 if (shape) {
417 linkNode.append(function() {
418 return shape.node();
419 });
420 }
421 const label = node.select(".label");
422 if (label) {
423 linkNode.append(function() {
424 return label.node();
425 });
426 }
427 }
428 }
429 });
430};
431const flowRendererV2 = {
432 setConf,
433 addVertices,
434 addEdges,
435 getClasses,
436 draw
437};
438const fade = (color, opacity) => {
439 const channel$1 = channel;
440 const r = channel$1(color, "r");
441 const g = channel$1(color, "g");
442 const b = channel$1(color, "b");
443 return rgba(r, g, b, opacity);
444};
445const getStyles = (options) => `.label {
446 font-family: ${options.fontFamily};
447 color: ${options.nodeTextColor || options.textColor};
448 }
449 .cluster-label text {
450 fill: ${options.titleColor};
451 }
452 .cluster-label span,p {
453 color: ${options.titleColor};
454 }
455
456 .label text,span,p {
457 fill: ${options.nodeTextColor || options.textColor};
458 color: ${options.nodeTextColor || options.textColor};
459 }
460
461 .node rect,
462 .node circle,
463 .node ellipse,
464 .node polygon,
465 .node path {
466 fill: ${options.mainBkg};
467 stroke: ${options.nodeBorder};
468 stroke-width: 1px;
469 }
470 .flowchart-label text {
471 text-anchor: middle;
472 }
473 // .flowchart-label .text-outer-tspan {
474 // text-anchor: middle;
475 // }
476 // .flowchart-label .text-inner-tspan {
477 // text-anchor: start;
478 // }
479
480 .node .katex path {
481 fill: #000;
482 stroke: #000;
483 stroke-width: 1px;
484 }
485
486 .node .label {
487 text-align: center;
488 }
489 .node.clickable {
490 cursor: pointer;
491 }
492
493 .arrowheadPath {
494 fill: ${options.arrowheadColor};
495 }
496
497 .edgePath .path {
498 stroke: ${options.lineColor};
499 stroke-width: 2.0px;
500 }
501
502 .flowchart-link {
503 stroke: ${options.lineColor};
504 fill: none;
505 }
506
507 .edgeLabel {
508 background-color: ${options.edgeLabelBackground};
509 rect {
510 opacity: 0.5;
511 background-color: ${options.edgeLabelBackground};
512 fill: ${options.edgeLabelBackground};
513 }
514 text-align: center;
515 }
516
517 /* For html labels only */
518 .labelBkg {
519 background-color: ${fade(options.edgeLabelBackground, 0.5)};
520 // background-color:
521 }
522
523 .cluster rect {
524 fill: ${options.clusterBkg};
525 stroke: ${options.clusterBorder};
526 stroke-width: 1px;
527 }
528
529 .cluster text {
530 fill: ${options.titleColor};
531 }
532
533 .cluster span,p {
534 color: ${options.titleColor};
535 }
536 /* .cluster div {
537 color: ${options.titleColor};
538 } */
539
540 div.mermaidTooltip {
541 position: absolute;
542 text-align: center;
543 max-width: 200px;
544 padding: 2px;
545 font-family: ${options.fontFamily};
546 font-size: 12px;
547 background: ${options.tertiaryColor};
548 border: 1px solid ${options.border2};
549 border-radius: 2px;
550 pointer-events: none;
551 z-index: 100;
552 }
553
554 .flowchartTitleText {
555 text-anchor: middle;
556 font-size: 18px;
557 fill: ${options.textColor};
558 }
559`;
560const flowStyles = getStyles;
561export {
562 applyStyle as a,
563 addHtmlLabel as b,
564 applyTransition as c,
565 applyClass as d,
566 edgeToId as e,
567 flowRendererV2 as f,
568 flowStyles as g,
569 isSubgraph as i,
570 selectAll as s
571};