Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ele.component() #1878

maxkfranz opened this issue Jul 4, 2017 · 2 comments

ele.component() #1878

maxkfranz opened this issue Jul 4, 2017 · 2 comments


Copy link

eles.components() gives all components of the elements in the calling collection. It would be nice to have ele.component() that gives the component of a node or an edge.

ele.component() would have to take into account all the elements in the graph --- i.e. you can't specify a subset of elements to consider. For those cases, it's better to use eles.components().

@maxkfranz maxkfranz added this to the future milestone Jul 4, 2017
Copy link

shabble commented Apr 20, 2018

is this as simple as something like:

function (ele) {
    let compEles = new Set(); 
    cy.elements().breadthFirstSearch({ root: ele, visit: (v) => { compEles.add(v) }} );
   return compEles;

or is there some better algorithm to use?

If it's as simple as above I can try to look at making a PR for it.

Copy link
Member Author

More or less. You'd use a new cy.collection() and merge() for internal functions for performance. It's basically the existing ele.components() function implementation but only using one node as input rather than all nodes.

@maxkfranz maxkfranz self-assigned this Jan 17, 2019
maxkfranz added a commit that referenced this issue Jan 18, 2019
- Repurpose `eles.components()` to be more general by allowing setting of the `root` collection -- components that `root` nodes belong to will be returned.  The signature is now `eles.components(root)`, where `root` is `eles.nodes()` by default.
- The repurposing of `eles.components()` makes it so `ele.component()` is basically a one-liner.
- Improve performance a bit by avoiding intermediary collections.
- Add `eles.componentsOf()` alias.

Ref #1878
@maxkfranz maxkfranz modified the milestones: future, 3.4.0 Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants