Skip to content

Commit

Permalink
refactor: Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Dec 7, 2023
1 parent 65a08ef commit 867686f
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions packages/mermaid/src/diagrams/flowchart/flowDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,22 @@ export const lookUpDomId = function (id: string) {
*
*/
export const addVertex = function (
_id: string,
id: string,
textObj: FlowText,
type: 'group',
style: string[],
classes: string[],
dir: string,
props = {}
) {
let txt;
const id = _id;
if (id === undefined) {
return;
}
if (id.trim().length === 0) {
if (!id || id.trim().length === 0) {
return;
}
let txt;

if (vertices[id] === undefined) {
vertices[id] = {
id: id,
id,
labelType: 'text',
domId: MERMAID_DOM_ID_PREFIX + id + '-' + vertexCounter,
styles: [],
Expand All @@ -95,7 +91,7 @@ export const addVertex = function (
vertices[id].text = txt;
} else {
if (vertices[id].text === undefined) {
vertices[id].text = _id;
vertices[id].text = id;
}
}
if (type !== undefined) {
Expand Down Expand Up @@ -255,24 +251,24 @@ export const setDirection = function (dir: string) {
* @param className - Class to add
*/
export const setClass = function (ids: string, className: string) {
ids.split(',').forEach(function (_id) {
const id = _id;
if (vertices[id] !== undefined) {
for (const id of ids.split(',')) {
if (vertices[id]) {
vertices[id].classes.push(className);
}

if (subGraphLookup[id] !== undefined) {
if (subGraphLookup[id]) {
subGraphLookup[id].classes.push(className);
}
});
}
};

const setTooltip = function (ids: string, tooltip: string) {
ids.split(',').forEach(function (id) {
if (tooltip !== undefined) {
tooltips[version === 'gen-1' ? lookUpDomId(id) : id] = sanitizeText(tooltip);
}
});
if (!tooltip) {
return;
}
tooltip = sanitizeText(tooltip);
for (const id of ids.split(',')) {
tooltips[version === 'gen-1' ? lookUpDomId(id) : id] = tooltip;
}
};

const setClickFun = function (id: string, functionName: string, functionArgs: string) {
Expand Down Expand Up @@ -491,10 +487,7 @@ export const addSubGraph = function (
return { nodeList, dir };
}

let nodeList: string[] = [];

const { nodeList: nl, dir } = uniq(list.flat());
nodeList = nl;
const { nodeList, dir } = uniq(list.flat());
if (version === 'gen-1') {
for (let i = 0; i < nodeList.length; i++) {
nodeList[i] = lookUpDomId(nodeList[i]);
Expand Down

0 comments on commit 867686f

Please sign in to comment.