8000 Fix scatterternary lasso/select drag modes by etpinard · Pull Request #1831 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Fix scatterternary lasso/select drag modes #1831

New issue

Have a question about this project? Sign up for a free GitHub account to open an is 8000 sue 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 5 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix select/lasso on ternary subplots
- broken since #448
- 🔒 down with test
  • Loading branch information
etpinard committed Jun 28, 2017
commit 4bbbe5cdc13ffc23b9214ba3621fa3924ff13cda
4 changes: 4 additions & 0 deletions src/plots/ternary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
oldTernary.clipDef.remove();
}
}

if(oldFullLayout._zoomlayer) {
oldFullLayout._zoomlayer.selectAll('.select-outline').remove();
}
};
13 changes: 8 additions & 5 deletions src/plots/ternary/ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ proto.makeFramework = function() {

_this.plotContainer.selectAll('.backplot,.frontplot,.grids')
.call(Drawing.setClipUrl, clipId);

if(!_this.graphDiv._context.staticPlot) {
_this.initInteractions();
}
};

var w_over_h = Math.sqrt(4 / 3);
Expand Down Expand Up @@ -302,6 +298,10 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
'M' + (x0 + w / 2) + ',' + y0 + 'l' + (w / 2) + ',' + h : 'M0,0')
.call(Color.stroke, caxis.linecolor || '#000')
.style('stroke-width', (caxis.linewidth || 0) + 'px');

if(!_this.graphDiv._context.staticPlot) {
_this.initInteractions();
}
};

proto.drawAxes = function(doTitles) {
Expand Down Expand Up @@ -387,7 +387,10 @@ proto.initInteractions = function() {
var dragOptions = {
element: dragger,
gd: gd,
plotinfo: {plot: zoomContainer},
plotinfo: {
xaxis: _this.xaxis,
yaxis: _this.yaxis
},
doubleclick: doubleClick,
subplot: _this.id,
prepFn: function(e, startX, startY) {
Expand Down
52 changes: 52 additions & 0 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var doubleClick = require('../assets/double_click');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var customMatchers = require('../assets/custom_matchers');

Expand Down Expand Up @@ -368,4 +369,55 @@ describe('select box and lasso', function() {
})
.then(done);
});

it('should work on scatterternary traces', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/ternary_simple'));
var gd = createGraphDiv();
var pts = [];

fig.layout.width = 800;
fig.layout.dragmode = 'select';

function assertPoints(expected) {
expect(pts.length).toBe(expected.length, 'selected points length');

pts.forEach(function(p, i) {
var e = expected[i];
expect(p.a).toBe(e.a, 'selected pt a val');
expect(p.b).toBe(e.b, 'selected pt b val');
expect(p.c).toBe(e.c, 'selected pt c val');
});
pts = [];
}

Plotly.plot(gd, fig).then(function() {
gd.on('plotly_selected', function(data) {
pts = data.points;
});

assertSelectionNodes(0, 0);
drag([[400, 200], [445, 235]]);
assertSelectionNodes(0, 2);
assertPoints([{ a: 0.5, b: 0.25, c: 0.25 }]);

return Plotly.relayout(gd, 'dragmode', 'lasso');
})
.then(function() {
assertSelectionNodes(0, 0);
drag([[400, 200], [445, 200], [445, 235], [400, 235], [400, 200]]);
assertSelectionNodes(0, 2);
assertPoints([{ a: 0.5, b: 0.25, c: 0.25 }]);

// should work after a relayout too
return Plotly.relayout(gd, 'width', 400);
})
.then(function() {
assertSelectionNodes(0, 0);
drag([[200, 200], [230, 200], [230, 230], [200, 230], [200, 200]]);
assertSelectionNodes(0, 2);
assertPoints([{ a: 0.5, b: 0.25, c: 0.25 }]);
})
.catch(fail)
.then(done);
});
});
0