@@ -82,11 +82,11 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
8282
8383    // barComponent = canvasDefaultProps.barComponent, 
8484
85-     //  enableLabel = canvasDefaultProps.enableLabel,
86-     //  label = canvasDefaultProps.label,
87-     //  labelSkipWidth = canvasDefaultProps.labelSkipWidth,
88-     //  labelSkipHeight = canvasDefaultProps.labelSkipHeight,
89-     //  labelTextColor = canvasDefaultProps.labelTextColor,
85+     enableLabel =  canvasDefaultProps . enableLabel , 
86+     label =  canvasDefaultProps . label , 
87+     labelSkipWidth =  canvasDefaultProps . labelSkipWidth , 
88+     labelSkipHeight =  canvasDefaultProps . labelSkipHeight , 
89+     labelTextColor =  canvasDefaultProps . labelTextColor , 
9090
9191    // markers, 
9292
@@ -137,8 +137,8 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
137137    const  getBorderColor  =  useInheritedColor < ComputedBarDatum < RawDatum > > ( borderColor ,  theme ) 
138138    const  getColor  =  useOrdinalColorScale ( colors ,  colorBy ) 
139139    const  getIndex  =  usePropertyAccessor ( indexBy ) 
140-     //  const getLabel = usePropertyAccessor(label)
141-     //  const getLabelColor = useInheritedColor<ComputedBarDatum<RawDatum>>(labelTextColor, theme)
140+     const  getLabel  =  usePropertyAccessor ( label ) 
141+     const  getLabelColor  =  useInheritedColor < ComputedBarDatum < RawDatum > > ( labelTextColor ,  theme ) 
142142    const  getTooltipLabel  =  usePropertyAccessor ( tooltipLabel ) 
143143
144144    const  options  =  { 
@@ -173,6 +173,16 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
173173        [ hiddenIds ,  keys ,  result . bars ] 
174174    ) 
175175
176+     const  shouldRenderLabel  =  useCallback ( 
177+         ( {  width,  height } : {  height : number ;  width : number  } )  =>  { 
178+             if  ( ! enableLabel )  return  false 
179+             if  ( labelSkipWidth  >  0  &&  width  <  labelSkipWidth )  return  false 
180+             if  ( labelSkipHeight  >  0  &&  height  <  labelSkipHeight )  return  false 
181+             return  true 
182+         } , 
183+         [ enableLabel ,  labelSkipHeight ,  labelSkipWidth ] 
184+     ) 
185+ 
176186    useEffect ( ( )  =>  { 
177187        const  ctx  =  canvasEl . current ?. getContext ( '2d' ) 
178188
@@ -266,6 +276,13 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
266276            if  ( borderWidth  >  0 )  { 
267277                ctx . stroke ( ) 
268278            } 
279+ 
280+             if  ( shouldRenderLabel ( {  height,  width } ) )  { 
281+                 ctx . textBaseline  =  'middle' 
282+                 ctx . textAlign  =  'center' 
283+                 ctx . fillStyle  =  getLabelColor ( bar ) 
284+                 ctx . fillText ( getLabel ( bar . data ) ,  x  +  width  /  2 ,  y  +  height  /  2 ) 
285+             } 
269286        } ) 
270287
271288        ctx . save ( ) 
@@ -278,6 +295,8 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
278295        enableGridX , 
279296        enableGridY , 
280297        getBorderColor , 
298+         getLabel , 
299+         getLabelColor , 
281300        gridXValues , 
282301        gridYValues , 
283302        groupMode , 
@@ -297,6 +316,7 @@ const InnerBarCanvas = <RawDatum extends BarDatum>({
297316        result . xScale , 
298317        result . yScale , 
299318        reverse , 
319+         shouldRenderLabel , 
300320        theme , 
301321        width , 
302322    ] ) 
0 commit comments