vasturiano/force-graph

hot to draw a image on click?

Lora336 opened this issue · 1 comments

Hi, @vasturiano !

In my case,
I am using images as a node.

When one of the nodes is clicked, I want to add a 'flag image' above it. (new image, not node)

flag images

and then,
I try this code, but nodes disappeared.....
what happened...?

I want just add a image above the node
thank you

https://codesandbox.io/s/force-graph-svg-images-5zbkp?file=/index.js

this is my code, add a image

myGraph
            .graphData(_nowgData)
            .nodeCanvasObjectMode(() => 'replace')
            .nodeCanvasObject(({}, ctx) => {
                ctx.drawImage(imgs[12], objectX, objectY - 100, 50, 50);
            })

@Lora336 you can use the onNodeClick to mark the node that you wish to change the appearance of. Then in your nodeCanvasObject((node, ctx) => ...) function you can selectively choose a different draw pattern when you encounter the node you have previously clicked.