Skip to content

Commit 05b0dca

Browse files
committed
Fix failing cases
1 parent b800e55 commit 05b0dca

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -942,11 +942,13 @@ function showSelect(zoomlayer, dragOptions) {
942942
paths.push(ppts.join('L') + 'L' + ppts[0]);
943943
}
944944

945-
outlines.enter()
946-
.append('path')
947-
.attr('class', function(d) { return 'select-outline select-outline-' + d; })
948-
.attr('transform', 'translate(' + xs + ', ' + ys + ')')
949-
.attr('d', 'M' + paths.join('M') + 'Z');
945+
if(paths.length) {
946+
outlines.enter()
947+
.append('path')
948+
.attr('class', function(d) { return 'select-outline select-outline-' + d; })
949+
.attr('transform', 'translate(' + xs + ', ' + ys + ')')
950+
.attr('d', 'M' + paths.join('M') + 'Z');
951+
}
950952
}
951953

952954
function updateZoombox(zb, corners, box, path0, dimmed, lum) {

src/plots/cartesian/select.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,16 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
117117
fillRangeItems = plotinfo.fillRangeItems;
118118
} else {
119119
if(mode === 'select') {
120-
fillRangeItems = function(eventData, currentPolygon) {
120+
fillRangeItems = function(eventData, poly) {
121121
var ranges = eventData.range = {};
122122

123123
for(i = 0; i < allAxes.length; i++) {
124124
var ax = allAxes[i];
125125
var axLetter = ax._id.charAt(0);
126-
var x = axLetter === 'x';
127126

128127
ranges[ax._id] = [
129-
ax.p2d(currentPolygon[0][x ? 0 : 1]),
130-
ax.p2d(currentPolygon[2][x ? 0 : 1])
128+
ax.p2d(poly[axLetter + 'min']),
129+
ax.p2d(poly[axLetter + 'max'])
131130
].sort(ascending);
132131
}
133132
};
@@ -154,6 +153,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
154153
if(dy < Math.min(dx * 0.6, MINSELECT)) {
155154
// horizontal motion: make a vertical box
156155
currentPolygon = [[x0, 0], [x0, ph], [x1, ph], [x1, 0]];
156+
currentPolygon.xmin = Math.min(x0, x1);
157+
currentPolygon.xmax = Math.max(x0, x1);
158+
currentPolygon.ymin = Math.min(0, ph);
159+
currentPolygon.ymax = Math.max(0, ph);
157160
// extras to guide users in keeping a straight selection
158161
corners.attr('d', 'M' + Math.min(x0, x1) + ',' + (y0 - MINSELECT) +
159162
'h-4v' + (2 * MINSELECT) + 'h4Z' +
@@ -164,6 +167,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
164167
else if(dx < Math.min(dy * 0.6, MINSELECT)) {
165168
// vertical motion: make a horizontal box
166169
currentPolygon = [[0, y0], [0, y1], [pw, y1], [pw, y0]];
170+
currentPolygon.xmin = Math.min(0, pw);
171+
currentPolygon.xmax = Math.max(0, pw);
172+
currentPolygon.ymin = Math.min(y0, y1);
173+
currentPolygon.ymax = Math.max(y0, y1);
167174
corners.attr('d', 'M' + (x0 - MINSELECT) + ',' + Math.min(y0, y1) +
168175
'v-4h' + (2 * MINSELECT) + 'v4Z' +
169176
'M' + (x0 - MINSELECT) + ',' + (Math.max(y0, y1) - 1) +
@@ -172,6 +179,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
172179
else {
173180
// diagonal motion
174181
currentPolygon = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]];
182+
currentPolygon.xmin = Math.min(x0, x1);
183+
currentPolygon.xmax = Math.max(x0, x1);
184+
currentPolygon.ymin = Math.min(y0, y1);
185+
currentPolygon.ymax = Math.max(y0, y1);
175186
corners.attr('d', 'M0,0Z');
176187
}
177188
}
@@ -181,7 +192,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
181192
}
182193

183194
// create outline & tester
184-
if(dragOptions.polygons.length) {
195+
if(dragOptions.polygons && dragOptions.polygons.length) {
185196
mergedPolygons = polybool(dragOptions.mergedPolygons, [currentPolygon], 'or');
186197
testPoly = multipolygonTester(dragOptions.polygons.concat([currentPolygon]));
187198
}
@@ -231,6 +242,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
231242

232243
dragOptions.doneFn = function(dragged, numclicks) {
233244
corners.remove();
245+
234246
throttle.done(throttleID).then(function() {
235247
throttle.clear(throttleID);
236248

@@ -248,11 +260,13 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
248260
dragOptions.gd.emit('plotly_selected', eventData);
249261
}
250262

251-
// save last polygons
252-
dragOptions.polygons.push(currentPolygon);
263+
if(currentPolygon && dragOptions.polygons) {
264+
// save last polygons
265+
dragOptions.polygons.push(currentPolygon);
253266

254-
// we have to keep reference to arrays, therefore just replace items
255-
dragOptions.mergedPolygons.splice.apply(dragOptions.mergedPolygons, [0, dragOptions.mergedPolygons.length].concat(mergedPolygons));
267+
// we have to keep reference to arrays, therefore just replace items
268+
dragOptions.mergedPolygons.splice.apply(dragOptions.mergedPolygons, [0, dragOptions.mergedPolygons.length].concat(mergedPolygons));
269+
}
256270
});
257271
};
258272
};

0 commit comments

Comments
 (0)