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

Tree traversal. #6

Closed
mbostock opened this issue Sep 30, 2010 · 4 comments
Closed

Tree traversal. #6

mbostock opened this issue Sep 30, 2010 · 4 comments
Milestone

Comments

@mbostock
Copy link
Member

More tree traversal methods are needed. Potentially:

  • parent - select parent node.
  • previous - select previous sibling.
  • next - select next sibling.
  • firstChild - select first child.
  • lastChild - select last child.
  • children - select all (immediate) children.

Some convenience filtering method might also be useful:

  • first - filter selection to the first node.
  • last - filter selection to the last node.
  • slice(start[, end]) - filter selection to the given subset by index.
@mbostock
Copy link
Member Author

One of the difficulties here is the semantics of parent selection; you basically need the inverse of the select and selectAll methods. For example, if you select-all a bunch of siblings, and you want to select the parent, you probably just want to select that parent once. On the other hand, if you select-all a bunch of divs, then sub-select a child paragraph for each, when selecting the parent you probably want all the parent divs.

I suppose a general solution would be to detect when the parent nodes are the same, and then coalesce, but the grouping of the nodes is important, too. Should selecting the parent (or the parents) return one group or many? Maybe selectParent and selectParents?

@mbostock
Copy link
Member Author

Also, if you allow xpath expressions for selection, this problem is simpler because then you can use the existing select methods.

@mbostock
Copy link
Member Author

In 2.0.0, you can pass arbitrary functions to select and selectAll. That's good enough for now.

@kanitw
Copy link

kanitw commented Sep 15, 2015

Looks like it's undocumented that we can pass arbitrary function to select and selectAll.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants