Skip to content

Commit 6175fb5

Browse files
committed
sankey: add warning if node is in multiple groups, change transition settings
1 parent 63d8190 commit 6175fb5

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/traces/sankey/calc.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ function convertToD3Sankey(trace) {
5151
for(j = 0; j < group.length; j++) {
5252
var nodeIndex = group[j];
5353
var groupIndex = nodeCount + i;
54-
groupLookup[nodeIndex] = groupIndex;
54+
if(groupLookup.hasOwnProperty(nodeIndex)) {
55+
Lib.warn('Node ' + nodeIndex + ' is already part of a group.');
56+
} else {
57+
groupLookup[nodeIndex] = groupIndex;
58+
}
5559
}
5660
}
5761

src/traces/sankey/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module.exports = {
1515
sankeyIterations: 50,
1616
forceIterations: 5,
1717
forceTicksPerFrame: 10,
18-
duration: 350,
19-
ease: 'quart-in-out',
18+
duration: 500,
19+
ease: 'linear',
2020
cn: {
2121
sankey: 'sankey',
2222
sankeyLinks: 'sankey-links',

test/image/mocks/sankey_groups.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"color": "white",
99
"width": 2
1010
},
11-
"color": ["black", "black", "black", "black", "black", "orange" ],
12-
"label": ["process0", "process1", "process2", "process3", "process4", "Group A"],
11+
"color": ["black", "black", "black", "black", "black", "orange", "orange" ],
12+
"label": ["process0", "process1", "process2", "process3", "process4", "Group A", "Group B"],
1313
"groups": [[2, 3, 4]]
1414
},
1515
"link": {

test/jasmine/tests/sankey_test.js

+24
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,30 @@ describe('sankey tests', function() {
303303
expect(groups.length).toBe(2);
304304
expect(calcData[0].circular).toBe(false);
305305
});
306+
307+
it('emits a warning if a node is part of more than one group', function() {
308+
var warnings = [];
309+
spyOn(Lib, 'warn').and.callFake(function(msg) {
310+
warnings.push(msg);
311+
});
312+
313+
var calcData = _calc(Lib.extendDeep({}, base, {
314+
node: {
315+
label: ['a', 'b', 'c', 'd', 'e'],
316+
groups: [[0, 1], [1, 2, 3]]
317+
},
318+
link: {
319+
value: [1, 1, 1, 1],
320+
source: [0, 1, 2, 3],
321+
target: [1, 2, 4, 4]
322+
}
323+
}));
324+
325+
expect(warnings.length).toBe(1);
326+
327+
// Expect node '1' to be in the first group
328+
expect(calcData[0]._groupLookup[1]).toBe(5);
329+
});
306330
});
307331

308332
describe('lifecycle methods', function() {

0 commit comments

Comments
 (0)