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
  • Loading branch information
maxkfranz authored Oct 26, 2023
2 parents b1751b8 + 19fb178 commit edd0810
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 edd0810

Please sign in to comment.