@@ -69,53 +69,68 @@ function sankeyModel(layout, d, traceIndex) {
69
69
}
70
70
71
71
function computeLinkConcentrations ( ) {
72
- graph . nodes . forEach ( function ( node ) {
72
+ var i , j , k ;
73
+ for ( i = 0 ; i < graph . nodes . length ; i ++ ) {
74
+ var node = graph . nodes [ i ] ;
73
75
// Links connecting the same two nodes are part of a flow
74
76
var flows = { } ;
75
- node . targetLinks . forEach ( function ( link ) {
76
- var flowKey = link . source . pointNumber + ':' + link . target . pointNumber ;
77
+ var flowKey ;
78
+ var link ;
79
+ for ( j = 0 ; j < node . targetLinks . length ; j ++ ) {
80
+ link = node . targetLinks [ j ] ;
81
+ flowKey = link . source . pointNumber + ':' + link . target . pointNumber ;
77
82
if ( ! flows . hasOwnProperty ( flowKey ) ) flows [ flowKey ] = [ ] ;
78
83
flows [ flowKey ] . push ( link ) ;
79
- } ) ;
84
+ }
80
85
81
86
// Compute statistics for each flow
82
- Object . keys ( flows ) . forEach ( function ( flowKey ) {
87
+ var keys = Object . keys ( flows ) ;
88
+ for ( j = 0 ; j < keys . length ; j ++ ) {
89
+ flowKey = keys [ j ] ;
83
90
var flowLinks = flows [ flowKey ] ;
84
91
85
92
// Find the total size of the flow and total size per label
86
93
var total = 0 ;
87
94
var totalPerLabel = { } ;
88
- flowLinks . forEach ( function ( link ) {
95
+ for ( k = 0 ; k < flowLinks . length ; k ++ ) {
96
+ link = flowLinks [ k ] ;
89
97
if ( ! totalPerLabel [ link . label ] ) totalPerLabel [ link . label ] = 0 ;
90
98
totalPerLabel [ link . label ] += link . value ;
91
99
total += link . value ;
92
- } ) ;
100
+ }
93
101
94
102
// Find the ratio of the link's value and the size of the flow
95
- flowLinks . forEach ( function ( link ) {
103
+ for ( k = 0 ; k < flowLinks . length ; k ++ ) {
104
+ link = flowLinks [ k ] ;
96
105
link . flow = {
97
106
value : total ,
98
107
labelConcentration : totalPerLabel [ link . label ] / total ,
99
108
concentration : link . value / total ,
100
109
links : flowLinks
101
110
} ;
102
- } ) ;
103
- } ) ;
111
+ }
112
+ }
104
113
105
114
// Gather statistics of all links at current node
106
- var totalOutflow = sum ( node . sourceLinks , function ( n ) {
107
- return n . value ;
108
- } ) ;
109
- node . sourceLinks . forEach ( function ( link ) {
115
+ var totalOutflow = 0 ;
116
+ for ( j = 0 ; j < node . sourceLinks . length ; j ++ ) {
117
+ totalOutflow += node . sourceLinks [ j ] . value ;
118
+ }
119
+ for ( j = 0 ; j < node . sourceLinks . length ; j ++ ) {
120
+ link = node . sourceLinks [ j ] ;
110
121
link . concentrationOut = link . value / totalOutflow ;
111
- } ) ;
112
- var totalInflow = sum ( node . targetLinks , function ( n ) {
113
- return n . value ;
114
- } ) ;
115
- node . targetLinks . forEach ( function ( link ) {
122
+ }
123
+
124
+ var totalInflow = 0 ;
125
+ for ( j = 0 ; j < node . targetLinks . length ; j ++ ) {
126
+ totalInflow += node . targetLinks [ j ] . value ;
127
+ }
128
+
129
+ for ( j = 0 ; j < node . targetLinks . length ; j ++ ) {
130
+ link = node . targetLinks [ j ] ;
116
131
link . concenrationIn = link . value / totalInflow ;
117
- } ) ;
118
- } ) ;
132
+ }
133
+ }
119
134
}
120
135
computeLinkConcentrations ( ) ;
121
136
0 commit comments