MCPcopy Create free account
hub / github.com/plotly/plotly.js / dragend

Function dragend

src/traces/parcoords/axisbrush.js:248–323  ·  view source on GitHub ↗
(lThis, d)

Source from the content-addressed store, hash-verified

246}
247
248function dragend(lThis, d) {
249 var brush = d.brush;
250 var filter = brush.filter;
251 var s = brush.svgBrush;
252
253 if(!s._dragging) { // i.e. click
254 // mock zero drag
255 mousemove(lThis, d);
256 drag(lThis, d);
257 // remember it is a click not a drag
258 d.brush.svgBrush.wasDragged = false;
259 }
260 s._dragging = false;
261
262 var e = d3.event;
263 e.sourceEvent.stopPropagation();
264 var grabbingBar = s.grabbingBar;
265 s.grabbingBar = false;
266 s.grabLocation = undefined;
267 d.parent.inBrushDrag = false;
268 clearCursor(); // instead of clearing, a nicer thing would be to set it according to current location
269 if(!s.wasDragged) { // a click+release on the same spot (ie. w/o dragging) means a bar or full reset
270 s.wasDragged = undefined; // logic-wise unneeded, just shows `wasDragged` has no longer a meaning
271 if(s.clickableOrdinalRange) {
272 if(brush.filterSpecified && d.multiselect) {
273 s.extent.push(s.clickableOrdinalRange);
274 } else {
275 s.extent = [s.clickableOrdinalRange];
276 brush.filterSpecified = true;
277 }
278 } else if(grabbingBar) {
279 s.extent = s.stayingIntervals;
280 if(s.extent.length === 0) {
281 brushClear(brush);
282 }
283 } else {
284 brushClear(brush);
285 }
286 s.brushCallback(d);
287 renderHighlight(lThis.parentNode);
288 s.brushEndCallback(brush.filterSpecified ? filter.getConsolidated() : []);
289 return; // no need to fuse intervals or snap to ordinals, so we can bail early
290 }
291
292 var mergeIntervals = function() {
293 // Key piece of logic: once the button is released, possibly overlapping intervals will be fused:
294 // Here it's done immediately on click release while on ordinal snap transition it's done at the end
295 filter.set(filter.getConsolidated());
296 };
297
298 if(d.ordinal) {
299 var a = d.unitTickvals;
300 if(a[a.length - 1] < a[0]) a.reverse();
301 s.newExtent = [
302 ordinalScaleSnap(0, a, s.newExtent[0], s.stayingIntervals),
303 ordinalScaleSnap(1, a, s.newExtent[1], s.stayingIntervals)
304 ];
305 var hasNewExtent = s.newExtent[1] > s.newExtent[0];

Callers 1

attachDragBehaviorFunction · 0.85

Calls 7

mousemoveFunction · 0.85
clearCursorFunction · 0.85
brushClearFunction · 0.85
renderHighlightFunction · 0.85
ordinalScaleSnapFunction · 0.85
mergeIntervalsFunction · 0.85
dragFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…