@@ -67,6 +67,72 @@ function sankeyModel(layout, d, traceIndex) {
67
67
Lib . warn ( 'node.pad was reduced to ' , sankey . nodePadding ( ) , ' to fit within the figure.' ) ;
68
68
}
69
69
70
+ function computeLinkConcentrations ( ) {
71
+ var i , j , k ;
72
+ for ( i = 0 ; i < graph . nodes . length ; i ++ ) {
73
+ var node = graph . nodes [ i ] ;
74
+ // Links connecting the same two nodes are part of a flow
75
+ var flows = { } ;
76
+ var flowKey ;
77
+ var link ;
78
+ for ( j = 0 ; j < node . targetLinks . length ; j ++ ) {
79
+ link = node . targetLinks [ j ] ;
80
+ flowKey = link . source . pointNumber + ':' + link . target . pointNumber ;
81
+ if ( ! flows . hasOwnProperty ( flowKey ) ) flows [ flowKey ] = [ ] ;
82
+ flows [ flowKey ] . push ( link ) ;
83
+ }
84
+
85
+ // Compute statistics for each flow
86
+ var keys = Object . keys ( flows ) ;
87
+ for ( j = 0 ; j < keys . length ; j ++ ) {
88
+ flowKey = keys [ j ] ;
89
+ var flowLinks = flows [ flowKey ] ;
90
+
91
+ // Find the total size of the flow and total size per label
92
+ var total = 0 ;
93
+ var totalPerLabel = { } ;
94
+ for ( k = 0 ; k < flowLinks . length ; k ++ ) {
95
+ link = flowLinks [ k ] ;
96
+ if ( ! totalPerLabel [ link . label ] ) totalPerLabel [ link . label ] = 0 ;
97
+ totalPerLabel [ link . label ] += link . value ;
98
+ total += link . value ;
99
+ }
100
+
101
+ // Find the ratio of the link's value and the size of the flow
102
+ for ( k = 0 ; k < flowLinks . length ; k ++ ) {
103
+ link = flowLinks [ k ] ;
104
+ link . flow = {
105
+ value : total ,
106
+ labelConcentration : totalPerLabel [ link . label ] / total ,
107
+ concentration : link . value / total ,
108
+ links : flowLinks
109
+ } ;
110
+ }
111
+ }
112
+
113
+ // Gather statistics of all links at current node
114
+ var totalOutflow = 0 ;
115
+ for ( j = 0 ; j < node . sourceLinks . length ; j ++ ) {
116
+ totalOutflow += node . sourceLinks [ j ] . value ;
117
+ }
118
+ for ( j = 0 ; j < node . sourceLinks . length ; j ++ ) {
119
+ link = node . sourceLinks [ j ] ;
120
+ link . concentrationOut = link . value / totalOutflow ;
121
+ }
122
+
123
+ var totalInflow = 0 ;
124
+ for ( j = 0 ; j < node . targetLinks . length ; j ++ ) {
125
+ totalInflow += node . targetLinks [ j ] . value ;
126
+ }
127
+
128
+ for ( j = 0 ; j < node . targetLinks . length ; j ++ ) {
129
+ link = node . targetLinks [ j ] ;
130
+ link . concenrationIn = link . value / totalInflow ;
131
+ }
132
+ }
133
+ }
134
+ computeLinkConcentrations ( ) ;
135
+
70
136
return {
71
137
circular : circular ,
72
138
key : traceIndex ,
@@ -100,6 +166,9 @@ function sankeyModel(layout, d, traceIndex) {
100
166
101
167
function linkModel ( d , l , i ) {
102
168
var tc = tinycolor ( l . color ) ;
169
+ if ( l . concentrationscale ) {
170
+ tc = tinycolor ( l . concentrationscale ( l . flow . labelConcentration ) ) ;
171
+ }
103
172
var basicKey = l . source . label + '|' + l . target . label ;
104
173
var key = basicKey + '__' + i ;
105
174
@@ -121,7 +190,8 @@ function linkModel(d, l, i) {
121
190
valueSuffix : d . valueSuffix ,
122
191
sankey : d . sankey ,
123
192
parent : d ,
124
- interactionState : d . interactionState
193
+ interactionState : d . interactionState ,
194
+ flow : l . flow
125
195
} ;
126
196
}
127
197
@@ -568,7 +638,7 @@ function switchToSankeyFormat(nodes) {
568
638
}
569
639
570
640
// scene graph
571
- module . exports = function ( svg , calcData , layout , callbacks ) {
641
+ module . exports = function ( gd , svg , calcData , layout , callbacks ) {
572
642
573
643
var styledData = calcData
574
644
. filter ( function ( d ) { return unwrap ( d ) . trace . visible ; } )
0 commit comments