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