score:3
Accepted answer
You can distinguish between single click and double click using setTimeout
, check the demo:
var timeout = null;
d3.select('rect').on("click", function(d) {
clearTimeout(timeout);
timeout = setTimeout(function() {
console.clear();
console.log("node was single clicked", new Date());
}, 300)
})
.on("dblclick", function(d) {
clearTimeout(timeout);
console.clear();
console.log("node was double clicked", new Date());
});
rect {
fill: steelblue;
}
<script src="https://d3js.org/d3.v4.min.js"></script>
Open the console and click / double click on the rect:
<svg width="400" height="110">
<rect width="100" height="100" />
</svg>
Source: stackoverflow.com
Related Query
- Both single and double click on a node in d3 force directed graph
- Add text label to d3 node in Force directed Graph and resize on hover
- D3 force directed graph with drag and drop support to make selected node position fixed when dropped
- Is there a tap and double tap event in d3.js force directed graph
- how to distinguish between single mouse click and double click on same node element in d3 js
- d3js Force Directed Graph - Click on node to popup infobox which read from JSON
- Highlight a node and its neighbour node in force directed graph
- D3 force directed layout - changing node color and its links color on button click
- d3 force directed graph, focus on node double click
- force directed graph - define the color of a node, if the node is source and target at the same time
- how to display the node attributes like person's name photo and address in a force directed graph
- Highlight selected node, its links, and its children in a D3 force directed graph
- D3 highlight selected node, and its links to parent and ancestors in a force directed graph
- Prevent node overlap in force directed graph
- Zooming and brushing in d3 force directed graph
- How to calculate in-degree, out-degree and weigted degree for force directed graph (d3.js)?
- Freezing force directed network graph and make draggable in D3
- How do I make a d3.js force directed graph interactive using ajax and python?
- D3v4 force directed graph - localStorage disconnects links and nodes
- Interactively fixing a node in a directed force graph
- Zooming to a clicked node on a D3 Force Directed Graph
- Updating nodes and links with labels in d3 force directed network graph is not removing the nodes properly
- D3 force directed graph node - text is being duplicated when expading
- D3js - Force directed graph - advanced highlighting of neigbour nodes and links, is it possible?
- how to highlight(change color) of all connected(neighbours) nodes and links in a d3 force directed graph
- d3 force directed graph using node names for links
- How to show edges in force directed graph using d3.js and Angular?
- End points of the links of the force directed graph always stuck to left corner of the rectangular node
- force directed graph change color of all connected node on mouseover
- How to make d3js force directed graph less shaky when a node is dragged?
More Query from same tag
- why yAxisBar is not showing correct data, D3
- How to create linked (href) labels in a d3 circle packing chart?
- how to give href to d3js text element
- plot dots on multiple lines in line chart
- My developer visual stops working after declaring an object using d3-scale function
- How to mask svg image with a rectangle using d3?
- how to highlight a bar in stacked bar chart d3.js v4
- Freeze Y-Axis label in d3.js
- How to append text to d3js dispatch chart
- d3js Tree Layout vertical distance between text of circle overlaps
- Dynamic onclick inside attr?
- Using public variables and interfaces in external libraries when using Typescript
- How to programmatically trigger a D3 drag event?
- Line() in d3 generating NaN
- Auto updating Tree issue
- How to show the d3 chart inside the div
- dc.js multi line series chart filtering
- Rotate objects in D3.js
- Only part of y axis and no x-axis being displayed d3.js
- Looping transition in D3 version 4 and 5
- Capturing the visualization created by D3 Library and storing the state in DB
- Uncaught TypeError: (void 0) is not a function using d3 with angular 7
- Backbone JS fire event upon rendering template
- Standard/best color schema for D3.js
- D3 V4 ticks line x1 value
- How to update max value of Radial Progress Chart
- Add html content with line break inside d3 circle
- how to load a json object instead of json file
- How to make a scatterplot based upon certain criteria using d3.js
- Changing the orientation of the Stacked bar Chart from Vertical to Horizontal in D3