1
1
import { create } from "d3" ;
2
2
import { filter } from "../defined.js" ;
3
- import { Mark , identity , maybeColor , title , number } from "../mark.js" ;
3
+ import { Mark , identity , maybeColor , title , number , maybeNumber } from "../mark.js" ;
4
4
import { Style , applyDirectStyles , applyIndirectStyles , applyTransform , applyAttr } from "../style.js" ;
5
5
6
6
export class RuleX extends Mark {
@@ -12,32 +12,35 @@ export class RuleX extends Mark {
12
12
y2,
13
13
title,
14
14
stroke,
15
+ strokeOpacity,
15
16
inset = 0 ,
16
17
insetTop = inset ,
17
18
insetBottom = inset ,
18
19
...options
19
20
} = { }
20
21
) {
21
22
const [ vstroke , cstroke ] = maybeColor ( stroke , "currentColor" ) ;
23
+ const [ vstrokeOpacity , cstrokeOpacity ] = maybeNumber ( strokeOpacity ) ;
22
24
super (
23
25
data ,
24
26
[
25
27
{ name : "x" , value : x , scale : "x" , optional : true } ,
26
28
{ name : "y1" , value : y1 , scale : "y" , optional : true } ,
27
29
{ name : "y2" , value : y2 , scale : "y" , optional : true } ,
28
30
{ name : "title" , value : title , optional : true } ,
29
- { name : "stroke" , value : vstroke , scale : "color" , optional : true }
31
+ { name : "stroke" , value : vstroke , scale : "color" , optional : true } ,
32
+ { name : "strokeOpacity" , value : vstrokeOpacity , scale : "opacity" , optional : true }
30
33
] ,
31
34
options
32
35
) ;
33
- Style ( this , { stroke : cstroke , ...options } ) ;
36
+ Style ( this , { stroke : cstroke , strokeOpacity : cstrokeOpacity , ...options } ) ;
34
37
this . insetTop = number ( insetTop ) ;
35
38
this . insetBottom = number ( insetBottom ) ;
36
39
}
37
40
render (
38
41
I ,
39
42
{ x, y} ,
40
- { x : X , y1 : Y1 , y2 : Y2 , title : L , stroke : S } ,
43
+ { x : X , y1 : Y1 , y2 : Y2 , title : L , stroke : S , strokeOpacity : SO } ,
41
44
{ width, height, marginTop, marginRight, marginLeft, marginBottom}
42
45
) {
43
46
const index = filter ( I , X , Y1 , Y2 , S ) ;
@@ -53,6 +56,7 @@ export class RuleX extends Mark {
53
56
. attr ( "y1" , Y1 ? i => Y1 [ i ] + this . insetTop : marginTop + this . insetTop )
54
57
. attr ( "y2" , Y2 ? ( y . bandwidth ? i => Y2 [ i ] + y . bandwidth ( ) - this . insetBottom : i => Y2 [ i ] - this . insetBottom ) : height - marginBottom - this . insetBottom )
55
58
. call ( applyAttr , "stroke" , S && ( i => S [ i ] ) )
59
+ . call ( applyAttr , "stroke-opacity" , SO && ( i => SO [ i ] ) )
56
60
. call ( title ( L ) ) )
57
61
. node ( ) ;
58
62
}
@@ -67,32 +71,35 @@ export class RuleY extends Mark {
67
71
y,
68
72
title,
69
73
stroke,
74
+ strokeOpacity,
70
75
inset = 0 ,
71
76
insetRight = inset ,
72
77
insetLeft = inset ,
73
78
...options
74
79
} = { }
75
80
) {
76
81
const [ vstroke , cstroke ] = maybeColor ( stroke , "currentColor" ) ;
82
+ const [ vstrokeOpacity , cstrokeOpacity ] = maybeNumber ( strokeOpacity ) ;
77
83
super (
78
84
data ,
79
85
[
80
86
{ name : "y" , value : y , scale : "y" , optional : true } ,
81
87
{ name : "x1" , value : x1 , scale : "x" , optional : true } ,
82
88
{ name : "x2" , value : x2 , scale : "x" , optional : true } ,
83
89
{ name : "title" , value : title , optional : true } ,
84
- { name : "stroke" , value : vstroke , scale : "color" , optional : true }
90
+ { name : "stroke" , value : vstroke , scale : "color" , optional : true } ,
91
+ { name : "strokeOpacity" , value : vstrokeOpacity , scale : "opacity" , optional : true }
85
92
] ,
86
93
options
87
94
) ;
88
- Style ( this , { stroke : cstroke , ...options } ) ;
95
+ Style ( this , { stroke : cstroke , strokeOpacity : cstrokeOpacity , ...options } ) ;
89
96
this . insetRight = number ( insetRight ) ;
90
97
this . insetLeft = number ( insetLeft ) ;
91
98
}
92
99
render (
93
100
I ,
94
101
{ x, y} ,
95
- { y : Y , x1 : X1 , x2 : X2 , title : L , stroke : S } ,
102
+ { y : Y , x1 : X1 , x2 : X2 , title : L , stroke : S , strokeOpacity : SO } ,
96
103
{ width, height, marginTop, marginRight, marginLeft, marginBottom}
97
104
) {
98
105
const index = filter ( I , Y , X1 , X2 ) ;
@@ -108,6 +115,7 @@ export class RuleY extends Mark {
108
115
. attr ( "y1" , Y ? i => Y [ i ] : ( marginTop + height - marginBottom ) / 2 )
109
116
. attr ( "y2" , Y ? i => Y [ i ] : ( marginTop + height - marginBottom ) / 2 )
110
117
. call ( applyAttr , "stroke" , S && ( i => S [ i ] ) )
118
+ . call ( applyAttr , "stroke-opacity" , SO && ( i => SO [ i ] ) )
111
119
. call ( title ( L ) ) )
112
120
. node ( ) ;
113
121
}
0 commit comments