chore: Cleanup flowRenderer-v3-unified.ts

This commit is contained in:
Sidharth Vinod
2024-06-28 22:00:11 +05:30
parent 3b2c751cd2
commit b1b5ad3c9b
2 changed files with 32 additions and 47 deletions

View File

@@ -29,7 +29,6 @@ export const setConf = function (cnf) {
*/
export const addVertices = async function (vert, g, svgId, root, doc, diagObj) {
const svg = root.select(`[id="${svgId}"]`);
// console.log('SVG:', svg, svg.node(), 'root:', root, root.node());
const keys = vert.keys();

View File

@@ -9,16 +9,6 @@ import type { LayoutData } from '../../rendering-util/types.js';
import utils from '../../utils.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 (
text: string,
diagramObj: any
@@ -40,8 +30,6 @@ export const draw = async function (text: string, id: string, _version: string,
// @ts-ignore - document is always available
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
// into the Layout data format
log.debug('Before getData: ');
@@ -52,7 +40,7 @@ export const draw = async function (text: string, id: string, _version: string,
data4Layout.type = diag.type;
data4Layout.layoutAlgorithm = layout;
data4Layout.direction = DIR;
data4Layout.direction = getDirection();
data4Layout.nodeSpacing = conf?.nodeSpacing || 50;
data4Layout.rankSpacing = conf?.rankSpacing || 50;
data4Layout.markers = ['point', 'circle', 'cross'];
@@ -70,43 +58,41 @@ export const draw = async function (text: string, id: string, _version: string,
setupViewPortForSVG(svg, padding, 'flowchart', conf?.useMaxWidth || false);
// If node has a link, wrap it in an anchor SVG object.
data4Layout.nodes.forEach((vertex) => {
if (vertex.link) {
const node = select('#' + id + ' [id="' + vertex.id + '"]');
if (node) {
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', 'rel', 'noopener');
if (securityLevel === 'sandbox') {
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', '_top');
} else if (vertex.linkTarget) {
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', vertex.linkTarget);
}
const linkNode = node.insert(function () {
return link;
}, ':first-child');
const shape = node.select('.label-container');
if (shape) {
linkNode.append(function () {
return shape.node();
});
}
const label = node.select('.label');
if (label) {
linkNode.append(function () {
return label.node();
});
}
}
for (const vertex of data4Layout.nodes) {
const node = select(`#${id} [id="${vertex.id}"]`);
if (!node || !vertex.link) {
continue;
}
});
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', 'rel', 'noopener');
if (securityLevel === 'sandbox') {
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', '_top');
} else if (vertex.linkTarget) {
link.setAttributeNS('http://www.w3.org/2000/svg', 'target', vertex.linkTarget);
}
const linkNode = node.insert(function () {
return link;
}, ':first-child');
const shape = node.select('.label-container');
if (shape) {
linkNode.append(function () {
return shape.node();
});
}
const label = node.select('.label');
if (label) {
linkNode.append(function () {
return label.node();
});
}
}
};
export default {
setConf,
getClasses,
draw,
};