0

Making mobile application with phonejs, I'm using d3.js with force layout. I want to add some functionality when node of d3 is double-tapped or held-with-tap. But double-click event does not do anything in phone. I also tried jQuery touch events but didn't work here. How can I put touch event on node of d3?

Here is the node:

node = container.append("g").selectAll("image.node")
      .data(nodes_edges_json.nodes)
      .enter().appent("g").append("svg:image")
      .attr("class", "node")
      .attr("xlink:href", function(nodeObj) { return setImage(nodeObj); })
      .attr("width", function(nodeObj) { return setHeightWidth(nodeObj); })
      .attr("height", function(nodeObj) { return setHeightWidth(nodeObj); })
      .on("dblclick", function(data, index) {
           d3.event.preventDefault();
           getdata(data, index);
       });
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
Alina
  • 130
  • 1
  • 13
  • [This question](http://stackoverflow.com/questions/11895682/is-there-a-tap-and-double-tap-event-in-d3-js) should help. – Lars Kotthoff Mar 18 '14 at 09:09
  • I tried that but didn't work..@Lars Kotthoff – Alina Mar 18 '14 at 09:25
  • Have you tried to use `touchstart`? – MarcoL Mar 18 '14 at 09:42
  • touchstart event is identified but I want taphold or double-tab event on node..@MacroCI – Alina Mar 18 '14 at 10:46
  • I think you have to use another library to support that, because you need timers for that. For double tap have a look to this other answer: http://stackoverflow.com/questions/13479236/d3-js-double-tap while for tap hold this one could be useful as well: http://stackoverflow.com/questions/2625210/long-press-in-javascript More, have a look to this gist: http://bl.ocks.org/eweitnauer/7144421 – MarcoL Mar 18 '14 at 11:08
  • Thanks @MarcoCl... mouseup and mousedown events worked for me.. – Alina Mar 30 '14 at 19:32

1 Answers1

0

I would make a suggestion that you look into http://eightmedia.github.io/hammer.js/ I had the same issue and had to go against using the dxhold option. Hammer worked great though.

Ohtilob
  • 56
  • 2