11import { ascending } from "d3" ;
22import { create } from "d3" ;
33import { filter } from "../defined.js" ;
4- import { Mark , maybeColor , title } from "../mark.js" ;
4+ import { Mark , maybeColor , maybeNumber , title } from "../mark.js" ;
55import { Style , applyDirectStyles , applyIndirectStyles , applyTransform , applyAttr } from "../style.js" ;
66
77export class Link extends Mark {
@@ -15,10 +15,12 @@ export class Link extends Mark {
1515 z,
1616 title,
1717 stroke,
18+ strokeOpacity,
1819 ...options
1920 } = { }
2021 ) {
2122 const [ vstroke , cstroke ] = maybeColor ( stroke , "currentColor" ) ;
23+ const [ vstrokeOpacity , cstrokeOpacity ] = maybeNumber ( strokeOpacity ) ;
2224 super (
2325 data ,
2426 [
@@ -28,18 +30,23 @@ export class Link extends Mark {
2830 { name : "y2" , value : y2 , scale : "y" } ,
2931 { name : "z" , value : z , optional : true } ,
3032 { name : "title" , value : title , optional : true } ,
31- { name : "stroke" , value : vstroke , scale : "color" , optional : true }
33+ { name : "stroke" , value : vstroke , scale : "color" , optional : true } ,
34+ { name : "strokeOpacity" , value : vstrokeOpacity , scale : "opacity" , optional : true }
3235 ] ,
3336 options
3437 ) ;
35- Style ( this , { stroke : cstroke , ...options } ) ;
38+ Style ( this , {
39+ stroke : cstroke ,
40+ strokeOpacity : cstrokeOpacity ,
41+ ...options
42+ } ) ;
3643 }
3744 render (
3845 I ,
3946 { x, y} ,
40- { x1 : X1 , y1 : Y1 , x2 : X2 , y2 : Y2 , z : Z , title : L , stroke : S }
47+ { x1 : X1 , y1 : Y1 , x2 : X2 , y2 : Y2 , z : Z , title : L , stroke : S , strokeOpacity : SO }
4148 ) {
42- const index = filter ( I , X1 , Y1 , X2 , Y2 , S ) ;
49+ const index = filter ( I , X1 , Y1 , X2 , Y2 , S , SO ) ;
4350 if ( Z ) index . sort ( ( i , j ) => ascending ( Z [ i ] , Z [ j ] ) ) ;
4451 return create ( "svg:g" )
4552 . call ( applyIndirectStyles , this )
@@ -53,6 +60,7 @@ export class Link extends Mark {
5360 . attr ( "x2" , i => X2 [ i ] )
5461 . attr ( "y2" , i => Y2 [ i ] )
5562 . call ( applyAttr , "stroke" , S && ( i => S [ i ] ) )
63+ . call ( applyAttr , "stroke-opacity" , SO && ( i => SO [ i ] ) )
5664 . call ( title ( L ) ) )
5765 . node ( ) ;
5866 }
0 commit comments