Skip to content

Commit 22cf4ba

Browse files
committed
expose a few things out of cartesian dragbox for ♻️
1 parent 04a886b commit 22cf4ba

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

src/plots/cartesian/dragbox.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var SHOWZOOMOUTTIP = true;
4545
// 's' - bottom only
4646
// 'ns' - top and bottom together, difference unchanged
4747
// ew - same for horizontal axis
48-
module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
48+
function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
4949
// mouseDown stores ms of first mousedown event in the last
5050
// DBLCLICKDELAY ms on the drag bars
5151
// numClicks stores how many mousedowns have been seen
@@ -439,9 +439,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
439439

440440
// everything but the corners gets wheel zoom
441441
if(ns.length * ew.length !== 1) {
442-
// still seems to be some confusion about onwheel vs onmousewheel...
443-
if(dragger.onwheel !== undefined) dragger.onwheel = zoomWheel;
444-
else if(dragger.onmousewheel !== undefined) dragger.onmousewheel = zoomWheel;
442+
attachWheelEventHandler(dragger, zoomWheel);
445443
}
446444

447445
// plotDrag: move the plot in response to a drag
@@ -792,7 +790,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
792790
}
793791

794792
return dragger;
795-
};
793+
}
796794

797795
function makeDragger(plotinfo, dragClass, cursor, x, y, w, h) {
798796
var dragger3 = plotinfo.draglayer.selectAll('.' + dragClass).data([0]);
@@ -931,6 +929,10 @@ function updateZoombox(zb, corners, box, path0, dimmed, lum) {
931929
zb.attr('d',
932930
path0 + 'M' + (box.l) + ',' + (box.t) + 'v' + (box.h) +
933931
'h' + (box.w) + 'v-' + (box.h) + 'h-' + (box.w) + 'Z');
932+
transitionZoombox(zb, corners, dimmed, lum);
933+
}
934+
935+
function transitionZoombox(zb, corners, dimmed, lum) {
934936
if(!dimmed) {
935937
zb.transition()
936938
.style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' :
@@ -1035,3 +1037,25 @@ function calcLinks(constraintGroups, xIDs, yIDs) {
10351037
xy: isSubplotConstrained
10361038
};
10371039
}
1040+
1041+
// still seems to be some confusion about onwheel vs onmousewheel...
1042+
function attachWheelEventHandler(element, handler) {
1043+
if(element.onwheel !== undefined) element.onwheel = handler;
1044+
else if(element.onmousewheel !== undefined) element.onmousewheel = handler;
1045+
}
1046+
1047+
module.exports = {
1048+
makeDragBox: makeDragBox,
1049+
1050+
makeDragger: makeDragger,
1051+
makeZoombox: makeZoombox,
1052+
makeCorners: makeCorners,
1053+
1054+
updateZoombox: updateZoombox,
1055+
xyCorners: xyCorners,
1056+
transitionZoombox: transitionZoombox,
1057+
removeZoombox: removeZoombox,
1058+
clearSelect: clearSelect,
1059+
1060+
attachWheelEventHandler: attachWheelEventHandler
1061+
};

src/plots/cartesian/graph_interact.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var Fx = require('../../components/fx');
1515
var dragElement = require('../../components/dragelement');
1616

1717
var constants = require('./constants');
18-
var dragBox = require('./dragbox');
18+
var makeDragBox = require('./dragbox').makeDragBox;
1919

2020
module.exports = function initInteractions(gd) {
2121
var fullLayout = gd._fullLayout;
@@ -56,7 +56,7 @@ module.exports = function initInteractions(gd) {
5656
if(!plotinfo.mainplot) {
5757
// main dragger goes over the grids and data, so we use its
5858
// mousemove events for all data hover effects
59-
var maindrag = dragBox(gd, plotinfo, 0, 0,
59+
var maindrag = makeDragBox(gd, plotinfo, 0, 0,
6060
xa._length, ya._length, 'ns', 'ew');
6161

6262
maindrag.onmousemove = function(evt) {
@@ -100,13 +100,13 @@ module.exports = function initInteractions(gd) {
100100

101101
// corner draggers
102102
if(gd._context.showAxisDragHandles) {
103-
dragBox(gd, plotinfo, -DRAGGERSIZE, -DRAGGERSIZE,
103+
makeDragBox(gd, plotinfo, -DRAGGERSIZE, -DRAGGERSIZE,
104104
DRAGGERSIZE, DRAGGERSIZE, 'n', 'w');
105-
dragBox(gd, plotinfo, xa._length, -DRAGGERSIZE,
105+
makeDragBox(gd, plotinfo, xa._length, -DRAGGERSIZE,
106106
DRAGGERSIZE, DRAGGERSIZE, 'n', 'e');
107-
dragBox(gd, plotinfo, -DRAGGERSIZE, ya._length,
107+
makeDragBox(gd, plotinfo, -DRAGGERSIZE, ya._length,
108108
DRAGGERSIZE, DRAGGERSIZE, 's', 'w');
109-
dragBox(gd, plotinfo, xa._length, ya._length,
109+
makeDragBox(gd, plotinfo, xa._length, ya._length,
110110
DRAGGERSIZE, DRAGGERSIZE, 's', 'e');
111111
}
112112
}
@@ -115,21 +115,21 @@ module.exports = function initInteractions(gd) {
115115
// these drag each axis separately
116116
if(isNumeric(y0)) {
117117
if(xa.anchor === 'free') y0 -= fullLayout._size.h * (1 - ya.domain[1]);
118-
dragBox(gd, plotinfo, xa._length * 0.1, y0,
118+
makeDragBox(gd, plotinfo, xa._length * 0.1, y0,
119119
xa._length * 0.8, DRAGGERSIZE, '', 'ew');
120-
dragBox(gd, plotinfo, 0, y0,
120+
makeDragBox(gd, plotinfo, 0, y0,
121121
xa._length * 0.1, DRAGGERSIZE, '', 'w');
122-
dragBox(gd, plotinfo, xa._length * 0.9, y0,
122+
makeDragBox(gd, plotinfo, xa._length * 0.9, y0,
123123
xa._length * 0.1, DRAGGERSIZE, '', 'e');
124124
}
125125
// y axis draggers
126126
if(isNumeric(x0)) {
127127
if(ya.anchor === 'free') x0 -= fullLayout._size.w * xa.domain[0];
128-
dragBox(gd, plotinfo, x0, ya._length * 0.1,
128+
makeDragBox(gd, plotinfo, x0, ya._length * 0.1,
129129
DRAGGERSIZE, ya._length * 0.8, 'ns', '');
130-
dragBox(gd, plotinfo, x0, ya._length * 0.9,
130+
makeDragBox(gd, plotinfo, x0, ya._length * 0.9,
131131
DRAGGERSIZE, ya._length * 0.1, 's', '');
132-
dragBox(gd, plotinfo, x0, 0,
132+
makeDragBox(gd, plotinfo, x0, 0,
133133
DRAGGERSIZE, ya._length * 0.1, 'n', '');
134134
}
135135
}

0 commit comments

Comments
 (0)