-1

I have a d3 tree and I want to be able to right click the node so that a new file is opened which lists the children of that node. How do I do this? Thank you

Veda
  • 21
  • 1
  • 1

1 Answers1

6

In your code where you are creating the nodes and it's attributes you add...

.on('contextmenu',/* handler */);

So an example of this used in code would be...

node.enter().append("g")
        .attr("class", "node")
        .on('dblclick', /* handler for double click */ )
        .on('contextmenu', /* handler for right click */ );

As for reading in the file which I am assuming is a local text file you can reference

Javascript - read local text file

and just call the function you create in the .on.

.on('contextmenu', functionForReadFile);

Community
  • 1
  • 1
Joey
  • 1,724
  • 3
  • 18
  • 38
  • thank you very much, i would like it to open a new json file that lists the children though, not read in a file, if that makes sense – Veda May 18 '15 at 20:59
  • It sounds like you want to 'create' a new file, can't open a new one if it doesn't exist. Are you wanting it to show the json data and have it save to a file? – Mike Weber May 18 '15 at 22:40