@@ -20,11 +20,14 @@ import {
20
20
YAxis
21
21
} from 'recharts' ;
22
22
import { useChartMargin } from '../../hooks/useChartMargin' ;
23
+ import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel' ;
24
+ import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights' ;
23
25
import { usePrepareDimensionsAndMeasures } from '../../hooks/usePrepareDimensionsAndMeasures' ;
24
26
import { useTooltipFormatter } from '../../hooks/useTooltipFormatter' ;
25
27
import { IChartDimension } from '../../interfaces/IChartDimension' ;
26
28
import { IChartMeasure } from '../../interfaces/IChartMeasure' ;
27
29
import { RechartBaseProps } from '../../interfaces/RechartBaseProps' ;
30
+ import { defaultFormatter } from '../../internal/defaults' ;
28
31
import { tickLineConfig , tooltipContentStyle , tooltipFillOpacity } from '../../internal/staticProps' ;
29
32
30
33
interface MeasureConfig extends IChartMeasure {
@@ -76,11 +79,11 @@ export interface ColumnChartProps extends RechartBaseProps {
76
79
}
77
80
78
81
const dimensionDefaults = {
79
- formatter : ( d ) => d
82
+ formatter : defaultFormatter
80
83
} ;
81
84
82
85
const measureDefaults = {
83
- formatter : ( d ) => d ,
86
+ formatter : defaultFormatter ,
84
87
opacity : 1
85
88
} ;
86
89
@@ -108,7 +111,8 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
108
111
gridStroke : ThemingParameters . sapList_BorderColor ,
109
112
gridHorizontal : true ,
110
113
gridVertical : false ,
111
- legendPosition : 'top' ,
114
+ legendPosition : 'bottom' ,
115
+ legendHorizontalAlign : 'left' ,
112
116
barGap : 3 ,
113
117
zoomingTool : false ,
114
118
...props . chartConfig
@@ -124,6 +128,8 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
124
128
125
129
const tooltipValueFormatter = useTooltipFormatter ( measures ) ;
126
130
131
+ const [ yAxisWidth , legendPosition ] = useLongestYAxisLabel ( dataset , measures ) ;
132
+
127
133
const primaryDimension = dimensions [ 0 ] ;
128
134
const primaryMeasure = measures [ 0 ] ;
129
135
@@ -159,14 +165,8 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
159
165
const isBigDataSet = dataset ?. length > 30 ?? false ;
160
166
const primaryDimensionAccessor = primaryDimension ?. accessor ;
161
167
162
- const marginChart = useChartMargin (
163
- dataset ,
164
- measures ,
165
- chartConfig . margin ,
166
- false ,
167
- dimensions . length > 1 ,
168
- chartConfig . zoomingTool
169
- ) ;
168
+ const marginChart = useChartMargin ( chartConfig . margin , chartConfig . zoomingTool ) ;
169
+ const xAxisHeights = useObserveXAxisHeights ( chartRef , props . dimensions . length ) ;
170
170
171
171
return (
172
172
< ChartContainer
@@ -193,9 +193,10 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
193
193
dataKey = { dimension . accessor }
194
194
xAxisId = { index }
195
195
interval = { dimension ?. interval ?? ( isBigDataSet ? 'preserveStart' : 0 ) }
196
- tick = { < XAxisTicks config = { dimension } chartRef = { chartRef } level = { index } /> }
196
+ tick = { < XAxisTicks config = { dimension } level = { index } /> }
197
197
tickLine = { index < 1 }
198
198
axisLine = { index < 1 }
199
+ height = { xAxisHeights [ index ] }
199
200
/>
200
201
) ;
201
202
} ) }
@@ -205,6 +206,7 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
205
206
yAxisId = "left"
206
207
interval = { 0 }
207
208
tick = { < YAxisTicks config = { primaryMeasure } /> }
209
+ width = { yAxisWidth }
208
210
/>
209
211
{ chartConfig . secondYAxis ?. dataKey && (
210
212
< YAxis
@@ -235,7 +237,14 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
235
237
/>
236
238
) ;
237
239
} ) }
238
- { ! noLegend && < Legend verticalAlign = { chartConfig . legendPosition } onClick = { onItemLegendClick } /> }
240
+ { ! noLegend && (
241
+ < Legend
242
+ verticalAlign = { chartConfig . legendPosition }
243
+ align = { chartConfig . legendHorizontalAlign }
244
+ onClick = { onItemLegendClick }
245
+ wrapperStyle = { legendPosition }
246
+ />
247
+ ) }
239
248
{ chartConfig . referenceLine && (
240
249
< ReferenceLine
241
250
stroke = { chartConfig . referenceLine . color }
0 commit comments