Skip to content

Commit fbce873

Browse files
committed
prelim stuff for geo selections
- make sure dragmode is set to 'pan' by default for geo plots - add select and lasso mode bar button to geo plots - add updateFx fast relayout pass - init dragElement instance *just for* lasso and select drag modes, note that 'pan' still uses d3's drag abstaction
1 parent 2d8348e commit fbce873

File tree

5 files changed

+93
-37
lines changed

5 files changed

+93
-37
lines changed

src/components/fx/layout_defaults.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
2929

3030
coerce('hovermode', hovermodeDflt);
3131

32-
// if only mapbox subplots is present on graph,
32+
// if only mapbox or geo subplots is present on graph,
3333
// reset 'zoom' dragmode to 'pan' until 'zoom' is implemented,
3434
// so that the correct modebar button is active
35-
if(layoutOut._has('mapbox') && layoutOut._basePlotModules.length === 1 &&
36-
layoutOut.dragmode === 'zoom') {
35+
var hasMapbox = layoutOut._has('mapbox');
36+
var hasGeo = layoutOut._has('geo');
37+
var len = layoutOut._basePlotModules.length;
38+
39+
if(layoutOut.dragmode === 'zoom' && (
40+
((hasMapbox || hasGeo) && len === 1) ||
41+
(hasMapbox && hasGeo && len === 2)
42+
)) {
3743
layoutOut.dragmode = 'pan';
3844
}
3945
};

src/components/modebar/manage.js

+17-23
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ module.exports = function manageModeBar(gd) {
7171

7272
// logic behind which buttons are displayed by default
7373
function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
74-
var fullLayout = gd._fullLayout,
75-
fullData = gd._fullData;
74+
var fullLayout = gd._fullLayout;
75+
var fullData = gd._fullData;
7676

77-
var hasCartesian = fullLayout._has('cartesian'),
78-
hasGL3D = fullLayout._has('gl3d'),
79-
hasGeo = fullLayout._has('geo'),
80-
hasPie = fullLayout._has('pie'),
81-
hasGL2D = fullLayout._has('gl2d'),
82-
hasTernary = fullLayout._has('ternary'),
83-
hasMapbox = fullLayout._has('mapbox');
77+
var hasCartesian = fullLayout._has('cartesian');
78+
var hasGL3D = fullLayout._has('gl3d');
79+
var hasGeo = fullLayout._has('geo');
80+
var hasPie = fullLayout._has('pie');
81+
var hasGL2D = fullLayout._has('gl2d');
82+
var hasTernary = fullLayout._has('ternary');
83+
var hasMapbox = fullLayout._has('mapbox');
8484

8585
var groups = [];
8686

@@ -112,18 +112,13 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
112112
addGroup(['hoverClosest3d']);
113113
}
114114

115-
if(hasGeo) {
116-
addGroup(['zoomInGeo', 'zoomOutGeo', 'resetGeo']);
117-
addGroup(['hoverClosestGeo']);
118-
}
119-
120115
var allAxesFixed = areAllAxesFixed(fullLayout),
121116
dragModeGroup = [];
122117

123118
if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {
124119
dragModeGroup = ['zoom2d', 'pan2d'];
125120
}
126-
if(hasMapbox) {
121+
if(hasMapbox || hasGeo) {
127122
dragModeGroup = ['pan2d'];
128123
}
129124
if(isSelectable(fullData)) {
@@ -138,18 +133,17 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
138133

139134
if(hasCartesian && hasPie) {
140135
addGroup(['toggleHover']);
141-
}
142-
else if(hasGL2D) {
136+
} else if(hasGL2D) {
143137
addGroup(['hoverClosestGl2d']);
144-
}
145-
else if(hasCartesian) {
138+
} else if(hasCartesian) {
146139
addGroup(['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']);
147-
}
148-
else if(hasPie) {
140+
} else if(hasPie) {
149141
addGroup(['hoverClosestPie']);
150-
}
151-
else if(hasMapbox) {
142+
} else if(hasMapbox) {
152143
addGroup(['resetViewMapbox', 'toggleHover']);
144+
} else if(hasGeo) {
145+
addGroup(['zoomInGeo', 'zoomOutGeo', 'resetGeo']);
146+
addGroup(['hoverClosestGeo']);
153147
}
154148

155149
return appendButtonsToGroups(groups, buttonsToAdd);

src/plot_api/subroutines.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ exports.doTicksRelayout = function(gd) {
490490

491491
exports.doModeBar = function(gd) {
492492
var fullLayout = gd._fullLayout;
493-
var subplotIds, subplotObj, i;
493+
var subplotIds, subplotLayout, subplotObj, i;
494494

495495
ModeBar.manage(gd);
496496
initInteractions(gd);
@@ -513,6 +513,13 @@ exports.doModeBar = function(gd) {
513513
subplotObj.updateFx(fullLayout);
514514
}
515515

516+
subplotIds = Plots.getSubplotIds(fullLayout, 'geo');
517+
for(i = 0; i < subplotIds.length; i++) {
518+
subplotLayout = fullLayout[subplotIds[i]];
519+
subplotObj = subplotLayout._subplot;
520+
subplotObj.updateFx(fullLayout, subplotLayout);
521+
}
522+
516523
return Plots.previousPromises(gd);
517524
};
518525

src/plots/cartesian/select.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,18 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
7979
if(!trace._module || !trace._module.selectPoints) continue;
8080

8181
if(dragOptions.subplot) {
82-
if(trace.subplot !== dragOptions.subplot) continue;
83-
84-
searchTraces.push({
85-
selectPoints: trace._module.selectPoints,
86-
cd: cd,
87-
xaxis: dragOptions.xaxes[0],
88-
yaxis: dragOptions.yaxes[0]
89-
});
90-
}
91-
else {
82+
if(
83+
trace.subplot === dragOptions.subplot ||
84+
trace.geo === dragOptions.subplot
85+
) {
86+
searchTraces.push({
87+
selectPoints: trace._module.selectPoints,
88+
cd: cd,
89+
xaxis: dragOptions.xaxes[0],
90+
yaxis: dragOptions.yaxes[0]
91+
});
92+
}
93+
} else {
9294
if(xAxisIds.indexOf(trace.xaxis) === -1) continue;
9395
if(yAxisIds.indexOf(trace.yaxis) === -1) continue;
9496

src/plots/geo/geo2.js

+47
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var Drawing = require('../../components/drawing');
1919
var Fx = require('../../components/fx');
2020
var Plots = require('../plots');
2121
var Axes = require('../cartesian/axes');
22+
var dragElement = require('../../components/dragelement');
23+
var prepSelect = require('../cartesian/select');
2224

2325
var createGeoZoom = require('./zoom');
2426
var constants = require('./constants');
@@ -351,6 +353,51 @@ proto.updateFx = function(fullLayout, geoLayout) {
351353
framework.call(createGeoZoom(_this, geoLayout));
352354
framework.on('dblclick.zoom', zoomReset);
353355
}
356+
else if(dragMode === 'select' || dragMode === 'lasso') {
357+
framework.on('.zoom', null);
358+
359+
var fillRangeItems;
360+
361+
if(dragMode === 'select') {
362+
fillRangeItems = function(eventData, poly) {
363+
var ranges = eventData.range = {};
364+
ranges[_this.id] = [
365+
invert([poly.xmin, poly.ymin]),
366+
invert([poly.xmax, poly.ymax])
367+
];
368+
};
369+
} else if(dragMode === 'lasso') {
370+
fillRangeItems = function(eventData, poly, pts) {
371+
var dataPts = eventData.lassoPoints = {};
372+
dataPts[_this.id] = pts.filtered.map(invert);
373+
};
374+
}
375+
376+
var dragOptions = {
377+
element: _this.bgRect.node(),
378+
gd: gd,
379+
plotinfo: {
380+
xaxis: _this.xaxis,
381+
yaxis: _this.yaxis,
382+
fillRangeItems: fillRangeItems
383+
},
384+
xaxes: [_this.xaxis],
385+
yaxes: [_this.yaxis],
386+
subplot: _this.id
387+
};
388+
389+
dragOptions.prepFn = function(e, startX, startY) {
390+
prepSelect(e, startX, startY, dragOptions, dragMode);
391+
};
392+
393+
dragOptions.doneFn = function(dragged, numClicks) {
394+
if(numClicks === 2) {
395+
fullLayout._zoomlayer.selectAll('.select-outline').remove();
396+
}
397+
};
398+
399+
dragElement.init(dragOptions);
400+
}
354401

355402
framework.on('mousemove', function() {
356403
var lonlat = _this.projection.invert(d3.mouse(this));

0 commit comments

Comments
 (0)