Skip to content

Commit b868959

Browse files
committed
move clearSelect to cartesian/select.js
... so that select.js can use it w/o having to require dragbox.js which causes a circular dep.
1 parent 978a70e commit b868959

File tree

6 files changed

+48
-48
lines changed

6 files changed

+48
-48
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ var Plots = require('../plots');
2828

2929
var doTicks = require('./axes').doTicks;
3030
var getFromId = require('./axis_ids').getFromId;
31-
var prepSelect = require('./select');
31+
var prepSelect = require('./select').prepSelect;
32+
var clearSelect = require('./select').clearSelect;
3233
var scaleZoom = require('./scale_zoom');
3334

3435
var constants = require('./constants');
@@ -974,13 +975,6 @@ function makeCorners(zoomlayer, xs, ys) {
974975
.attr('d', 'M0,0Z');
975976
}
976977

977-
function clearSelect(zoomlayer) {
978-
// until we get around to persistent selections, remove the outline
979-
// here. The selection itself will be removed when the plot redraws
980-
// at the end.
981-
zoomlayer.selectAll('.select-outline').remove();
982-
}
983-
984978
function updateZoombox(zb, corners, box, path0, dimmed, lum) {
985979
zb.attr('d',
986980
path0 + 'M' + (box.l) + ',' + (box.t) + 'v' + (box.h) +
@@ -1156,7 +1150,6 @@ module.exports = {
11561150
xyCorners: xyCorners,
11571151
transitionZoombox: transitionZoombox,
11581152
removeZoombox: removeZoombox,
1159-
clearSelect: clearSelect,
11601153
showDoubleClickNotifier: showDoubleClickNotifier,
11611154

11621155
attachWheelEventHandler: attachWheelEventHandler

src/plots/cartesian/select.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,28 @@ var multipolygonTester = polygon.multitester;
3030

3131
function getAxId(ax) { return ax._id; }
3232

33-
module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
34-
var gd = dragOptions.gd,
35-
fullLayout = gd._fullLayout,
36-
zoomLayer = fullLayout._zoomlayer,
37-
dragBBox = dragOptions.element.getBoundingClientRect(),
38-
plotinfo = dragOptions.plotinfo,
39-
xs = plotinfo.xaxis._offset,
40-
ys = plotinfo.yaxis._offset,
41-
x0 = startX - dragBBox.left,
42-
y0 = startY - dragBBox.top,
43-
x1 = x0,
44-
y1 = y0,
45-
path0 = 'M' + x0 + ',' + y0,
46-
pw = dragOptions.xaxes[0]._length,
47-
ph = dragOptions.yaxes[0]._length,
48-
xAxisIds = dragOptions.xaxes.map(getAxId),
49-
yAxisIds = dragOptions.yaxes.map(getAxId),
50-
allAxes = dragOptions.xaxes.concat(dragOptions.yaxes),
51-
filterPoly, testPoly, mergedPolygons, currentPolygon,
52-
subtract = e.altKey,
53-
i, cd, trace, searchInfo, eventData;
54-
33+
function prepSelect(e, startX, startY, dragOptions, mode) {
34+
var gd = dragOptions.gd;
35+
var fullLayout = gd._fullLayout;
36+
var zoomLayer = fullLayout._zoomlayer;
37+
var dragBBox = dragOptions.element.getBoundingClientRect();
38+
var plotinfo = dragOptions.plotinfo;
39+
var xs = plotinfo.xaxis._offset;
40+
var ys = plotinfo.yaxis._offset;
41+
var x0 = startX - dragBBox.left;
42+
var y0 = startY - dragBBox.top;
43+
var x1 = x0;
44+
var y1 = y0;
45+
var path0 = 'M' + x0 + ',' + y0;
46+
var pw = dragOptions.xaxes[0]._length;
47+
var ph = dragOptions.yaxes[0]._length;
48+
var xAxisIds = dragOptions.xaxes.map(getAxId);
49+
var yAxisIds = dragOptions.yaxes.map(getAxId);
50+
var allAxes = dragOptions.xaxes.concat(dragOptions.yaxes);
51+
var subtract = e.altKey;
52+
53+
var filterPoly, testPoly, mergedPolygons, currentPolygon;
54+
var i, cd, trace, searchInfo, eventData;
5555

5656
// take over selection polygons from prev mode, if any
5757
if((e.shiftKey || e.altKey) && (plotinfo.selection && plotinfo.selection.polygons) && !dragOptions.polygons) {
@@ -331,7 +331,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
331331
}
332332
});
333333
};
334-
};
334+
}
335335

336336
function updateSelectedState(gd, searchTraces, eventData) {
337337
var i, j, searchInfo, trace;
@@ -451,3 +451,15 @@ function fillSelectionItem(selection, searchInfo) {
451451

452452
return selection;
453453
}
454+
455+
function clearSelect(zoomlayer) {
456+
// until we get around to persistent selections, remove the outline
457+
// here. The selection itself will be removed when the plot redraws
458+
// at the end.
459+
zoomlayer.selectAll('.select-outline').remove();
460+
}
461+
462+
module.exports = {
463+
prepSelect: prepSelect,
464+
clearSelect: clearSelect
465+
};

src/plots/geo/geo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Fx = require('../../components/fx');
2020
var Plots = require('../plots');
2121
var Axes = require('../cartesian/axes');
2222
var dragElement = require('../../components/dragelement');
23-
var prepSelect = require('../cartesian/select');
23+
var prepSelect = require('../cartesian/select').prepSelect;
2424

2525
var createGeoZoom = require('./zoom');
2626
var constants = require('./constants');

src/plots/mapbox/mapbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var mapboxgl = require('mapbox-gl');
1414
var Fx = require('../../components/fx');
1515
var Lib = require('../../lib');
1616
var dragElement = require('../../components/dragelement');
17-
var prepSelect = require('../cartesian/select');
17+
var prepSelect = require('../cartesian/select').prepSelect;
1818
var constants = require('./constants');
1919
var layoutAttributes = require('./layout_attributes');
2020
var createMapboxLayer = require('./layers');

src/plots/polar/polar.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var dragElement = require('../../components/dragelement');
2222
var dragBox = require('../cartesian/dragbox');
2323
var Fx = require('../../components/fx');
2424
var Titles = require('../../components/titles');
25-
var prepSelect = require('../cartesian/select');
25+
var prepSelect = require('../cartesian/select').prepSelect;
26+
var clearSelect = require('../cartesian/select').clearSelect;
2627
var setCursor = require('../../lib/setcursor');
2728

2829
var MID_SHIFT = require('../../constants/alignment').MID_SHIFT;
@@ -634,7 +635,7 @@ proto.updateMainDrag = function(fullLayout, polarLayout) {
634635
zb = dragBox.makeZoombox(zoomlayer, lum, cx, cy, path0);
635636
zb.attr('fill-rule', 'evenodd');
636637
corners = dragBox.makeCorners(zoomlayer, cx, cy);
637-
dragBox.clearSelect(zoomlayer);
638+
clearSelect(zoomlayer);
638639
}
639640

640641
function zoomMove(dx, dy) {
@@ -868,7 +869,7 @@ proto.updateRadialDrag = function(fullLayout, polarLayout) {
868869
dragOpts.moveFn = moveFn;
869870
dragOpts.doneFn = doneFn;
870871

871-
dragBox.clearSelect(fullLayout._zoomlayer);
872+
clearSelect(fullLayout._zoomlayer);
872873
};
873874

874875
dragOpts.clampFn = function(dx, dy) {
@@ -1000,7 +1001,7 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
10001001
dragOpts.moveFn = moveFn;
10011002
dragOpts.doneFn = doneFn;
10021003

1003-
dragBox.clearSelect(fullLayout._zoomlayer);
1004+
clearSelect(fullLayout._zoomlayer);
10041005
};
10051006

10061007
dragElement.init(dragOpts);

src/plots/ternary/ternary.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ var Axes = require('../cartesian/axes');
2424
var dragElement = require('../../components/dragelement');
2525
var Fx = require('../../components/fx');
2626
var Titles = require('../../components/titles');
27-
var prepSelect = require('../cartesian/select');
27+
var prepSelect = require('../cartesian/select').prepSelect;
28+
var clearSelect = require('../cartesian/select').clearSelect;
2829
var constants = require('../cartesian/constants');
2930

3031
function Ternary(options, fullLayout) {
@@ -478,7 +479,7 @@ proto.initInteractions = function() {
478479
dragOptions.moveFn = plotDrag;
479480
dragOptions.doneFn = dragDone;
480481
panPrep();
481-
clearSelect();
482+
clearSelect(zoomContainer);
482483
}
483484
else if(dragModeNow === 'select' || dragModeNow === 'lasso') {
484485
prepSelect(e, startX, startY, dragOptions, dragModeNow);
@@ -536,7 +537,7 @@ proto.initInteractions = function() {
536537
})
537538
.attr('d', 'M0,0Z');
538539

539-
clearSelect();
540+
clearSelect(zoomContainer);
540541
}
541542

542543
function getAFrac(x, y) { return 1 - (y / _this.h); }
@@ -680,13 +681,6 @@ proto.initInteractions = function() {
680681
Registry.call('relayout', gd, attrs);
681682
}
682683

683-
function clearSelect() {
684-
// until we get around to persistent selections, remove the outline
685-
// here. The selection itself will be removed when the plot redraws
686-
// at the end.
687-
zoomContainer.selectAll('.select-outline').remove();
688-
}
689-
690684
// finally, set up hover and click
691685
// these event handlers must already be set before dragElement.init
692686
// so it can stash them and override them.

0 commit comments

Comments
 (0)