cytoscape
Version:
Graph theory (a.k.a. network) library for analysis and visualisation
73 lines (54 loc) • 1.43 kB
JavaScript
import * as is from '../is';
import Collection from '../collection';
let corefn = ({
// get a collection
// - empty collection on no args
// - collection of elements in the graph on selector arg
// - guarantee a returned collection when elements or collection specified
collection: function( eles, opts ){
if( is.string( eles ) ){
return this.$( eles );
} else if( is.elementOrCollection( eles ) ){
return eles.collection();
} else if( is.array( eles ) ){
if (!opts) {
opts = {};
}
return new Collection( this, eles, opts.unique, opts.removed );
}
return new Collection( this );
},
nodes: function( selector ){
let nodes = this.$( function( ele ){
return ele.isNode();
} );
if( selector ){
return nodes.filter( selector );
}
return nodes;
},
edges: function( selector ){
let edges = this.$( function( ele ){
return ele.isEdge();
} );
if( selector ){
return edges.filter( selector );
}
return edges;
},
// search the graph like jQuery
$: function( selector ){
let eles = this._private.elements;
if( selector ){
return eles.filter( selector );
} else {
return eles.spawnSelf();
}
},
mutableElements: function(){
return this._private.elements;
}
});
// aliases
corefn.elements = corefn.filter = corefn.$;
export default corefn;