Skip to content

Commit 4bbbe5c

Browse files
committed
fix select/lasso on ternary subplots
- broken since #448 - 🔒 down with test
1 parent e3a2c84 commit 4bbbe5c

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

src/plots/ternary/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
6969
oldTernary.clipDef.remove();
7070
}
7171
}
72+
73+
if(oldFullLayout._zoomlayer) {
74+
oldFullLayout._zoomlayer.selectAll('.select-outline').remove();
75+
}
7276
};

src/plots/ternary/ternary.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ proto.makeFramework = function() {
122122

123123
_this.plotContainer.selectAll('.backplot,.frontplot,.grids')
124124
.call(Drawing.setClipUrl, clipId);
125-
126-
if(!_this.graphDiv._context.staticPlot) {
127-
_this.initInteractions();
128-
}
129125
};
130126

131127
var w_over_h = Math.sqrt(4 / 3);
@@ -302,6 +298,10 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
302298
'M' + (x0 + w / 2) + ',' + y0 + 'l' + (w / 2) + ',' + h : 'M0,0')
303299
.call(Color.stroke, caxis.linecolor || '#000')
304300
.style('stroke-width', (caxis.linewidth || 0) + 'px');
301+
302+
if(!_this.graphDiv._context.staticPlot) {
303+
_this.initInteractions();
304+
}
305305
};
306306

307307
proto.drawAxes = function(doTitles) {
@@ -387,7 +387,10 @@ proto.initInteractions = function() {
387387
var dragOptions = {
388388
element: dragger,
389389
gd: gd,
390-
plotinfo: {plot: zoomContainer},
390+
plotinfo: {
391+
xaxis: _this.xaxis,
392+
yaxis: _this.yaxis
393+
},
391394
doubleclick: doubleClick,
392395
subplot: _this.id,
393396
prepFn: function(e, startX, startY) {

test/jasmine/tests/select_test.js

+52
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var doubleClick = require('../assets/double_click');
66

77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
var fail = require('../assets/fail_test');
910
var mouseEvent = require('../assets/mouse_event');
1011
var customMatchers = require('../assets/custom_matchers');
1112

@@ -368,4 +369,55 @@ describe('select box and lasso', function() {
368369
})
369370
.then(done);
370371
});
372+
373+
it('should work on scatterternary traces', function(done) {
374+
var fig = Lib.extendDeep({}, require('@mocks/ternary_simple'));
375+
var gd = createGraphDiv();
376+
var pts = [];
377+
378+
fig.layout.width = 800;
379+
fig.layout.dragmode = 'select';
380+
381+
function assertPoints(expected) {
382+
expect(pts.length).toBe(expected.length, 'selected points length');
383+
384+
pts.forEach(function(p, i) {
385+
var e = expected[i];
386+
expect(p.a).toBe(e.a, 'selected pt a val');
387+
expect(p.b).toBe(e.b, 'selected pt b val');
388+
expect(p.c).toBe(e.c, 'selected pt c val');
389+
});
390+
pts = [];
391+
}
392+
393+
Plotly.plot(gd, fig).then(function() {
394+
gd.on('plotly_selected', function(data) {
395+
pts = data.points;
396+
});
397+
398+
assertSelectionNodes(0, 0);
399+
drag([[400, 200], [445, 235]]);
400+
assertSelectionNodes(0, 2);
401+
assertPoints([{ a: 0.5, b: 0.25, c: 0.25 }]);
402+
403+
return Plotly.relayout(gd, 'dragmode', 'lasso');
404+
})
405+
.then(function() {
406+
assertSelectionNodes(0, 0);
407+
drag([[400, 200], [445, 200], [445, 235], [400, 235], [400, 200]]);
408+
assertSelectionNodes(0, 2);
409+
assertPoints([{ a: 0.5, b: 0.25, c: 0.25 }]);
410+
411+
// should work after a relayout too
412+
return Plotly.relayout(gd, 'width', 400);
413+
})
414+
.then(function() {
415+
assertSelectionNodes(0, 0);
416+
drag([[200, 200], [230, 200], [230, 230], [200, 230], [200, 200]]);
417+
assertSelectionNodes(0, 2);
418+
assertPoints([{ a: 0.5, b: 0.25, c: 0.25 }]);
419+
})
420+
.catch(fail)
421+
.then(done);
422+
});
371423
});

0 commit comments

Comments
 (0)