@@ -60,6 +60,10 @@ function convertToD3Sankey(trace) {
60
60
}
61
61
62
62
// Process links
63
+ var groupedLinks = {
64
+ source : [ ] ,
65
+ target : [ ]
66
+ } ;
63
67
for ( i = 0 ; i < linkSpec . value . length ; i ++ ) {
64
68
var val = linkSpec . value [ i ] ;
65
69
// remove negative values, but keep zeros with special treatment
@@ -103,6 +107,9 @@ function convertToD3Sankey(trace) {
103
107
target : target ,
104
108
value : + val
105
109
} ) ;
110
+
111
+ groupedLinks . source . push ( source ) ;
112
+ groupedLinks . target . push ( target ) ;
106
113
}
107
114
108
115
// Process nodes
@@ -122,7 +129,14 @@ function convertToD3Sankey(trace) {
122
129
} ) ;
123
130
}
124
131
132
+ // Check if we have circularity on the resulting graph
133
+ var circular = false ;
134
+ if ( circularityPresent ( totalCount , groupedLinks . source , groupedLinks . target ) ) {
135
+ circular = true ;
136
+ }
137
+
125
138
return {
139
+ circular : circular ,
126
140
links : links ,
127
141
nodes : nodes ,
128
142
@@ -132,9 +146,7 @@ function convertToD3Sankey(trace) {
132
146
} ;
133
147
}
134
148
135
- function circularityPresent ( nodeList , sources , targets ) {
136
-
137
- var nodeLen = nodeList . length ;
149
+ function circularityPresent ( nodeLen , sources , targets ) {
138
150
var nodes = Lib . init2dArray ( nodeLen , 0 ) ;
139
151
140
152
for ( var i = 0 ; i < Math . min ( sources . length , targets . length ) ; i ++ ) {
@@ -156,15 +168,10 @@ function circularityPresent(nodeList, sources, targets) {
156
168
}
157
169
158
170
module . exports = function calc ( gd , trace ) {
159
- var circular = false ;
160
- if ( circularityPresent ( trace . node . label , trace . link . source , trace . link . target ) ) {
161
- circular = true ;
162
- }
163
-
164
171
var result = convertToD3Sankey ( trace ) ;
165
172
166
173
return wrap ( {
167
- circular : circular ,
174
+ circular : result . circular ,
168
175
_nodes : result . nodes ,
169
176
_links : result . links ,
170
177
0 commit comments