nylen / d3-process-map

Web application to illustrate the relationships between objects in a process using d3.js.
MIT License
417 stars 196 forks source link

Highlighting multiple levels of parent/child relationships #3

Open nylen opened 10 years ago

nylen commented 10 years ago

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:

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.