11import { create } from "d3-selection" ;
22import { identity , indexOf } from "../mark.js" ;
33import { defined } from "../defined.js" ;
4- import { Mark , string , number } from "../mark.js" ;
4+ import { Mark , number } from "../mark.js" ;
5+ import { Style , applyIndirectStyles , applyDirectStyles } from "../style.js" ;
56
67class Bar extends Mark {
78 constructor (
89 data ,
910 channels ,
1011 {
11- fill = "currentColor" ,
12- fillOpacity,
13- stroke,
14- strokeWidth,
15- strokeOpacity,
16- mixBlendMode,
12+ style,
1713 insetTop = 0 ,
1814 insetRight = 0 ,
1915 insetBottom = 0 ,
2016 insetLeft = 0
2117 } = { }
2218 ) {
2319 super ( data , channels ) ;
24- this . fill = string ( fill ) ;
25- this . fillOpacity = number ( fillOpacity ) ;
26- this . stroke = string ( stroke ) ;
27- this . strokeWidth = number ( strokeWidth ) ;
28- this . strokeOpacity = number ( strokeOpacity ) ;
29- this . mixBlendMode = string ( mixBlendMode ) ;
20+ this . style = Style ( style ) ;
3021 this . insetTop = number ( insetTop ) ;
3122 this . insetRight = number ( insetRight ) ;
3223 this . insetBottom = number ( insetBottom ) ;
3324 this . insetLeft = number ( insetLeft ) ;
3425 }
3526 render ( I , scales , channels ) {
3627 const { x : X , y : Y } = channels ;
37- const {
38- fill,
39- fillOpacity,
40- stroke,
41- strokeWidth,
42- strokeOpacity,
43- mixBlendMode
44- } = this ;
28+ const { style} = this ;
4529 return create ( "svg:g" )
46- . attr ( "fill" , fill )
47- . attr ( "fill-opacity" , fillOpacity )
48- . attr ( "stroke" , stroke )
49- . attr ( "stroke-width" , strokeWidth )
50- . attr ( "stroke-opacity" , strokeOpacity )
30+ . call ( applyIndirectStyles , style )
5131 . call ( g => g . selectAll ( )
5232 . data ( I . filter ( i => defined ( X [ i ] ) && defined ( Y [ i ] ) ) )
5333 . join ( "rect" )
54- . style ( "mix-blend-mode" , mixBlendMode )
34+ . call ( applyDirectStyles , style )
5535 . attr ( "x" , this . _x ( scales , channels ) )
5636 . attr ( "width" , this . _width ( scales , channels ) )
5737 . attr ( "y" , this . _y ( scales , channels ) )
@@ -61,15 +41,15 @@ class Bar extends Mark {
6141}
6242
6343export class BarX extends Bar {
64- constructor ( data , { x = identity , y = indexOf } = { } , style ) {
44+ constructor ( data , { x = identity , y = indexOf , ... options } = { } ) {
6545 super (
6646 data ,
6747 [
6848 { name : "x" , value : x , scale : "x" } ,
6949 { name : "y" , value : y , scale : "y" , type : "band" } ,
7050 { value : [ 0 ] , scale : "x" } // ensure the x-domain includes zero
7151 ] ,
72- style
52+ options
7353 ) ;
7454 }
7555 _x ( { x} , { x : X } ) {
@@ -91,15 +71,15 @@ export class BarX extends Bar {
9171}
9272
9373export class BarY extends Bar {
94- constructor ( data , { x = indexOf , y = identity } = { } , style ) {
74+ constructor ( data , { x = indexOf , y = identity , ... options } = { } ) {
9575 super (
9676 data ,
9777 [
9878 { name : "x" , value : x , scale : "x" , type : "band" } ,
9979 { name : "y" , value : y , scale : "y" } ,
10080 { value : [ 0 ] , scale : "y" } // ensure the y-domain includes zero
10181 ] ,
102- style
82+ options
10383 ) ;
10484 }
10585 _x ( { x} , { x : X } ) {
@@ -120,10 +100,10 @@ export class BarY extends Bar {
120100 }
121101}
122102
123- export function barX ( data , channels , style ) {
124- return new BarX ( data , channels , style ) ;
103+ export function barX ( data , options ) {
104+ return new BarX ( data , options ) ;
125105}
126106
127- export function barY ( data , channels , style ) {
128- return new BarY ( data , channels , style ) ;
107+ export function barY ( data , options ) {
108+ return new BarY ( data , options ) ;
129109}
0 commit comments