@@ -271,6 +271,7 @@ function sankeyModel(layout, d, traceIndex) {
271
271
nodeLineWidth : trace . node . line . width ,
272
272
linkLineColor : trace . link . line . color ,
273
273
linkLineWidth : trace . link . line . width ,
274
+ linkArrowWidth : trace . link . arrowwidth ,
274
275
valueFormat : trace . valueformat ,
275
276
valueSuffix : trace . valuesuffix ,
276
277
textFont : trace . textfont ,
@@ -309,6 +310,7 @@ function linkModel(d, l, i) {
309
310
linkPath : linkPath ,
310
311
linkLineColor : d . linkLineColor ,
311
312
linkLineWidth : d . linkLineWidth ,
313
+ linkArrowWidth : d . linkArrowWidth ,
312
314
valueFormat : d . valueFormat ,
313
315
valueSuffix : d . valueSuffix ,
314
316
sankey : d . sankey ,
@@ -318,7 +320,7 @@ function linkModel(d, l, i) {
318
320
} ;
319
321
}
320
322
321
- function createCircularClosedPathString ( link ) {
323
+ function createCircularClosedPathString ( link , arrowWidth ) {
322
324
// Using coordinates computed by d3-sankey-circular
323
325
var pathString = '' ;
324
326
var offset = link . width / 2 ;
@@ -328,17 +330,17 @@ function createCircularClosedPathString(link) {
328
330
pathString =
329
331
// start at the left of the target node
330
332
'M ' +
331
- coords . targetX + ' ' + ( coords . targetY + offset ) + ' ' +
333
+ ( coords . targetX - arrowWidth ) + ' ' + ( coords . targetY + offset ) + ' ' +
332
334
'L' +
333
- coords . rightInnerExtent + ' ' + ( coords . targetY + offset ) +
335
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . targetY + offset ) +
334
336
'A' +
335
337
( coords . rightLargeArcRadius + offset ) + ' ' + ( coords . rightSmallArcRadius + offset ) + ' 0 0 1 ' +
336
- ( coords . rightFullExtent - offset ) + ' ' + ( coords . targetY - coords . rightSmallArcRadius ) +
338
+ ( coords . rightFullExtent - offset - arrowWidth ) + ' ' + ( coords . targetY - coords . rightSmallArcRadius ) +
337
339
'L' +
338
- ( coords . rightFullExtent - offset ) + ' ' + coords . verticalRightInnerExtent +
340
+ ( coords . rightFullExtent - offset - arrowWidth ) + ' ' + coords . verticalRightInnerExtent +
339
341
'A' +
340
342
( coords . rightLargeArcRadius + offset ) + ' ' + ( coords . rightLargeArcRadius + offset ) + ' 0 0 1 ' +
341
- coords . rightInnerExtent + ' ' + ( coords . verticalFullExtent - offset ) +
343
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . verticalFullExtent - offset ) +
342
344
'L' +
343
345
coords . leftInnerExtent + ' ' + ( coords . verticalFullExtent - offset ) +
344
346
'A' +
@@ -366,34 +368,35 @@ function createCircularClosedPathString(link) {
366
368
( coords . leftLargeArcRadius - offset ) + ' ' + ( coords . leftLargeArcRadius - offset ) + ' 0 0 0 ' +
367
369
coords . leftInnerExtent + ' ' + ( coords . verticalFullExtent + offset ) +
368
370
'L' +
369
- coords . rightInnerExtent + ' ' + ( coords . verticalFullExtent + offset ) +
371
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . verticalFullExtent + offset ) +
370
372
'A' +
371
373
( coords . rightLargeArcRadius - offset ) + ' ' + ( coords . rightLargeArcRadius - offset ) + ' 0 0 0 ' +
372
- ( coords . rightFullExtent + offset ) + ' ' + coords . verticalRightInnerExtent +
374
+ ( coords . rightFullExtent + offset - arrowWidth ) + ' ' + coords . verticalRightInnerExtent +
373
375
'L' +
374
- ( coords . rightFullExtent + offset ) + ' ' + ( coords . targetY - coords . rightSmallArcRadius ) +
376
+ ( coords . rightFullExtent + offset - arrowWidth ) + ' ' + ( coords . targetY - coords . rightSmallArcRadius ) +
375
377
'A' +
376
378
( coords . rightLargeArcRadius - offset ) + ' ' + ( coords . rightSmallArcRadius - offset ) + ' 0 0 0 ' +
377
- coords . rightInnerExtent + ' ' + ( coords . targetY - offset ) +
379
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . targetY - offset ) +
378
380
'L' +
379
- coords . targetX + ' ' + ( coords . targetY - offset ) +
381
+ ( coords . targetX - arrowWidth ) + ' ' + ( coords . targetY - offset ) +
382
+ ( arrowWidth > 0 ? 'L ' + coords . targetX + ' ' + ( coords . targetY ) : '' ) +
380
383
'Z' ;
381
384
} else {
382
385
// Bottom path
383
386
pathString =
384
387
// start at the left of the target node
385
388
'M ' +
386
- coords . targetX + ' ' + ( coords . targetY - offset ) + ' ' +
389
+ ( coords . targetX - arrowWidth ) + ' ' + ( coords . targetY - offset ) + ' ' +
387
390
'L' +
388
- coords . rightInnerExtent + ' ' + ( coords . targetY - offset ) +
391
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . targetY - offset ) +
389
392
'A' +
390
393
( coords . rightLargeArcRadius + offset ) + ' ' + ( coords . rightSmallArcRadius + offset ) + ' 0 0 0 ' +
391
- ( coords . rightFullExtent - offset ) + ' ' + ( coords . targetY + coords . rightSmallArcRadius ) +
394
+ ( coords . rightFullExtent - offset - arrowWidth ) + ' ' + ( coords . targetY + coords . rightSmallArcRadius ) +
392
395
'L' +
393
- ( coords . rightFullExtent - offset ) + ' ' + coords . verticalRightInnerExtent +
396
+ ( coords . rightFullExtent - offset - arrowWidth ) + ' ' + coords . verticalRightInnerExtent +
394
397
'A' +
395
398
( coords . rightLargeArcRadius + offset ) + ' ' + ( coords . rightLargeArcRadius + offset ) + ' 0 0 0 ' +
396
- coords . rightInnerExtent + ' ' + ( coords . verticalFullExtent + offset ) +
399
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . verticalFullExtent + offset ) +
397
400
'L' +
398
401
coords . leftInnerExtent + ' ' + ( coords . verticalFullExtent + offset ) +
399
402
'A' +
@@ -421,17 +424,18 @@ function createCircularClosedPathString(link) {
421
424
( coords . leftLargeArcRadius - offset ) + ' ' + ( coords . leftLargeArcRadius - offset ) + ' 0 0 1 ' +
422
425
coords . leftInnerExtent + ' ' + ( coords . verticalFullExtent - offset ) +
423
426
'L' +
424
- coords . rightInnerExtent + ' ' + ( coords . verticalFullExtent - offset ) +
427
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . verticalFullExtent - offset ) +
425
428
'A' +
426
429
( coords . rightLargeArcRadius - offset ) + ' ' + ( coords . rightLargeArcRadius - offset ) + ' 0 0 1 ' +
427
- ( coords . rightFullExtent + offset ) + ' ' + coords . verticalRightInnerExtent +
430
+ ( coords . rightFullExtent + offset - arrowWidth ) + ' ' + coords . verticalRightInnerExtent +
428
431
'L' +
429
- ( coords . rightFullExtent + offset ) + ' ' + ( coords . targetY + coords . rightSmallArcRadius ) +
432
+ ( coords . rightFullExtent + offset - arrowWidth ) + ' ' + ( coords . targetY + coords . rightSmallArcRadius ) +
430
433
'A' +
431
434
( coords . rightLargeArcRadius - offset ) + ' ' + ( coords . rightSmallArcRadius - offset ) + ' 0 0 1 ' +
432
- coords . rightInnerExtent + ' ' + ( coords . targetY + offset ) +
435
+ ( coords . rightInnerExtent - arrowWidth ) + ' ' + ( coords . targetY + offset ) +
433
436
'L' +
434
- coords . targetX + ' ' + ( coords . targetY + offset ) +
437
+ ( coords . targetX - arrowWidth ) + ' ' + ( coords . targetY + offset ) +
438
+ ( arrowWidth > 0 ? 'L ' + coords . targetX + ' ' + ( coords . targetY ) : '' ) +
435
439
'Z' ;
436
440
}
437
441
return pathString ;
@@ -441,26 +445,36 @@ function linkPath() {
441
445
var curvature = 0.5 ;
442
446
function path ( d ) {
443
447
if ( d . link . circular ) {
444
- return createCircularClosedPathString ( d . link ) ;
448
+ return createCircularClosedPathString ( d . link , d . linkArrowWidth ) ;
445
449
} else {
450
+ var arrowWidth = d . linkArrowWidth ;
446
451
var x0 = d . link . source . x1 ;
447
- var x1 = d . link . target . x0 ;
452
+ var x1 = d . link . target . x0 - arrowWidth ;
448
453
var xi = interpolateNumber ( x0 , x1 ) ;
449
454
var x2 = xi ( curvature ) ;
450
455
var x3 = xi ( 1 - curvature ) ;
451
456
var y0a = d . link . y0 - d . link . width / 2 ;
452
457
var y0b = d . link . y0 + d . link . width / 2 ;
453
458
var y1a = d . link . y1 - d . link . width / 2 ;
454
459
var y1b = d . link . y1 + d . link . width / 2 ;
455
- return 'M' + x0 + ',' + y0a +
456
- 'C' + x2 + ',' + y0a +
457
- ' ' + x3 + ',' + y1a +
458
- ' ' + x1 + ',' + y1a +
459
- 'L' + x1 + ',' + y1b +
460
- 'C' + x3 + ',' + y1b +
461
- ' ' + x2 + ',' + y0b +
462
- ' ' + x0 + ',' + y0b +
463
- 'Z' ;
460
+ var start = 'M' + x0 + ',' + y0a ;
461
+ var upperCurve = 'C' + x2 + ',' + y0a +
462
+ ' ' + x3 + ',' + y1a +
463
+ ' ' + x1 + ',' + y1a ;
464
+ var lowerCurve = 'C' + x3 + ',' + y1b +
465
+ ' ' + x2 + ',' + y0b +
466
+ ' ' + x0 + ',' + y0b ;
467
+ var rightEnd ;
468
+
469
+ if ( arrowWidth > 0 ) {
470
+ rightEnd =
471
+ 'L' + ( x1 + arrowWidth ) + ',' + ( y1a + d . link . width / 2 ) +
472
+ ' L' + x1 + ',' + y1b
473
+ ;
474
+ } else {
475
+ rightEnd = 'L' + x1 + ',' + y1b ;
476
+ }
477
+ return start + upperCurve + rightEnd + lowerCurve + 'Z' ;
464
478
}
465
479
}
466
480
return path ;
0 commit comments