Skip to content

Commit

Permalink
Fixes COSE TypeError by filtering the edges in the passed-in options …
Browse files Browse the repository at this point in the history
…(discards any edge that has a connected node not in the passed-in node collection) -- #3170
  • Loading branch information
chrtannus committed Oct 24, 2023
1 parent b1751b8 commit 19fb178
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/extensions/layout/cose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 19fb178

Please sign in to comment.