Skip to content

Commit 33bd4a8

Browse files
author
EggHsu
committed
Remove duplicate nodes or relations on update
1 parent 46dfc12 commit 33bd4a8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/main/scripts/neo4jd3.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,18 @@ function Neo4jD3(_selector, _options) {
895895
}
896896

897897
function updateNodes(n) {
898-
Array.prototype.push.apply(nodes, n);
898+
var distinctNodes = [];
899+
if (nodes.length > 0) {
900+
n.forEach(function(item, index, array) {
901+
if (contains(nodes, item.id))
902+
return;
903+
else
904+
distinctNodes.push(item);
905+
});
906+
} else
907+
distinctNodes = n;
908+
909+
Array.prototype.push.apply(nodes, distinctNodes);
899910

900911
node = svgNodes.selectAll('.node')
901912
.data(nodes, function(d) { return d.id; });
@@ -912,7 +923,18 @@ function Neo4jD3(_selector, _options) {
912923
}
913924

914925
function updateRelationships(r) {
915-
Array.prototype.push.apply(relationships, r);
926+
var distinctRelations = [];
927+
if (relationships.length > 0) {
928+
r.forEach(function(item, index, array) {
929+
if (contains(relationships, item.id))
930+
return;
931+
else
932+
distinctRelations.push(item);
933+
});
934+
} else
935+
distinctRelations = r;
936+
937+
Array.prototype.push.apply(relationships, distinctRelations);
916938

917939
relationship = svgRelationships.selectAll('.relationship')
918940
.data(relationships, function(d) { return d.id; });

0 commit comments

Comments
 (0)