From e228ba94820f3c84cab492347193728d85ff8734 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Fri, 17 Jul 2015 17:04:29 +0200 Subject: [PATCH] different fix for clustering, this one should work :) (sounds familiar) --- dist/vis.js | 38 +++++++----------------------- lib/network/modules/Clustering.js | 39 +++++++------------------------ 2 files changed, 16 insertions(+), 61 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index f6a7a2ea..7720713e 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -34394,36 +34394,14 @@ return /******/ (function(modules) { // webpackBootstrap if (this.body.edges[edgeId] !== undefined) { var edge = this.body.edges[edgeId]; - // if the edge is a clusterEdge, we delete it. The opening of the clusters will restore these edges when required. - if (edgeId.substr(0, 12) === 'clusterEdge:') { - // we only delete the cluster edge if there is another edge to the node that is not a cluster. - var target = edge.from.isCluster === true ? edge.toId : edge.fromId; - var deleteEdge = false; - - // search the contained edges for an edge that has a link to the targetNode - for (var edgeId2 in childEdgesObj) { - if (childEdgesObj.hasOwnProperty(edgeId2)) { - if (this.body.edges[edgeId2] !== undefined && edgeId2 !== edgeId) { - var edge2 = this.body.edges[edgeId2]; - if (edge2.fromId == target || edge2.toId == target) { - deleteEdge = true; - break; - } - } - } - } - - // if we found the edge that will trigger the recreation of a new cluster edge on opening, we can delete this edge. - if (deleteEdge === true) { - edge.edgeType.cleanup(); - // this removes the edge from node.edges, which is why edgeIds is formed - edge.disconnect(); - delete childEdgesObj[edgeId]; - delete this.body.edges[edgeId]; - } else { - edge.togglePhysics(false); - edge.options.hidden = true; - } + // if this is a cluster edge that is fully encompassed in the cluster, we want to delete it + // this check verifies that both of the connected nodes are in this cluster + if (edgeId.substr(0, 12) === 'clusterEdge:' && childNodesObj[edge.fromId] !== undefined && childNodesObj[edge.toId] !== undefined) { + edge.edgeType.cleanup(); + // this removes the edge from node.edges, which is why edgeIds is formed + edge.disconnect(); + delete childEdgesObj[edgeId]; + delete this.body.edges[edgeId]; } else { edge.togglePhysics(false); edge.options.hidden = true; diff --git a/lib/network/modules/Clustering.js b/lib/network/modules/Clustering.js index 1bb376ac..74d035de 100644 --- a/lib/network/modules/Clustering.js +++ b/lib/network/modules/Clustering.js @@ -380,37 +380,14 @@ class ClusterEngine { if (this.body.edges[edgeId] !== undefined) { let edge = this.body.edges[edgeId]; - // if the edge is a clusterEdge, we delete it. The opening of the clusters will restore these edges when required. - if (edgeId.substr(0,12) === "clusterEdge:") { - // we only delete the cluster edge if there is another edge to the node that is not a cluster. - let target = edge.from.isCluster === true ? edge.toId : edge.fromId; - let deleteEdge = false; - - // search the contained edges for an edge that has a link to the targetNode - for (let edgeId2 in childEdgesObj) { - if (childEdgesObj.hasOwnProperty(edgeId2)) { - if (this.body.edges[edgeId2] !== undefined && edgeId2 !== edgeId) { - let edge2 = this.body.edges[edgeId2]; - if (edge2.fromId == target || edge2.toId == target) { - deleteEdge = true; - break; - } - } - } - } - - // if we found the edge that will trigger the recreation of a new cluster edge on opening, we can delete this edge. - if (deleteEdge === true) { - edge.edgeType.cleanup(); - // this removes the edge from node.edges, which is why edgeIds is formed - edge.disconnect(); - delete childEdgesObj[edgeId]; - delete this.body.edges[edgeId]; - } - else { - edge.togglePhysics(false); - edge.options.hidden = true; - } + // if this is a cluster edge that is fully encompassed in the cluster, we want to delete it + // this check verifies that both of the connected nodes are in this cluster + if (edgeId.substr(0,12) === "clusterEdge:" && childNodesObj[edge.fromId] !== undefined && childNodesObj[edge.toId] !== undefined) { + edge.edgeType.cleanup(); + // this removes the edge from node.edges, which is why edgeIds is formed + edge.disconnect(); + delete childEdgesObj[edgeId]; + delete this.body.edges[edgeId]; } else { edge.togglePhysics(false);