mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 00:40:22 +02:00
chore: Cleanup flowRenderer-v3-unified.ts
This commit is contained in:
@@ -29,7 +29,6 @@ export const setConf = function (cnf) {
|
|||||||
*/
|
*/
|
||||||
export const addVertices = async function (vert, g, svgId, root, doc, diagObj) {
|
export const addVertices = async function (vert, g, svgId, root, doc, diagObj) {
|
||||||
const svg = root.select(`[id="${svgId}"]`);
|
const svg = root.select(`[id="${svgId}"]`);
|
||||||
// console.log('SVG:', svg, svg.node(), 'root:', root, root.node());
|
|
||||||
|
|
||||||
const keys = vert.keys();
|
const keys = vert.keys();
|
||||||
|
|
||||||
|
@@ -9,16 +9,6 @@ import type { LayoutData } from '../../rendering-util/types.js';
|
|||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
import { getDirection } from './flowDb.js';
|
import { getDirection } from './flowDb.js';
|
||||||
|
|
||||||
// Configuration
|
|
||||||
const conf: Record<string, any> = {};
|
|
||||||
|
|
||||||
export const setConf = function (cnf: Record<string, any>) {
|
|
||||||
const keys = Object.keys(cnf);
|
|
||||||
for (const key of keys) {
|
|
||||||
conf[key] = cnf[key];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getClasses = function (
|
export const getClasses = function (
|
||||||
text: string,
|
text: string,
|
||||||
diagramObj: any
|
diagramObj: any
|
||||||
@@ -40,8 +30,6 @@ export const draw = async function (text: string, id: string, _version: string,
|
|||||||
// @ts-ignore - document is always available
|
// @ts-ignore - document is always available
|
||||||
const doc = securityLevel === 'sandbox' ? sandboxElement.nodes()[0].contentDocument : document;
|
const doc = securityLevel === 'sandbox' ? sandboxElement.nodes()[0].contentDocument : document;
|
||||||
|
|
||||||
const DIR = getDirection();
|
|
||||||
|
|
||||||
// The getData method provided in all supported diagrams is used to extract the data from the parsed structure
|
// The getData method provided in all supported diagrams is used to extract the data from the parsed structure
|
||||||
// into the Layout data format
|
// into the Layout data format
|
||||||
log.debug('Before getData: ');
|
log.debug('Before getData: ');
|
||||||
@@ -52,7 +40,7 @@ export const draw = async function (text: string, id: string, _version: string,
|
|||||||
|
|
||||||
data4Layout.type = diag.type;
|
data4Layout.type = diag.type;
|
||||||
data4Layout.layoutAlgorithm = layout;
|
data4Layout.layoutAlgorithm = layout;
|
||||||
data4Layout.direction = DIR;
|
data4Layout.direction = getDirection();
|
||||||
data4Layout.nodeSpacing = conf?.nodeSpacing || 50;
|
data4Layout.nodeSpacing = conf?.nodeSpacing || 50;
|
||||||
data4Layout.rankSpacing = conf?.rankSpacing || 50;
|
data4Layout.rankSpacing = conf?.rankSpacing || 50;
|
||||||
data4Layout.markers = ['point', 'circle', 'cross'];
|
data4Layout.markers = ['point', 'circle', 'cross'];
|
||||||
@@ -70,10 +58,11 @@ export const draw = async function (text: string, id: string, _version: string,
|
|||||||
setupViewPortForSVG(svg, padding, 'flowchart', conf?.useMaxWidth || false);
|
setupViewPortForSVG(svg, padding, 'flowchart', conf?.useMaxWidth || false);
|
||||||
|
|
||||||
// If node has a link, wrap it in an anchor SVG object.
|
// If node has a link, wrap it in an anchor SVG object.
|
||||||
data4Layout.nodes.forEach((vertex) => {
|
for (const vertex of data4Layout.nodes) {
|
||||||
if (vertex.link) {
|
const node = select(`#${id} [id="${vertex.id}"]`);
|
||||||
const node = select('#' + id + ' [id="' + vertex.id + '"]');
|
if (!node || !vertex.link) {
|
||||||
if (node) {
|
continue;
|
||||||
|
}
|
||||||
const link = doc.createElementNS('http://www.w3.org/2000/svg', 'a');
|
const link = doc.createElementNS('http://www.w3.org/2000/svg', 'a');
|
||||||
link.setAttributeNS('http://www.w3.org/2000/svg', 'class', vertex.cssClasses);
|
link.setAttributeNS('http://www.w3.org/2000/svg', 'class', vertex.cssClasses);
|
||||||
link.setAttributeNS('http://www.w3.org/2000/svg', 'rel', 'noopener');
|
link.setAttributeNS('http://www.w3.org/2000/svg', 'rel', 'noopener');
|
||||||
@@ -101,12 +90,9 @@ export const draw = async function (text: string, id: string, _version: string,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setConf,
|
|
||||||
getClasses,
|
getClasses,
|
||||||
draw,
|
draw,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user