score:2
as the changelog states, rebind
can be replaced by implementing a simple wrapper function.
cc.on = function() {
var value = event.on.apply(event, arguments);
return value === event ? cc : value;
};
return cc;
function clickcancel() {
var event = d3.dispatch('click', 'dblclick');
function cc(selection) {
var down,
tolerance = 5,
last,
wait = null;
// euclidean distance
function dist(a, b) {
return math.sqrt(math.pow(a[0] - b[0], 2), math.pow(a[1] - b[1], 2));
}
selection.on('mousedown', function() {
down = d3.mouse(document.body);
last = +new date();
});
selection.on('mouseup', function() {
if (dist(down, d3.mouse(document.body)) > tolerance) {
return;
} else {
if (wait) {
window.cleartimeout(wait);
wait = null;
event.call('dblclick', d3.event);
} else {
wait = window.settimeout((function(e) {
return function() {
event.call('click', e);
wait = null;
};
})(d3.event), 300);
}
}
});
};
cc.on = function() {
var value = event.on.apply(event, arguments);
return value === event ? cc : value;
};
return cc;
}
var cc = clickcancel();
d3.select('#map').call(cc);
cc.on('click', function() {
d3.select('#map').text(d3.select('#map').text() + 'click, ');
});
cc.on('dblclick', function() {
d3.select('#map').text(d3.select('#map').text() + 'dblclick, ');
});
#map {
width: 960px;
height: 500px;
background: cyan;
}
<script src="https://d3js.org/d3.v4.min.js"></script>
<div id='map'></div>
this is simply the source from the original rebind method.
Source: stackoverflow.com
Related Query
- Distinguishing click and double-click in D3 Version 4
- Both single and double click on a node in d3 force directed graph
- how to distinguish between single mouse click and double click on same node element in d3 js
- d3 zoom with button and double click but don't zoom with with scroll wheel
- Double click event not working on D3 version 6.1
- How to disable double click zoom for d3.behavior.zoom?
- How can I make double click event on node in d3.js?
- D3 Differentiate between click and drag for an element which has a drag behavior
- d3 zoom and pan upgrade to version 4
- Is there a tap and double tap event in d3.js force directed graph
- Can it is possible to use click event in tag cloud of D3 and If yes how?
- D3 update dataset on click and redraw the bar chart
- dagre-d3 how to click node and run an event after that
- d3.js click and apply zoom and pan to distribute points located inside a targeted division to the triggered subdivisions
- D3 click coordinates after pan and zoom
- d3.js : Differentiate between drag/start/end and click event
- How to use mouse click and drag to zoom in D3
- Initialize element and start dragging with just one click
- D3 Tree node double click highlights text
- Change the color of nodes on double click in D3
- dc.js simulate click on chart and trigger filter on
- d3 world map with country click and zoom almost working not quite
- Getting the lat and long of a click event
- Defining and calling a function instead of in-line function for click event
- D3.js Zoom and Pan to element on Click
- D3.js version 6: Loading a TSV and changing Variable types
- How to attach nodes and links to simulation force in d3js version 4?
- D3 map, click and get id from json
- Delete and add nodes with click on a node in d3.js
- collapsible trees in typescript and d3 version v3
More Query from same tag
- How to fix d3 parsing error when using function and return value to set "d"?
- Place text on the radii extending from the center of a circle D3
- How to place legends for stacked bar chart underneath in d3.js
- D3.js- How to format tick values as quarters instead of months
- R varied length vector or list in variable
- R / d3heatmap / shiny - is there a way to embed images in d3 tooltip?
- Multiple Area Charts with D3.js
- Update D3 text width by adding new width
- Line Bar Chart in D3 js
- D3.js: Get an array of the data attached to a selection?
- Only select subset in d3
- How can I keep a d3 mouseover open while my mouse is over the tooltip?
- Adding text tip to bar chart d3
- Zoom out D3 Force-Directed Graph without using mouse wheel
- How to center a svg in a div container
- How are d3.map() values reset back to default?
- NVD3 JavaScript charting - lineChart with duplicate right hand y-axis using 1 or more series
- d3 - How do I find the correct projection for a country?
- bars not showing in bar chart
- How to add controls and buttons to map?
- How can I get the natural width and height of an svg image element?
- Finding time ranges which intersect with given time range
- Average in Crossfilter and DC.js
- Capturing the mouseover event of a shape blocked by another transparent shape
- How to update subelements in d3?
- can an element event be triggered that is behind an other element
- D3 how to make dynamic sequential transitions work using transform/translate and offset coordinates?
- Change hover over of d3.js sunburst chart so that name of segment is appended rather than %
- d3.js static graph scrolling
- Swift Node Tree to complex Json