@@ -13,14 +13,16 @@ var d3 = require('d3');
13
13
var tinycolor = require ( 'tinycolor2' ) ;
14
14
var Color = require ( '../../components/color' ) ;
15
15
var Drawing = require ( '../../components/drawing' ) ;
16
- var d3sankey = require ( 'd3-sankey' ) ;
16
+ // TODO: allow swapping Sankey engine
17
+ // var d3Sankey = require('d3-sankey');
18
+ var d3SankeyCircular = require ( 'd3-sankey-circular' ) ;
17
19
var d3Force = require ( 'd3-force' ) ;
18
20
var Lib = require ( '../../lib' ) ;
19
21
var gup = require ( '../../lib/gup' ) ;
20
22
var keyFun = gup . keyFun ;
21
23
var repeat = gup . repeat ;
22
24
var unwrap = gup . unwrap ;
23
- var interpolateNumber = require ( 'd3-interpolate' ) . interpolateNumber ;
25
+ // var interpolateNumber = require('d3-interpolate').interpolateNumber;
24
26
25
27
// view models
26
28
@@ -38,12 +40,13 @@ function sankeyModel(layout, d, traceIndex) {
38
40
var nodes = calcData . _nodes ;
39
41
var links = calcData . _links ;
40
42
41
- var sankey = d3sankey
42
- . sankey ( )
43
+ var sankey = d3SankeyCircular
44
+ . sankeyCircular ( )
43
45
. iterations ( c . sankeyIterations )
44
46
. size ( horizontal ? [ width , height ] : [ height , width ] )
45
47
. nodeWidth ( nodeThickness )
46
48
. nodePadding ( nodePad )
49
+ . circularLinkGap ( 2 )
47
50
. nodes ( nodes )
48
51
. links ( links ) ;
49
52
@@ -108,29 +111,34 @@ function linkModel(d, l, i) {
108
111
}
109
112
110
113
function linkPath ( ) {
111
- var curvature = 0.5 ;
112
-
113
- function shape ( d ) {
114
- var x0 = d . link . source . x1 ,
115
- x1 = d . link . target . x0 ,
116
- xi = interpolateNumber ( x0 , x1 ) ,
117
- x2 = xi ( curvature ) ,
118
- x3 = xi ( 1 - curvature ) ,
119
- y0a = d . link . y0 - d . link . width / 2 ,
120
- y0b = d . link . y0 + d . link . width / 2 ,
121
- y1a = d . link . y1 - d . link . width / 2 ,
122
- y1b = d . link . y1 + d . link . width / 2 ;
123
- return 'M' + x0 + ',' + y0a +
124
- 'C' + x2 + ',' + y0a +
125
- ' ' + x3 + ',' + y1a +
126
- ' ' + x1 + ',' + y1a +
127
- 'L' + x1 + ',' + y1b +
128
- 'C' + x3 + ',' + y1b +
129
- ' ' + x2 + ',' + y0b +
130
- ' ' + x0 + ',' + y0b +
131
- 'Z' ;
114
+ function circular ( d ) {
115
+ return d . link . path ;
132
116
}
133
- return shape ;
117
+
118
+ return circular ;
119
+ // var curvature = 0.5;
120
+
121
+ // function shape(d) {
122
+ // var x0 = d.link.source.x1,
123
+ // x1 = d.link.target.x0,
124
+ // xi = interpolateNumber(x0, x1),
125
+ // x2 = xi(curvature),
126
+ // x3 = xi(1 - curvature),
127
+ // y0a = d.link.y0 - d.link.width / 2,
128
+ // y0b = d.link.y0 + d.link.width / 2,
129
+ // y1a = d.link.y1 - d.link.width / 2,
130
+ // y1b = d.link.y1 + d.link.width / 2;
131
+ // return 'M' + x0 + ',' + y0a +
132
+ // 'C' + x2 + ',' + y0a +
133
+ // ' ' + x3 + ',' + y1a +
134
+ // ' ' + x1 + ',' + y1a +
135
+ // 'L' + x1 + ',' + y1b +
136
+ // 'C' + x3 + ',' + y1b +
137
+ // ' ' + x2 + ',' + y0b +
138
+ // ' ' + x0 + ',' + y0b +
139
+ // 'Z';
140
+ // }
141
+ // return shape;
134
142
}
135
143
136
144
function nodeModel ( d , n , i ) {
@@ -177,7 +185,7 @@ function nodeModel(d, n, i) {
177
185
valueFormat : d . valueFormat ,
178
186
valueSuffix : d . valueSuffix ,
179
187
sankey : d . sankey ,
180
- graph : d . sankey ( ) ,
188
+ graph : d . sankey . graph ,
181
189
arrangement : d . arrangement ,
182
190
uniqueNodeLabelPathId : [ d . guid , d . key , key ] . join ( '_' ) ,
183
191
interactionState : d . interactionState
@@ -466,7 +474,8 @@ module.exports = function(svg, calcData, layout, callbacks) {
466
474
467
475
var sankeyLink = sankeyLinks . selectAll ( '.' + c . cn . sankeyLink )
468
476
. data ( function ( d ) {
469
- return d . sankey ( ) . links
477
+ var links = d . graph . links ;
478
+ return links
470
479
. filter ( function ( l ) { return l . value ; } )
471
480
. map ( linkModel . bind ( null , d ) ) ;
472
481
} , keyFun ) ;
@@ -479,14 +488,17 @@ module.exports = function(svg, calcData, layout, callbacks) {
479
488
480
489
sankeyLink
481
490
. style ( 'stroke' , function ( d ) {
482
- return salientEnough ( d ) ? Color . tinyRGB ( tinycolor ( d . linkLineColor ) ) : d . tinyColorHue ;
491
+ return d . tinyColorHue ;
492
+ // return salientEnough(d) ? Color.tinyRGB(tinycolor(d.linkLineColor)) : d.tinyColorHue;
483
493
} )
484
494
. style ( 'stroke-opacity' , function ( d ) {
485
- return salientEnough ( d ) ? Color . opacity ( d . linkLineColor ) : d . tinyColorAlpha ;
495
+ return d . tinyColorAlpha ;
496
+ // return salientEnough(d) ? Color.opacity(d.linkLineColor) : d.tinyColorAlpha;
486
497
} )
487
- . style ( 'stroke-width' , function ( d ) { return salientEnough ( d ) ? d . linkLineWidth : 1 ; } )
488
- . style ( 'fill' , function ( d ) { return d . tinyColorHue ; } )
489
- . style ( 'fill-opacity' , function ( d ) { return d . tinyColorAlpha ; } ) ;
498
+ // .style('stroke-width', function(d) {return salientEnough(d) ? d.linkLineWidth : 1;})
499
+ //.style('fill', function(d) {return d.link.color;})
500
+ //.style('fill-opacity', function(d) {return d.tinyColorAlpha;})
501
+ . style ( 'stroke-width' , function ( d ) { return d . link . width ; } ) ;
490
502
491
503
sankeyLink . transition ( )
492
504
. ease ( c . ease ) . duration ( c . duration )
@@ -515,7 +527,7 @@ module.exports = function(svg, calcData, layout, callbacks) {
515
527
516
528
var sankeyNode = sankeyNodeSet . selectAll ( '.' + c . cn . sankeyNode )
517
529
. data ( function ( d ) {
518
- var nodes = d . sankey ( ) . nodes ;
530
+ var nodes = d . graph . nodes ;
519
531
persistOriginalPlace ( nodes ) ;
520
532
return nodes
521
533
. filter ( function ( n ) { return n . value ; } )
@@ -528,8 +540,8 @@ module.exports = function(svg, calcData, layout, callbacks) {
528
540
. call ( updateNodePositions )
529
541
. call ( attachPointerEvents , sankey , callbacks . nodeEvents ) ;
530
542
531
- sankeyNode
532
- . call ( attachDragHandler , sankeyLink , callbacks ) ; // has to be here as it binds sankeyLink
543
+ // sankeyNode
544
+ // .call(attachDragHandler, sankeyLink, callbacks); // has to be here as it binds sankeyLink
533
545
534
546
sankeyNode . transition ( )
535
547
. ease ( c . ease ) . duration ( c . duration )
0 commit comments