11import { create } from "d3-selection" ;
22import { identity , indexOf } from "../mark.js" ;
33import { defined } from "../defined.js" ;
4- import { Mark } from "../mark.js" ;
4+ import { Mark , string , number } from "../mark.js" ;
55
66class Bar extends Mark {
77 constructor (
@@ -21,29 +21,26 @@ class Bar extends Mark {
2121 } = { }
2222 ) {
2323 super ( data , channels ) ;
24- this . fill = fill ;
25- this . fillOpacity = fillOpacity ;
26- this . stroke = stroke ;
27- this . strokeWidth = strokeWidth ;
28- this . strokeOpacity = strokeOpacity ;
29- this . mixBlendMode = mixBlendMode ;
30- this . insetTop = insetTop ;
31- this . insetRight = insetRight ;
32- this . insetBottom = insetBottom ;
33- this . insetLeft = insetLeft ;
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 ) ;
30+ this . insetTop = number ( insetTop ) ;
31+ this . insetRight = number ( insetRight ) ;
32+ this . insetBottom = number ( insetBottom ) ;
33+ this . insetLeft = number ( insetLeft ) ;
3434 }
35- render ( I , scales ) {
35+ render ( I , scales , channels ) {
36+ const { x : X , y : Y } = channels ;
3637 const {
3738 fill,
3839 fillOpacity,
3940 stroke,
4041 strokeWidth,
4142 strokeOpacity,
42- mixBlendMode,
43- channels : {
44- x : { value : X } ,
45- y : { value : Y }
46- }
43+ mixBlendMode
4744 } = this ;
4845 return create ( "svg:g" )
4946 . attr ( "fill" , fill )
@@ -55,10 +52,10 @@ class Bar extends Mark {
5552 . data ( I . filter ( i => defined ( X [ i ] ) && defined ( Y [ i ] ) ) )
5653 . join ( "rect" )
5754 . style ( "mix-blend-mode" , mixBlendMode )
58- . attr ( "x" , this . _x ( scales ) )
59- . attr ( "width" , this . _width ( scales ) )
60- . attr ( "y" , this . _y ( scales ) )
61- . attr ( "height" , this . _height ( scales ) ) )
55+ . attr ( "x" , this . _x ( scales , channels ) )
56+ . attr ( "width" , this . _width ( scales , channels ) )
57+ . attr ( "y" , this . _y ( scales , channels ) )
58+ . attr ( "height" , this . _height ( scales , channels ) ) )
6259 . node ( ) ;
6360 }
6461}
@@ -75,19 +72,19 @@ export class BarX extends Bar {
7572 style
7673 ) ;
7774 }
78- _x ( { x : { scale : x } } ) {
79- const { insetLeft, channels : { x : { value : X } } } = this ;
75+ _x ( { x} , { x : X } ) {
76+ const { insetLeft} = this ;
8077 return i => Math . min ( x ( 0 ) , x ( X [ i ] ) ) + insetLeft ;
8178 }
82- _y ( { y : { scale : y } } ) {
83- const { insetTop, channels : { y : { value : Y } } } = this ;
79+ _y ( { y} , { y : Y } ) {
80+ const { insetTop} = this ;
8481 return i => y ( Y [ i ] ) + insetTop ;
8582 }
86- _width ( { x : { scale : x } } ) {
87- const { insetLeft, insetRight, channels : { x : { value : X } } } = this ;
83+ _width ( { x} , { x : X } ) {
84+ const { insetLeft, insetRight} = this ;
8885 return i => Math . max ( 0 , Math . abs ( x ( X [ i ] ) - x ( 0 ) ) - insetLeft - insetRight ) ;
8986 }
90- _height ( { y : { scale : y } } ) {
87+ _height ( { y} ) {
9188 const { insetTop, insetBottom} = this ;
9289 return Math . max ( 0 , y . bandwidth ( ) - insetTop - insetBottom ) ;
9390 }
@@ -105,20 +102,20 @@ export class BarY extends Bar {
105102 style
106103 ) ;
107104 }
108- _x ( { x : { scale : x } } ) {
109- const { insetLeft, channels : { x : { value : X } } } = this ;
105+ _x ( { x} , { x : X } ) {
106+ const { insetLeft} = this ;
110107 return i => x ( X [ i ] ) + insetLeft ;
111108 }
112- _y ( { y : { scale : y } } ) {
113- const { insetTop, channels : { y : { value : Y } } } = this ;
109+ _y ( { y} , { y : Y } ) {
110+ const { insetTop} = this ;
114111 return i => Math . min ( y ( 0 ) , y ( Y [ i ] ) ) + insetTop ;
115112 }
116- _width ( { x : { scale : x } } ) {
113+ _width ( { x} ) {
117114 const { insetLeft, insetRight} = this ;
118115 return Math . max ( 0 , x . bandwidth ( ) - insetLeft - insetRight ) ;
119116 }
120- _height ( { y : { scale : y } } ) {
121- const { insetTop, insetBottom, channels : { y : { value : Y } } } = this ;
117+ _height ( { y} , { y : Y } ) {
118+ const { insetTop, insetBottom} = this ;
122119 return i => Math . max ( 0 , Math . abs ( y ( 0 ) - y ( Y [ i ] ) ) - insetTop - insetBottom ) ;
123120 }
124121}
0 commit comments