Skip to content

Commit 98541b0

Browse files
committed
sankey: create a single dragger per trace that gets restyle, improve test
1 parent aa17f1b commit 98541b0

File tree

2 files changed

+70
-49
lines changed

2 files changed

+70
-49
lines changed

src/traces/sankey/render.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -838,19 +838,20 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
838838

839839
sankey.each(function(d, i) {
840840
gd._fullData[i]._sankey = d;
841-
// Draw dragbox
842-
Lib.ensureSingle(gd._fullLayout._draggers, 'rect', 'bgsankey-' + d.guid, function(el) {
843-
el
844-
.style('pointer-events', 'all')
845-
.attr('width', d.width)
846-
.attr('height', d.height)
847-
.attr('x', d.translateX)
848-
.attr('y', d.translateY)
849-
.classed('bgsankey', true)
850-
.style({fill: 'transparent', 'stroke-width': 0});
851-
841+
// Create dragbox if missing
842+
Lib.ensureSingle(gd._fullLayout._draggers, 'rect', 'bgsankey-' + d.trace.uid, function(el) {
852843
gd._fullData[i]._bgRect = el;
853844
});
845+
846+
// Style dragbox
847+
gd._fullData[i]._bgRect
848+
.style('pointer-events', 'all')
849+
.attr('width', d.width)
850+
.attr('height', d.height)
851+
.attr('x', d.translateX)
852+
.attr('y', d.translateY)
853+
.classed('bgsankey', true)
854+
.style({fill: 'transparent', 'stroke-width': 0});
854855
});
855856

856857
sankey.transition()
@@ -942,7 +943,8 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
942943
.call(attachPointerEvents, sankey, callbacks.nodeEvents)
943944
.call(attachDragHandler, sankeyLink, callbacks, gd); // has to be here as it binds sankeyLink
944945

945-
sankeyNode.transition()
946+
sankeyNode
947+
.transition()
946948
.ease(c.ease).duration(c.duration)
947949
.call(updateNodePositions)
948950
.style('opacity', function(n) { return n.partOfGroup ? 0 : 1;});

test/jasmine/tests/select_test.js

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var mouseEvent = require('../assets/mouse_event');
1313
var touchEvent = require('../assets/touch_event');
1414

1515
var LONG_TIMEOUT_INTERVAL = 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL;
16+
var delay = require('../assets/delay');
17+
var sankeyConstants = require('@src/traces/sankey/constants');
1618

1719
function drag(path, options) {
1820
var len = path.length;
@@ -2667,45 +2669,62 @@ describe('Test select box and lasso per trace:', function() {
26672669
.then(done);
26682670
});
26692671

2670-
it('@flaky should work on sankey traces', function(done) {
2671-
var fig = Lib.extendDeep({}, require('@mocks/sankey_circular.json'));
2672-
fig.layout.dragmode = 'select';
2673-
var dblClickPos = [250, 400];
2674-
var opts = {};
2672+
describe('should work on sankey traces', function() {
2673+
var waitingTime = sankeyConstants.duration * 2;
26752674

2676-
Plotly.plot(gd, fig)
2677-
.then(function() {
2678-
// No groups initially
2679-
expect(gd._fullData[0].node.groups).toEqual([]);
2675+
it('@flaky select', function(done) {
2676+
var fig = Lib.extendDeep({}, require('@mocks/sankey_circular.json'));
2677+
fig.layout.dragmode = 'select';
2678+
var dblClickPos = [250, 400];
26802679

2681-
opts.element = document.elementFromPoint(400, 400);
2682-
})
2683-
.then(function() {
2684-
// Grouping the two nodes on the top right
2685-
return _run(
2686-
[[640, 130], [400, 450]],
2687-
function() {
2688-
expect(gd._fullData[0].node.groups).toEqual([[2, 3]]);
2689-
},
2690-
dblClickPos, BOXEVENTS, 'for top right nodes #2 and #3'
2691-
);
2692-
})
2693-
.then(function() {
2694-
// Grouping node #4 and the previous group
2695-
drag([[715, 400], [300, 110]], opts);
2696-
})
2697-
.then(function() {
2698-
expect(gd._fullData[0].node.groups).toEqual([[4, 3, 2]]);
2699-
})
2700-
.then(function() {
2701-
// Grouping node #0 and #1 on the left side
2702-
drag([[160, 110], [200, 590]], opts);
2703-
})
2704-
.then(function() {
2705-
expect(gd._fullData[0].node.groups).toEqual([[4, 3, 2], [0, 1]]);
2706-
})
2707-
.catch(failTest)
2708-
.then(done);
2680+
Plotly.plot(gd, fig)
2681+
.then(function() {
2682+
// No groups initially
2683+
expect(gd._fullData[0].node.groups).toEqual([]);
2684+
})
2685+
.then(function() {
2686+
// Grouping the two nodes on the top right
2687+
return _run(
2688+
[[640, 130], [400, 450]],
2689+
function() {
2690+
expect(gd._fullData[0].node.groups).toEqual([[2, 3]], 'failed to group #2 + #3');
2691+
},
2692+
dblClickPos, BOXEVENTS, 'for top right nodes #2 and #3'
2693+
);
2694+
})
2695+
.then(delay(waitingTime))
2696+
.then(function() {
2697+
// Grouping node #4 and the previous group
2698+
drag([[715, 400], [300, 110]]);
2699+
})
2700+
.then(delay(waitingTime))
2701+
.then(function() {
2702+
expect(gd._fullData[0].node.groups).toEqual([[4, 3, 2]], 'failed to group #4 + existing group of #2 and #3');
2703+
})
2704+
.catch(failTest)
2705+
.then(done);
2706+
});
2707+
2708+
it('@flaky should not work when dragmode is undefined', function(done) {
2709+
var fig = Lib.extendDeep({}, require('@mocks/sankey_circular.json'));
2710+
fig.layout.dragmode = undefined;
2711+
2712+
Plotly.plot(gd, fig)
2713+
.then(function() {
2714+
// No groups initially
2715+
expect(gd._fullData[0].node.groups).toEqual([]);
2716+
})
2717+
.then(function() {
2718+
// Grouping the two nodes on the top right
2719+
drag([[640, 130], [400, 450]]);
2720+
})
2721+
.then(delay(waitingTime))
2722+
.then(function() {
2723+
expect(gd._fullData[0].node.groups).toEqual([]);
2724+
})
2725+
.catch(failTest)
2726+
.then(done);
2727+
});
27092728
});
27102729
});
27112730

0 commit comments

Comments
 (0)