Skip to content

Commit 1cd206f

Browse files
committed
sankey: turn node.groups into a info_array, use for loops
1 parent 85470a0 commit 1cd206f

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/traces/sankey/attributes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ var attrs = module.exports = overrideAll({
9090
description: 'The shown name of the node.'
9191
},
9292
groups: {
93-
valType: 'data_array',
93+
valType: 'info_array',
94+
dimensions: 2,
95+
freeLength: true,
9496
dflt: [],
97+
items: {valType: 'number', editType: 'calc'},
9598
role: 'calc',
9699
description: [
97100
'Groups of nodes.',

src/traces/sankey/calc.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ var isIndex = Lib.isIndex;
1717
var Colorscale = require('../../components/colorscale');
1818

1919
function convertToD3Sankey(trace) {
20-
// var nodeSpec = trace.node;
21-
// var linkSpec = trace.link;
22-
var nodeSpec = Lib.extendDeep({}, trace.node);
23-
var linkSpec = Lib.extendDeep({}, trace.link);
20+
var nodeSpec = trace.node;
21+
var linkSpec = trace.link;
2422

2523
var links = [];
2624
var hasLinkColorArray = isArrayOrTypedArray(linkSpec.color);
@@ -50,14 +48,10 @@ function convertToD3Sankey(trace) {
5048
for(i = 0; i < groups.length; i++) {
5149
var group = groups[i];
5250
// Build a lookup table to quickly find in which group a node is
53-
if(Array.isArray(group)) {
54-
for(j = 0; j < group.length; j++) {
55-
var nodeIndex = group[j];
56-
var groupIndex = nodeCount + i;
57-
groupLookup[nodeIndex] = groupIndex;
58-
}
59-
} else {
60-
Lib.warn('node.groups must be an array, default to empty array []');
51+
for(j = 0; j < group.length; j++) {
52+
var nodeIndex = group[j];
53+
var groupIndex = nodeCount + i;
54+
groupLookup[nodeIndex] = groupIndex;
6155
}
6256
}
6357

src/traces/sankey/render.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function sankeyModel(layout, d, traceIndex) {
6868
}
6969

7070
// Create transient nodes for animations
71-
Object.keys(calcData._groupLookup).forEach(function(nodePointNumber) {
71+
for(var nodePointNumber in calcData._groupLookup) {
7272
var groupIndex = parseInt(calcData._groupLookup[nodePointNumber]);
7373

7474
var groupingNode;
@@ -89,7 +89,7 @@ function sankeyModel(layout, d, traceIndex) {
8989
sourceLinks: [],
9090
targetLinks: []
9191
});
92-
});
92+
}
9393

9494
function computeLinkConcentrations() {
9595
var i, j, k;
@@ -161,7 +161,7 @@ function sankeyModel(layout, d, traceIndex) {
161161
circular: circular,
162162
key: traceIndex,
163163
trace: trace,
164-
guid: Math.floor(1e12 * (1 + Math.random())),
164+
guid: Lib.randstr(),
165165
horizontal: horizontal,
166166
width: width,
167167
height: height,
@@ -379,7 +379,7 @@ function nodeModel(d, n) {
379379
var key = 'node_' + n.pointNumber;
380380
// If it's a group, it's mutable and should be unique
381381
if(n.group) {
382-
key = 'group_' + Math.floor(1e12 * (1 + Math.random()));
382+
key = Lib.randstr();
383383
}
384384

385385
// for event data

0 commit comments

Comments
 (0)