react-force-graph icon indicating copy to clipboard operation
react-force-graph copied to clipboard

Dim background onclick

Open rohankk2 opened this issue 7 years ago • 5 comments

Is there a way to dim the background when i zoom onto a node. For example : https://graphics.straitstimes.com/STI/STIMEDIA/Interactives/2018/04/marvel-cinematic-universe-whos-who-interactive/index.html

if you see this when you click a node it zooms onto that node and sort of dims the other nodes out

rohankk2 avatar Jul 24 '19 18:07 rohankk2

@rohankk2 that should be doable. On click event just call .nodeColor(node => ...)and set a lower alpha channel of the rgba for the nodes that you wish to dim. Similar pattern to the highlight example: https://vasturiano.github.io/react-force-graph/example/highlight/

As for click to focus, there's another example for that: https://vasturiano.github.io/react-force-graph/example/click-to-focus/

vasturiano avatar Jul 25 '19 03:07 vasturiano

But the onclick event only gives me access to the current node right ? how do i dim out the others ?

rohankk2 avatar Jul 28 '19 02:07 rohankk2

@rohankk2 you can set a "selectedNode" state, like so:

onNodeClick = { node => this.setState({ selectedNode: node }) }

and then set your nodeColor function to depend on that state, for example:

nodeColor={ node => node === this.state.selectedNode ? 'rgba(255,0,0,1)' : 'rgba(255,0,0,0.5)' }

vasturiano avatar Jul 28 '19 19:07 vasturiano

But it considers only selected node at a time, how to dim neighbours and links @rohankk2

chaitali-pathak avatar Aug 07 '20 14:08 chaitali-pathak

nodeColor function will get called for all the nodes in the graph

nirmal495 avatar Nov 02 '20 11:11 nirmal495