1
1
import { create } from "d3" ;
2
2
import { filter } from "../defined.js" ;
3
3
import { Mark , identity , number } from "../mark.js" ;
4
+ import { isCollapsed } from "../scales.js" ;
4
5
import { applyDirectStyles , applyIndirectStyles , applyTransform , applyChannelStyles } from "../style.js" ;
5
6
6
7
const defaults = {
@@ -31,13 +32,10 @@ export class RuleX extends Mark {
31
32
this . insetTop = number ( insetTop ) ;
32
33
this . insetBottom = number ( insetBottom ) ;
33
34
}
34
- render (
35
- I ,
36
- { x, y} ,
37
- channels ,
38
- { width, height, marginTop, marginRight, marginLeft, marginBottom}
39
- ) {
35
+ render ( I , { x, y} , channels , dimensions ) {
40
36
const { x : X , y1 : Y1 , y2 : Y2 } = channels ;
37
+ const { width, height, marginTop, marginRight, marginLeft, marginBottom} = dimensions ;
38
+ const { insetTop, insetBottom} = this ;
41
39
const index = filter ( I , X , Y1 , Y2 ) ;
42
40
return create ( "svg:g" )
43
41
. call ( applyIndirectStyles , this )
@@ -48,8 +46,8 @@ export class RuleX extends Mark {
48
46
. call ( applyDirectStyles , this )
49
47
. attr ( "x1" , X ? i => X [ i ] : ( marginLeft + width - marginRight ) / 2 )
50
48
. attr ( "x2" , X ? i => X [ i ] : ( marginLeft + width - marginRight ) / 2 )
51
- . attr ( "y1" , Y1 ? i => Y1 [ i ] + this . insetTop : marginTop + this . insetTop )
52
- . attr ( "y2" , Y2 ? ( y . bandwidth ? i => Y2 [ i ] + y . bandwidth ( ) - this . insetBottom : i => Y2 [ i ] - this . insetBottom ) : height - marginBottom - this . insetBottom )
49
+ . attr ( "y1" , Y1 && ! isCollapsed ( y ) ? i => Y1 [ i ] + insetTop : marginTop + insetTop )
50
+ . attr ( "y2" , Y2 && ! isCollapsed ( y ) ? ( y . bandwidth ? i => Y2 [ i ] + y . bandwidth ( ) - insetBottom : i => Y2 [ i ] - insetBottom ) : height - marginBottom - insetBottom )
53
51
. call ( applyChannelStyles , channels ) )
54
52
. node ( ) ;
55
53
}
@@ -78,13 +76,10 @@ export class RuleY extends Mark {
78
76
this . insetRight = number ( insetRight ) ;
79
77
this . insetLeft = number ( insetLeft ) ;
80
78
}
81
- render (
82
- I ,
83
- { x, y} ,
84
- channels ,
85
- { width, height, marginTop, marginRight, marginLeft, marginBottom}
86
- ) {
79
+ render ( I , { x, y} , channels , dimensions ) {
87
80
const { y : Y , x1 : X1 , x2 : X2 } = channels ;
81
+ const { width, height, marginTop, marginRight, marginLeft, marginBottom} = dimensions ;
82
+ const { insetLeft, insetRight} = this ;
88
83
const index = filter ( I , Y , X1 , X2 ) ;
89
84
return create ( "svg:g" )
90
85
. call ( applyIndirectStyles , this )
@@ -93,8 +88,8 @@ export class RuleY extends Mark {
93
88
. data ( index )
94
89
. join ( "line" )
95
90
. call ( applyDirectStyles , this )
96
- . attr ( "x1" , X1 ? i => X1 [ i ] + this . insetLeft : marginLeft + this . insetLeft )
97
- . attr ( "x2" , X2 ? ( x . bandwidth ? i => X2 [ i ] + x . bandwidth ( ) - this . insetRight : i => X2 [ i ] - this . insetRight ) : width - marginRight - this . insetRight )
91
+ . attr ( "x1" , X1 && ! isCollapsed ( x ) ? i => X1 [ i ] + insetLeft : marginLeft + insetLeft )
92
+ . attr ( "x2" , X2 && ! isCollapsed ( x ) ? ( x . bandwidth ? i => X2 [ i ] + x . bandwidth ( ) - insetRight : i => X2 [ i ] - insetRight ) : width - marginRight - insetRight )
98
93
. attr ( "y1" , Y ? i => Y [ i ] : ( marginTop + height - marginBottom ) / 2 )
99
94
. attr ( "y2" , Y ? i => Y [ i ] : ( marginTop + height - marginBottom ) / 2 )
100
95
. call ( applyChannelStyles , channels ) )
0 commit comments