@@ -69,53 +69,68 @@ function sankeyModel(layout, d, traceIndex) {
6969 }
7070
7171 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 ] ;
7375 // Links connecting the same two nodes are part of a flow
7476 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 ;
7782 if ( ! flows . hasOwnProperty ( flowKey ) ) flows [ flowKey ] = [ ] ;
7883 flows [ flowKey ] . push ( link ) ;
79- } ) ;
84+ }
8085
8186 // 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 ] ;
8390 var flowLinks = flows [ flowKey ] ;
8491
8592 // Find the total size of the flow and total size per label
8693 var total = 0 ;
8794 var totalPerLabel = { } ;
88- flowLinks . forEach ( function ( link ) {
95+ for ( k = 0 ; k < flowLinks . length ; k ++ ) {
96+ link = flowLinks [ k ] ;
8997 if ( ! totalPerLabel [ link . label ] ) totalPerLabel [ link . label ] = 0 ;
9098 totalPerLabel [ link . label ] += link . value ;
9199 total += link . value ;
92- } ) ;
100+ }
93101
94102 // 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 ] ;
96105 link . flow = {
97106 value : total ,
98107 labelConcentration : totalPerLabel [ link . label ] / total ,
99108 concentration : link . value / total ,
100109 links : flowLinks
101110 } ;
102- } ) ;
103- } ) ;
111+ }
112+ }
104113
105114 // 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 ] ;
110121 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 ] ;
116131 link . concenrationIn = link . value / totalInflow ;
117- } ) ;
118- } ) ;
132+ }
133+ }
119134 }
120135 computeLinkConcentrations ( ) ;
121136
0 commit comments