@@ -60,6 +60,10 @@ function convertToD3Sankey(trace) {
6060 }
6161
6262 // Process links
63+ var groupedLinks = {
64+ source : [ ] ,
65+ target : [ ]
66+ } ;
6367 for ( i = 0 ; i < linkSpec . value . length ; i ++ ) {
6468 var val = linkSpec . value [ i ] ;
6569 // remove negative values, but keep zeros with special treatment
@@ -103,6 +107,9 @@ function convertToD3Sankey(trace) {
103107 target : target ,
104108 value : + val
105109 } ) ;
110+
111+ groupedLinks . source . push ( source ) ;
112+ groupedLinks . target . push ( target ) ;
106113 }
107114
108115 // Process nodes
@@ -122,7 +129,14 @@ function convertToD3Sankey(trace) {
122129 } ) ;
123130 }
124131
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+
125138 return {
139+ circular : circular ,
126140 links : links ,
127141 nodes : nodes ,
128142
@@ -132,9 +146,7 @@ function convertToD3Sankey(trace) {
132146 } ;
133147}
134148
135- function circularityPresent ( nodeList , sources , targets ) {
136-
137- var nodeLen = nodeList . length ;
149+ function circularityPresent ( nodeLen , sources , targets ) {
138150 var nodes = Lib . init2dArray ( nodeLen , 0 ) ;
139151
140152 for ( var i = 0 ; i < Math . min ( sources . length , targets . length ) ; i ++ ) {
@@ -156,15 +168,10 @@ function circularityPresent(nodeList, sources, targets) {
156168}
157169
158170module . 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-
164171 var result = convertToD3Sankey ( trace ) ;
165172
166173 return wrap ( {
167- circular : circular ,
174+ circular : result . circular ,
168175 _nodes : result . nodes ,
169176 _links : result . links ,
170177
0 commit comments