@@ -150,25 +150,38 @@ export function sankeyLayout(
150
150
const layoutData : SankeyLayoutOutputData = sankeyProcessor ( data ) ;
151
151
152
152
// post process (x, y), etc.
153
- layoutData . nodes . forEach ( ( node ) => {
154
- const { x0, x1, y0, y1 } = node ;
155
- /* points
156
- * 3---2
157
- * | |
158
- * 0---1
159
- */
160
- node . x = [ x0 , x1 , x1 , x0 ] ;
161
- node . y = [ y0 , y0 , y1 , y1 ] ;
162
- } ) ;
163
-
164
- layoutData . links . forEach ( ( edge ) => {
165
- const { source, target } = edge ;
166
- const sx = source . x1 ;
167
- const tx = target . x0 ;
168
- edge . x = [ sx , sx , tx , tx ] ;
169
- const offset = edge . width / 2 ;
170
- edge . y = [ edge . y0 + offset , edge . y0 - offset , edge . y1 + offset , edge . y1 - offset ] ;
171
- } ) ;
172
-
173
- return layoutData ;
153
+ const nodes = layoutData . nodes
154
+ . map ( ( node ) => {
155
+ const { x0, x1, y0, y1 } = node ;
156
+ /* points
157
+ * 3---2
158
+ * | |
159
+ * 0---1
160
+ */
161
+ node . x = [ x0 , x1 , x1 , x0 ] ;
162
+ node . y = [ y0 , y0 , y1 , y1 ] ;
163
+
164
+ return node ;
165
+ } )
166
+ . filter ( ( node ) => {
167
+ return node . name !== null ;
168
+ } ) ;
169
+
170
+ const links = layoutData . links
171
+ . map ( ( edge ) => {
172
+ const { source, target } = edge ;
173
+ const sx = source . x1 ;
174
+ const tx = target . x0 ;
175
+ edge . x = [ sx , sx , tx , tx ] ;
176
+ const offset = edge . width / 2 ;
177
+ edge . y = [ edge . y0 + offset , edge . y0 - offset , edge . y1 + offset , edge . y1 - offset ] ;
178
+
179
+ return edge ;
180
+ } )
181
+ . filter ( ( edge ) => {
182
+ const { source, target } = edge ;
183
+ return source . name !== null && target . name !== null ;
184
+ } ) ;
185
+
186
+ return { nodes, links } ;
174
187
}
0 commit comments