Skip to content

Commit 1a89a1e

Browse files
committed
sankey: reset node.(x|y) when grouping, test drag for every arrangements
1 parent 3cba316 commit 1a89a1e

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/traces/sankey/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ var attrs = module.exports = overrideAll({
9191
},
9292
groups: {
9393
valType: 'info_array',
94+
impliedEdits: {'x': [], 'y': []},
9495
dimensions: 2,
9596
freeLength: true,
9697
dflt: [],

src/traces/sankey/render.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ function startForce(sankeyNode, sankeyLink, d, forceKey, gd) {
641641
window.requestAnimationFrame(faster);
642642
} else {
643643
// Make sure the final x position is equal to its original value
644-
// necessary because the force simulation will have numerical error
644+
// because the force simulation will have numerical error
645645
var x = d.node.originalX;
646646
d.node.x0 = x - d.visibleWidth / 2;
647647
d.node.x1 = x + d.visibleWidth / 2;
@@ -744,6 +744,9 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
744744
firstRender = true;
745745
});
746746

747+
// To prevent animation on dragging
748+
var dragcover = gd.querySelector('.dragcover');
749+
747750
var styledData = calcData
748751
.filter(function(d) {return unwrap(d).trace.visible;})
749752
.map(sankeyModel.bind(null, layout));
@@ -808,7 +811,7 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
808811
.attr('d', linkPath());
809812

810813
sankeyLink
811-
.style('opacity', function() { return (gd._context.staticPlot || firstRender) ? 1 : 0;})
814+
.style('opacity', function() { return (gd._context.staticPlot || firstRender || dragcover) ? 1 : 0;})
812815
.transition()
813816
.ease(c.ease).duration(c.duration)
814817
.style('opacity', 1);

test/jasmine/assets/drag.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var isNumeric = require('fast-isnumeric');
22
var mouseEvent = require('./mouse_event');
33
var getNodeCoords = require('./get_node_coords');
4+
var delay = require('./delay');
45

56
function makeFns(node, dx, dy, opts) {
67
opts = opts || {};
@@ -49,7 +50,8 @@ function makeFns(node, dx, dy, opts) {
4950
* optionally specify an edge ('n', 'se', 'w' etc)
5051
* to grab it by an edge or corner (otherwise the middle is used)
5152
*/
52-
function drag(node, dx, dy, edge, x0, y0, nsteps, noCover) {
53+
function drag(node, dx, dy, edge, x0, y0, nsteps, noCover, timeDelay) {
54+
if(!timeDelay) timeDelay = 0;
5355
var fns = makeFns(node, dx, dy, {
5456
edge: edge,
5557
x0: x0,
@@ -58,7 +60,7 @@ function drag(node, dx, dy, edge, x0, y0, nsteps, noCover) {
5860
noCover: noCover
5961
});
6062

61-
return fns.start().then(fns.end);
63+
return fns.start().then(delay(timeDelay)).then(fns.end);
6264
}
6365

6466
function waitForDragCover() {

test/jasmine/tests/sankey_test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ describe('sankey tests', function() {
10121012
});
10131013

10141014
describe('Test drag interactions', function() {
1015-
['freeform', 'perpendicular'].forEach(function(arrangement) {
1015+
['freeform', 'perpendicular', 'snap'].forEach(function(arrangement) {
10161016
describe('for arrangement ' + arrangement + ':', function() {
10171017
var gd;
10181018
var mockCopy;
@@ -1037,9 +1037,10 @@ describe('sankey tests', function() {
10371037
return Promise.resolve()
10381038
.then(function() {
10391039
nodes = document.getElementsByClassName('sankey-node');
1040-
node = nodes.item(nodeId); // Selecting node with label 'Solid'
1040+
node = nodes.item(nodeId);
10411041
position = getNodeCoords(node);
1042-
return drag(node, move[0], move[1]);
1042+
var timeDelay = (arrangement === 'snap') ? 1000 : 0; // Wait for force simulation to finish
1043+
return drag(node, move[0], move[1], false, false, false, 10, false, timeDelay);
10431044
})
10441045
.then(function() {
10451046
nodes = document.getElementsByClassName('sankey-node');
@@ -1072,7 +1073,7 @@ describe('sankey tests', function() {
10721073
.then(done);
10731074
});
10741075

1075-
it('should persist the position of evry nodes after drag in attributes nodes.(x|y)', function(done) {
1076+
it('should persist the position of every nodes after drag in attributes nodes.(x|y)', function(done) {
10761077
mockCopy.data[0].arrangement = arrangement;
10771078
var move = [50, 50];
10781079
var nodes;

0 commit comments

Comments
 (0)