Skip to content

Commit

Permalink
Resolved Bug on collapseEdges function #31
Browse files Browse the repository at this point in the history
  • Loading branch information
osamazafar980 committed Sep 28, 2023
1 parent 307a163 commit 74458c5
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 40 deletions.
32 changes: 23 additions & 9 deletions dist/cytoscape-complexity-management.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,19 +659,33 @@ function complexityManagement(cy) {
actOnInvisible([].concat(_toConsumableArray(returnedElements.edgeIDListToRemove), cleanup), cy);
};
api.collapseEdges = function (edges) {
var edgeIDList = [];
var groupedEdges = new Map();

// Iterate through the edges and group them by their end nodes (regardless of direction)
edges.forEach(function (edge) {
edgeIDList.push(edge.id());
var edgeKey = [edge.source().id(), edge.target().id()].sort().join('-');
// If the edge key is not in the Map, create a new entry
if (!groupedEdges.has(edgeKey)) {
groupedEdges.set(edgeKey, [edge.id()]);
} else {
// If the edge key is already in the Map, append the edge to the existing list
groupedEdges.get(edgeKey).push(edge.id());
}
});
if (edgeIDList.length > 1) {
var metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);
// Convert the Map to an array of arrays
var ListOfEdgeIDList = Array.from(groupedEdges.values());
ListOfEdgeIDList.forEach(function (edgeIDList) {
if (edgeIDList.length > 1) {
var metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
});
};
api.collapseEdgesBetweenNodes = function (nodes) {
var nodeIDList = [];
Expand Down
32 changes: 23 additions & 9 deletions dist/cytoscape-complexity-management.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,19 +657,33 @@ function complexityManagement(cy) {
actOnInvisible([].concat(_toConsumableArray(returnedElements.edgeIDListToRemove), cleanup), cy);
};
api.collapseEdges = function (edges) {
var edgeIDList = [];
var groupedEdges = new Map();

// Iterate through the edges and group them by their end nodes (regardless of direction)
edges.forEach(function (edge) {
edgeIDList.push(edge.id());
var edgeKey = [edge.source().id(), edge.target().id()].sort().join('-');
// If the edge key is not in the Map, create a new entry
if (!groupedEdges.has(edgeKey)) {
groupedEdges.set(edgeKey, [edge.id()]);
} else {
// If the edge key is already in the Map, append the edge to the existing list
groupedEdges.get(edgeKey).push(edge.id());
}
});
if (edgeIDList.length > 1) {
var metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);
// Convert the Map to an array of arrays
var ListOfEdgeIDList = Array.from(groupedEdges.values());
ListOfEdgeIDList.forEach(function (edgeIDList) {
if (edgeIDList.length > 1) {
var metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
});
};
api.collapseEdgesBetweenNodes = function (nodes) {
var nodeIDList = [];
Expand Down
32 changes: 23 additions & 9 deletions dist/cytoscape-complexity-management.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5021,19 +5021,33 @@
actOnInvisible([].concat(_toConsumableArray(returnedElements.edgeIDListToRemove), cleanup), cy);
};
api.collapseEdges = function (edges) {
var edgeIDList = [];
var groupedEdges = new Map();

// Iterate through the edges and group them by their end nodes (regardless of direction)
edges.forEach(function (edge) {
edgeIDList.push(edge.id());
var edgeKey = [edge.source().id(), edge.target().id()].sort().join('-');
// If the edge key is not in the Map, create a new entry
if (!groupedEdges.has(edgeKey)) {
groupedEdges.set(edgeKey, [edge.id()]);
} else {
// If the edge key is already in the Map, append the edge to the existing list
groupedEdges.get(edgeKey).push(edge.id());
}
});
if (edgeIDList.length > 1) {
var metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);
// Convert the Map to an array of arrays
var ListOfEdgeIDList = Array.from(groupedEdges.values());
ListOfEdgeIDList.forEach(function (edgeIDList) {
if (edgeIDList.length > 1) {
var metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
});
};
api.collapseEdgesBetweenNodes = function (nodes) {
var nodeIDList = [];
Expand Down
41 changes: 28 additions & 13 deletions src/complexity-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,35 @@ export function complexityManagement(cy) {
};

api.collapseEdges = (edges) => {
let edgeIDList = [];

edges.forEach((edge) => {
edgeIDList.push(edge.id());
});
if (edgeIDList.length > 1) {
let metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);
const groupedEdges = new Map();

// Iterate through the edges and group them by their end nodes (regardless of direction)
edges.forEach(edge => {
const edgeKey = [edge.source().id(), edge.target().id()].sort().join('-');
// If the edge key is not in the Map, create a new entry
if (!groupedEdges.has(edgeKey)) {
groupedEdges.set(edgeKey, [edge.id()]);
} else {
// If the edge key is already in the Map, append the edge to the existing list
groupedEdges.get(edgeKey).push(edge.id());
}
});

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
// Convert the Map to an array of arrays
const ListOfEdgeIDList = Array.from(groupedEdges.values());

ListOfEdgeIDList.forEach(edgeIDList => {
if (edgeIDList.length > 1) {
let metaEdgeID = compMgrInstance.collapseEdges(edgeIDList);

// Remove required elements from cy instance
actOnInvisible(edgeIDList, cy);

// Add required meta edges to cy instance
actOnVisibleForMetaEdge(metaEdgeID, cy);
}
})

};

api.collapseEdgesBetweenNodes = (nodes) => {
Expand Down

0 comments on commit 74458c5

Please sign in to comment.