#1704 handling of subgraph data

This commit is contained in:
Knut Sveidqvist
2020-10-07 20:16:36 +02:00
parent 8ec99cb244
commit 4b2d98129e
4 changed files with 128 additions and 60 deletions

View File

@@ -454,19 +454,8 @@ export const addSubGraph = function(_id, list, _title) {
subCount = subCount + 1;
const subGraph = { id: id, nodes: nodeList, title: title.trim(), classes: [] };
/**
* Deletes an id from all subgraphs
*/
const del = _id => {
subGraphs.forEach(sg => {
const pos = sg.nodes.indexOf(_id);
if (pos >= 0) {
sg.nodes.splice(pos, 1);
}
});
};
// Removes the members of this subgraph from any other subgraphs, a node only belong to one subgraph
subGraph.nodes.forEach(_id => del(_id));
// Remove the members in the new subgraph if they already belong to another subgraph
subGraph.nodes.nodes = makeUniq(subGraph, subGraphs);
subGraphs.push(subGraph);
subGraphLookup[id] = subGraph;
return id;
@@ -664,6 +653,31 @@ const destructLink = (_str, _startStr) => {
return info;
};
// Todo optimizer this by caching existing nodes
const exists = (allSgs, _id) => {
let res = false;
allSgs.forEach(sg => {
const pos = sg.nodes.indexOf(_id);
if (pos >= 0) {
res = true;
}
});
return res;
};
/**
* Deletes an id from all subgraphs
*/
const makeUniq = (sg, allSubgraphs) => {
const res = [];
sg.nodes.forEach((_id, pos) => {
console.log('Checking: ', _id);
if (!exists(allSubgraphs, _id)) {
res.push(sg.nodes[pos]);
}
});
return { nodes: res };
};
export default {
parseDirective,
defaultConfig: () => configApi.defaultConfig.flowchart,
@@ -693,5 +707,7 @@ export default {
destructLink,
lex: {
firstGraph
}
},
exists,
makeUniq
};