Add jsdoc and refactor a bit of code

This commit is contained in:
Yash-Singh1
2021-11-06 19:36:06 -07:00
parent 66d4d9d5b8
commit d2d8c9bc8e
18 changed files with 21590 additions and 35968 deletions

View File

@@ -25,8 +25,8 @@ const conf = {
/**
* Function that adds the vertices found during parsing to the graph to be rendered.
* @param vert Object containing the vertices.
* @param g The graph that is to be drawn.
* @param {Object<string, { cssClasses: Array<string>; text: string; id: string; type: string; domId: string; }>} classes Object containing the vertices.
* @param {SVGGElement} g The graph that is to be drawn.
*/
export const addClasses = function (classes, g) {
// const svg = select(`[id="${svgId}"]`);
@@ -226,19 +226,23 @@ export const addRelations = function (relations, g) {
});
};
// Todo optimize
/**
* Gets the ID with the same label as in the cache
* @param {string} label The label to look for
* @returns {string} The resulting ID
*/
const getGraphId = function (label) {
const keys = Object.keys(idCache);
const foundEntry = Object.entries(idCache).find((entry) => entry[1].label === label);
for (let i = 0; i < keys.length; i++) {
if (idCache[keys[i]].label === label) {
return keys[i];
}
if (foundEntry) {
return foundEntry[0];
}
return undefined;
};
/**
* Merges the value of `conf` with the passed `cnf`
* @param {Object} cnf Config to merge
*/
export const setConf = function (cnf) {
const keys = Object.keys(cnf);
@@ -249,8 +253,8 @@ export const setConf = function (cnf) {
/**
* Draws a flowchart in the tag with id: id based on the graph definition in text.
* @param text
* @param id
* @param {string} text
* @param {string} id
*/
export const drawOld = function (text, id) {
idCache = {};
@@ -498,10 +502,11 @@ export const draw = function (text, id) {
// });
};
export default {
setConf,
draw,
};
/**
* Gets the arrow marker for a type index
* @param {number} type The type to look for
* @returns {"aggregation" | "extension" | "composition" | "dependency"} The arrow marker
*/
function getArrowMarker(type) {
let marker;
switch (type) {
@@ -522,3 +527,8 @@ function getArrowMarker(type) {
}
return marker;
}
export default {
setConf,
draw,
};