Skip to content

Commit

Permalink
Merge pull request #3178 from cytoscape/fix/cose-3170
Browse files Browse the repository at this point in the history
Fixes COSE TypeError by filtering the edges in the passed-in options

Cherry-pick to 3.25.x
  • Loading branch information
maxkfranz committed Oct 26, 2023
1 parent 86d0ce4 commit 55b4f3a
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 55b4f3a

Please sign in to comment.