Skip to content

Fix mapbox shift select regression #6258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions src/components/selections/select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var polybool = require('polybooljs');
var pointInPolygon = require('point-in-polygon/nested');
var pointInPolygon = require('point-in-polygon/nested'); // could we use contains lib/polygon instead?

var Registry = require('../../registry');
var dashStyle = require('../drawing').dashStyle;
Expand Down Expand Up @@ -32,7 +32,7 @@ var activateLastSelection = require('./draw').activateLastSelection;

var Lib = require('../../lib');
var ascending = Lib.sorterAsc;
var polygon = require('../../lib/polygon');
var libPolygon = require('../../lib/polygon');
var throttle = require('../../lib/throttle');
var getFromId = require('../../plots/cartesian/axis_ids').getFromId;
var clearGlCanvases = require('../../lib/clear_gl_canvases');
Expand All @@ -42,8 +42,8 @@ var redrawReglTraces = require('../../plot_api/subroutines').redrawReglTraces;
var constants = require('./constants');
var MINSELECT = constants.MINSELECT;

var filteredPolygon = polygon.filter;
var polygonTester = polygon.tester;
var filteredPolygon = libPolygon.filter;
var polygonTester = libPolygon.tester;

var helpers = require('./helpers');
var p2r = helpers.p2r;
Expand Down Expand Up @@ -350,7 +350,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {

fillRangeItems(eventData, poly);

dragOptions.gd.emit('plotly_selecting', eventData);
emitSelecting(gd, eventData);
}
);
}
Expand Down Expand Up @@ -381,7 +381,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {

clearSelectionsCache(dragOptions);

gd.emit('plotly_deselect', null);
emitDeselect(gd);

if(searchTraces.length) {
var clickedXaxis = searchTraces[0].xaxis;
Expand Down Expand Up @@ -419,7 +419,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
// but in case anyone depends on it we don't want to break it now.
// Note that click-to-select introduced pre v3 also emitts proper
// event data when clickmode is having 'select' in its flag list.
gd.emit('plotly_selected', undefined);
emitSelected(gd, undefined);
}
}

Expand Down Expand Up @@ -452,7 +452,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
}

eventData.selections = gd.layout.selections;
dragOptions.gd.emit('plotly_selected', eventData);
emitSelected(gd, eventData);
}).catch(Lib.error);
};
}
Expand Down Expand Up @@ -491,7 +491,7 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
clearSelectionsCache(dragOptions);

if(sendEvents) {
gd.emit('plotly_deselect', null);
emitDeselect(gd);
}
} else {
subtract = evt.shiftKey &&
Expand Down Expand Up @@ -531,7 +531,7 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli

if(sendEvents) {
eventData.selections = gd.layout.selections;
gd.emit('plotly_selected', eventData);
emitSelected(gd, eventData);
}
}
}
Expand Down Expand Up @@ -596,7 +596,7 @@ function multiTester(list) {
if(isPointSelectionDef(list[i])) {
testers.push(newPointNumTester(list[i]));
} else {
var tester = polygon.tester(list[i]);
var tester = polygonTester(list[i]);
tester.subtract = !!list[i].subtract;
testers.push(tester);

Expand Down Expand Up @@ -1196,7 +1196,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
}

eventData.selections = gd.layout.selections;
gd.emit('plotly_selected', eventData);
emitSelected(gd, eventData);
}

fullLayout._reselect = false;
Expand All @@ -1217,7 +1217,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
if(sendEvents) {
if(eventData.points.length) {
eventData.selections = gd.layout.selections;
gd.emit('plotly_selected', eventData);
emitSelected(gd, eventData);
} else {
gd.emit('plotly_deselect', null);
}
Expand Down Expand Up @@ -1506,6 +1506,17 @@ function getFillRangeItems(dragOptions) {
);
}

function emitSelecting(gd, eventData) {
gd.emit('plotly_selecting', eventData);
}

function emitSelected(gd, eventData) {
gd.emit('plotly_selected', eventData);
}

function emitDeselect(gd) {
gd.emit('plotly_deselect', null);
}

module.exports = {
reselect: reselect,
Expand Down
14 changes: 5 additions & 9 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,22 +429,18 @@ proto.updateFx = function(fullLayout, geoLayout) {
]);
}

var fillRangeItems;

if(dragMode === 'select') {
fillRangeItems = function(eventData, poly) {
var fillRangeItems = function(eventData, poly) {
if(poly.isRect) {
var ranges = eventData.range = {};
ranges[_this.id] = [
invert([poly.xmin, poly.ymin]),
invert([poly.xmax, poly.ymax])
];
};
} else if(dragMode === 'lasso') {
fillRangeItems = function(eventData, poly) {
} else {
var dataPts = eventData.lassoPoints = {};
dataPts[_this.id] = poly.map(invert);
};
}
}
};

// Note: dragOptions is needed to be declared for all dragmodes because
// it's the object that holds persistent selection state.
Expand Down
15 changes: 6 additions & 9 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var dragElement = require('../../components/dragelement');

var Fx = require('../../components/fx');
var dragHelpers = require('../../components/dragelement/helpers');
var rectMode = dragHelpers.rectMode;
var drawMode = dragHelpers.drawMode;
var selectMode = dragHelpers.selectMode;

Expand Down Expand Up @@ -550,20 +549,18 @@ proto.updateFx = function(fullLayout) {
var dragMode = fullLayout.dragmode;
var fillRangeItems;

if(rectMode(dragMode)) {
fillRangeItems = function(eventData, poly) {
fillRangeItems = function(eventData, poly) {
if(poly.isRect) {
var ranges = eventData.range = {};
ranges[self.id] = [
invert([poly.xmin, poly.ymin]),
invert([poly.xmax, poly.ymax])
];
};
} else {
fillRangeItems = function(eventData, pts) {
} else {
var dataPts = eventData.lassoPoints = {};
dataPts[self.id] = pts.map(invert);
};
}
dataPts[self.id] = poly.map(invert);
}
};

// Note: dragOptions is needed to be declared for all dragmodes because
// it's the object that holds persistent selection state.
Expand Down