From 19fb17857005294b45a49e77dcd45d5981d24edf Mon Sep 17 00:00:00 2001 From: Christian Lopes Date: Tue, 24 Oct 2023 15:46:39 -0300 Subject: [PATCH] Fixes COSE TypeError by filtering the edges in the passed-in options (discards any edge that has a connected node not in the passed-in node collection) -- #3170 --- src/extensions/layout/cose.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/extensions/layout/cose.js b/src/extensions/layout/cose.js index 38e5251724..3114c4cdab 100644 --- a/src/extensions/layout/cose.js +++ b/src/extensions/layout/cose.js @@ -105,8 +105,19 @@ var defaults = { */ function CoseLayout( options ){ this.options = util.extend( {}, defaults, options ); - this.options.layout = this; + + // Exclude any edge that has a source or target node that is not in the set of passed-in nodes + const nodes = this.options.eles.nodes(); + const edges = this.options.eles.edges(); + const notEdges = edges.filter((e) => { + const sourceId = e.source().data('id'); + const targetId = e.target().data('id'); + const hasSource = nodes.some((n) => n.data('id') === sourceId); + const hasTarget = nodes.some((n) => n.data('id') === targetId); + return !hasSource || !hasTarget; + }); + this.options.eles = this.options.eles.not(notEdges); } /**