11import { create } from "d3" ;
22import { filter } from "../defined.js" ;
3- import { Mark , number , maybeColor , title , maybeNumber } from "../mark.js" ;
4- import { Style , applyDirectStyles , applyIndirectStyles , applyTransform , impliedString , applyAttr } from "../style.js" ;
3+ import { Mark , number } from "../mark.js" ;
4+ import { applyDirectStyles , applyIndirectStyles , applyTransform , impliedString , applyAttr , applyChannelStyles } from "../style.js" ;
55import { maybeStackX , maybeStackY } from "../transforms/stack.js" ;
66
7+ const defaults = { } ;
8+
79export class AbstractBar extends Mark {
8- constructor (
9- data ,
10- channels ,
11- {
12- title,
13- fill,
14- fillOpacity,
15- stroke,
16- strokeOpacity,
17- inset = 0 ,
18- insetTop = inset ,
19- insetRight = inset ,
20- insetBottom = inset ,
21- insetLeft = inset ,
22- rx,
23- ry,
24- ...options
25- } = { }
26- ) {
27- const [ vstroke , cstroke ] = maybeColor ( stroke , "none" ) ;
28- const [ vstrokeOpacity , cstrokeOpacity ] = maybeNumber ( strokeOpacity ) ;
29- const [ vfill , cfill ] = maybeColor ( fill , cstroke === "none" ? "currentColor" : "none" ) ;
30- const [ vfillOpacity , cfillOpacity ] = maybeNumber ( fillOpacity ) ;
31- super (
32- data ,
33- [
34- ...channels ,
35- { name : "title" , value : title , optional : true } ,
36- { name : "fill" , value : vfill , scale : "color" , optional : true } ,
37- { name : "fillOpacity" , value : vfillOpacity , scale : "opacity" , optional : true } ,
38- { name : "stroke" , value : vstroke , scale : "color" , optional : true } ,
39- { name : "strokeOpacity" , value : vstrokeOpacity , scale : "opacity" , optional : true }
40- ] ,
41- options
42- ) ;
43- Style ( this , {
44- fill : cfill ,
45- fillOpacity : cfillOpacity ,
46- stroke : cstroke ,
47- strokeOpacity : cstrokeOpacity ,
48- ...options
49- } ) ;
10+ constructor ( data , channels , options = { } ) {
11+ super ( data , channels , options , defaults ) ;
12+ const { inset = 0 , insetTop = inset , insetRight = inset , insetBottom = inset , insetLeft = inset , rx, ry} = options ;
5013 this . insetTop = number ( insetTop ) ;
5114 this . insetRight = number ( insetRight ) ;
5215 this . insetBottom = number ( insetBottom ) ;
@@ -56,8 +19,7 @@ export class AbstractBar extends Mark {
5619 }
5720 render ( I , scales , channels , dimensions ) {
5821 const { rx, ry} = this ;
59- const { title : L , fill : F , fillOpacity : FO , stroke : S , strokeOpacity : SO } = channels ;
60- const index = filter ( I , ...this . _positions ( channels ) , F , FO , S , SO ) ;
22+ const index = filter ( I , ...this . _positions ( channels ) ) ;
6123 return create ( "svg:g" )
6224 . call ( applyIndirectStyles , this )
6325 . call ( this . _transform , scales )
@@ -69,13 +31,9 @@ export class AbstractBar extends Mark {
6931 . attr ( "width" , this . _width ( scales , channels , dimensions ) )
7032 . attr ( "y" , this . _y ( scales , channels , dimensions ) )
7133 . attr ( "height" , this . _height ( scales , channels , dimensions ) )
72- . call ( applyAttr , "fill" , F && ( i => F [ i ] ) )
73- . call ( applyAttr , "fill-opacity" , FO && ( i => FO [ i ] ) )
74- . call ( applyAttr , "stroke" , S && ( i => S [ i ] ) )
75- . call ( applyAttr , "stroke-opacity" , SO && ( i => SO [ i ] ) )
7634 . call ( applyAttr , "rx" , rx )
7735 . call ( applyAttr , "ry" , ry )
78- . call ( title ( L ) ) )
36+ . call ( applyChannelStyles , channels ) )
7937 . node ( ) ;
8038 }
8139 _x ( scales , { x : X } , { marginLeft} ) {
@@ -99,7 +57,8 @@ export class AbstractBar extends Mark {
9957}
10058
10159export class BarX extends AbstractBar {
102- constructor ( data , { x1, x2, y, ...options } = { } ) {
60+ constructor ( data , options = { } ) {
61+ const { x1, x2, y} = options ;
10362 super (
10463 data ,
10564 [
@@ -127,7 +86,8 @@ export class BarX extends AbstractBar {
12786}
12887
12988export class BarY extends AbstractBar {
130- constructor ( data , { x, y1, y2, ...options } = { } ) {
89+ constructor ( data , options = { } ) {
90+ const { x, y1, y2} = options ;
13191 super (
13292 data ,
13393 [
0 commit comments