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

Highlighting multiple levels of parent/child relationships #3

Open
nylen opened this issue Jul 6, 2014 · 0 comments
Open

Highlighting multiple levels of parent/child relationships #3

nylen opened this issue Jul 6, 2014 · 0 comments

Comments

@nylen
Copy link
Owner

nylen commented Jul 6, 2014

Right now the code highlights immediate parent and child nodes when you hover or click a node. A couple of people have asked about making this behavior configurable (e.g. highlight X levels of parents and Y levels of children).

Here are the code changes that would be needed to make this work:

Have a look at the highlightObject function. Right now it adds the inactive class to nodes which are not the current node and are not a child or parent of the current node. You would need to change this function to find all the nodes and edges you want to highlight. I would probably do this as follows:

  • Start with the node being highlighted, and walk up and down the tree (loop over depends and dependedOnBy), setting a property like highlightThis to true on each node that should be highlighted. If you find a node that already has highlightThis set, you’re in a cycle of the graph, so stop to avoid infinite recursion.
  • Use the highlightThis property you just set to determine whether to set the inactive class on each node.
  • Loop over all edges (graph.lines) and remove the inactive class if the source and target are both highlighted, otherwise add the inactive class.
  • Finally, loop over all nodes again and delete node.highlightThis;.

That’s the simplest algorithm I can think of that’s not O(n^2) or worse. I’d accept a pull request for this, if the code is clean and there are some options added to config.json to support the new behavior.

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

No branches or pull requests

1 participant