@@ -7,8 +7,7 @@ import { XAxisTicks } from '@ui5/webcomponents-react-charts/lib/components/XAxis
7
7
import { YAxisTicks } from '@ui5/webcomponents-react-charts/lib/components/YAxisTicks' ;
8
8
import { ChartContainer } from '@ui5/webcomponents-react-charts/lib/next/ChartContainer' ;
9
9
import { useLegendItemClick } from '@ui5/webcomponents-react-charts/lib/useLegendItemClick' ;
10
- import debounce from 'lodash.debounce' ;
11
- import React , { FC , forwardRef , Ref , useCallback , useMemo , useState } from 'react' ;
10
+ import React , { FC , forwardRef , Ref , useCallback , useMemo } from 'react' ;
12
11
import {
13
12
Area ,
14
13
Bar ,
@@ -31,7 +30,7 @@ import { IChartDimension } from '../../interfaces/IChartDimension';
31
30
import { IChartMeasure } from '../../interfaces/IChartMeasure' ;
32
31
import { RechartBaseProps } from '../../interfaces/RechartBaseProps' ;
33
32
import { defaultFormatter } from '../../internal/defaults' ;
34
- import { tickLineConfig , tooltipContentStyle , tooltipFillOpacity , xAxisPadding } from '../../internal/staticProps' ;
33
+ import { tickLineConfig , tooltipContentStyle , tooltipFillOpacity } from '../../internal/staticProps' ;
35
34
36
35
const dimensionDefaults = {
37
36
formatter : defaultFormatter
@@ -103,8 +102,6 @@ enum ChartTypes {
103
102
area = Area
104
103
}
105
104
106
- const BAR_DEFAULT_PADDING = 20 ;
107
-
108
105
type AvailableChartTypes = 'line' | 'bar' | 'area' | string ;
109
106
110
107
/**
@@ -127,9 +124,6 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
127
124
} = props ;
128
125
129
126
const chartRef = useConsolidatedRef < any > ( ref ) ;
130
- const [ currentBarWidth , setCurrentBarWidth ] = useState (
131
- dataset . some ( ( { type } ) => type === 'bar' ) ? BAR_DEFAULT_PADDING : 0
132
- ) ;
133
127
134
128
const chartConfig = useMemo ( ( ) => {
135
129
return {
@@ -166,34 +160,34 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
166
160
( payload , eventOrIndex , event ) => {
167
161
if ( payload . name ) {
168
162
typeof onDataPointClick === 'function' &&
169
- onDataPointClick (
170
- enrichEventWithDetails ( event ?? eventOrIndex , {
171
- value : payload . value . length ? payload . value [ 1 ] - payload . value [ 0 ] : payload . value ,
172
- dataIndex : payload . index ?? eventOrIndex ,
173
- dataKey : payload . value . length
174
- ? Object . keys ( payload ) . filter ( ( key ) =>
175
- payload . value . length
176
- ? payload [ key ] === payload . value [ 1 ] - payload . value [ 0 ]
177
- : payload [ key ] === payload . value && key !== 'value'
178
- ) [ 0 ]
179
- : payload . dataKey ??
180
- Object . keys ( payload ) . find ( ( key ) => payload [ key ] === payload . value && key !== 'value' ) ,
181
- payload : payload . payload
182
- } )
183
- ) ;
163
+ onDataPointClick (
164
+ enrichEventWithDetails ( event ?? eventOrIndex , {
165
+ value : payload . value . length ? payload . value [ 1 ] - payload . value [ 0 ] : payload . value ,
166
+ dataIndex : payload . index ?? eventOrIndex ,
167
+ dataKey : payload . value . length
168
+ ? Object . keys ( payload ) . filter ( ( key ) =>
169
+ payload . value . length
170
+ ? payload [ key ] === payload . value [ 1 ] - payload . value [ 0 ]
171
+ : payload [ key ] === payload . value && key !== 'value'
172
+ ) [ 0 ]
173
+ : payload . dataKey ??
174
+ Object . keys ( payload ) . find ( ( key ) => payload [ key ] === payload . value && key !== 'value' ) ,
175
+ payload : payload . payload
176
+ } )
177
+ ) ;
184
178
} else {
185
179
typeof onDataPointClick === 'function' &&
186
- onDataPointClick (
187
- enrichEventWithDetails (
188
- { } ,
189
- {
190
- value : eventOrIndex . value ,
191
- dataKey : eventOrIndex . dataKey ,
192
- dataIndex : eventOrIndex . index ,
193
- payload : eventOrIndex . payload
194
- }
195
- )
196
- ) ;
180
+ onDataPointClick (
181
+ enrichEventWithDetails (
182
+ { } ,
183
+ {
184
+ value : eventOrIndex . value ,
185
+ dataKey : eventOrIndex . dataKey ,
186
+ dataIndex : eventOrIndex . index ,
187
+ payload : eventOrIndex . payload
188
+ }
189
+ )
190
+ ) ;
197
191
}
198
192
} ,
199
193
[ onDataPointClick ]
@@ -217,30 +211,8 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
217
211
} ;
218
212
219
213
const Placeholder = useCallback ( ( ) => {
220
- return < ComposedChartPlaceholder layout = { layout } measures = { measures } /> ;
214
+ return < ComposedChartPlaceholder layout = { layout } measures = { measures } /> ;
221
215
} , [ layout , measures ] ) ;
222
-
223
- const updateChartPadding = useCallback (
224
- debounce ( ( ) => {
225
- if ( chartRef . current ) {
226
- const bars = chartRef . current . querySelectorAll (
227
- '.recharts-bar-rectangles .recharts-bar-rectangle:first-child path'
228
- ) ;
229
- if ( bars . length ) {
230
- let totalBarWidth = 0 ;
231
- bars . forEach ( ( bar ) => {
232
- const bBox = bar . getBBox ( ) ;
233
- totalBarWidth += layout === 'vertical' ? bBox . height : bBox . width ;
234
- } ) ;
235
- setCurrentBarWidth ( totalBarWidth ) ;
236
- }
237
- }
238
- } , 50 ) ,
239
- [ chartRef , setCurrentBarWidth , layout , props . dimensions ]
240
- ) ;
241
-
242
- const chartDoesNotContainAnyBars = ! props . measures . some ( ( measure ) => measure . type === 'bar' ) ;
243
-
244
216
return (
245
217
< ChartContainer
246
218
ref = { chartRef }
@@ -259,51 +231,43 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
259
231
stroke = { chartConfig . gridStroke }
260
232
/>
261
233
{ chartConfig . xAxisVisible &&
262
- dimensions . map ( ( dimension , index ) => {
263
- let AxisComponent ;
264
- const axisProps = {
265
- key : dimension . accessor ,
266
- dataKey : dimension . accessor ,
267
- interval : dimension ?. interval ?? ( isBigDataSet ? 'preserveStart' : 0 ) ,
268
- tickLine : index < 1 ,
269
- axisLine : index < 1 ,
270
- allowDuplicatedCategory : index === 0
271
- } ;
272
-
273
- if ( layout === 'vertical' ) {
274
- axisProps . type = 'category' ;
275
- axisProps . tick = < YAxisTicks config = { dimension } /> ;
276
- axisProps . yAxisId = index ;
277
- axisProps . padding = { top : currentBarWidth , bottom : currentBarWidth } ;
278
- axisProps . width = yAxisWidth ;
279
- AxisComponent = YAxis ;
280
- } else {
281
- axisProps . dataKey = dimension . accessor ;
282
- axisProps . tick = < XAxisTicks config = { dimension } /> ;
283
- axisProps . xAxisId = index ;
284
- if ( chartDoesNotContainAnyBars ) {
285
- axisProps . padding = xAxisPadding ;
286
- } else {
287
- axisProps . padding = { left : currentBarWidth , right : currentBarWidth } ;
288
- }
234
+ dimensions . map ( ( dimension , index ) => {
235
+ let AxisComponent ;
236
+ const axisProps : any = {
237
+ dataKey : dimension . accessor ,
238
+ interval : dimension ?. interval ?? ( isBigDataSet ? 'preserveStart' : 0 ) ,
239
+ tickLine : index < 1 ,
240
+ axisLine : index < 1 ,
241
+ allowDuplicatedCategory : index === 0 ,
242
+ scale : dimensions . length === 1 ? 'band' : 'auto'
243
+ } ;
289
244
290
- axisProps . height = xAxisHeights [ index ] ;
291
- // axisProps.height = 100
292
- AxisComponent = XAxis ;
293
- }
245
+ if ( layout === 'vertical' ) {
246
+ axisProps . type = 'category' ;
247
+ axisProps . tick = < YAxisTicks config = { dimension } /> ;
248
+ axisProps . yAxisId = index ;
249
+ axisProps . width = yAxisWidth ;
250
+ AxisComponent = YAxis ;
251
+ } else {
252
+ axisProps . dataKey = dimension . accessor ;
253
+ axisProps . tick = < XAxisTicks config = { dimension } /> ;
254
+ axisProps . xAxisId = index ;
255
+ axisProps . height = xAxisHeights [ index ] ;
256
+ AxisComponent = XAxis ;
257
+ }
294
258
295
- return < AxisComponent { ...axisProps } /> ;
296
- } ) }
259
+ return < AxisComponent key = { dimension . accessor } { ...axisProps } /> ;
260
+ } ) }
297
261
{ layout === 'horizontal' && (
298
262
< YAxis
299
263
{ ...measureAxisProps }
300
264
yAxisId = "primary"
301
265
width = { yAxisWidth }
302
- tick = { < YAxisTicks config = { primaryMeasure } /> }
266
+ tick = { < YAxisTicks config = { primaryMeasure } /> }
303
267
/>
304
268
) }
305
269
{ layout === 'vertical' && (
306
- < XAxis { ...measureAxisProps } xAxisId = "primary" type = "number" tick = { < XAxisTicks config = { primaryMeasure } /> } />
270
+ < XAxis { ...measureAxisProps } xAxisId = "primary" type = "number" tick = { < XAxisTicks config = { primaryMeasure } /> } />
307
271
) }
308
272
309
273
{ chartConfig . secondYAxis ?. dataKey && layout === 'horizontal' && (
@@ -337,7 +301,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
337
301
xAxisId = { layout === 'vertical' ? 'primary' : undefined }
338
302
/>
339
303
) }
340
- < Tooltip cursor = { tooltipFillOpacity } formatter = { tooltipValueFormatter } contentStyle = { tooltipContentStyle } />
304
+ < Tooltip cursor = { tooltipFillOpacity } formatter = { tooltipValueFormatter } contentStyle = { tooltipContentStyle } />
341
305
{ ! noLegend && (
342
306
< Legend
343
307
verticalAlign = { chartConfig . legendPosition }
@@ -350,7 +314,6 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
350
314
const ChartElement = ( ChartTypes [ element . type ] as any ) as FC < any > ;
351
315
352
316
const chartElementProps : any = {
353
- onAnimationEnd : updateChartPadding ,
354
317
isAnimationActive : noAnimation === false
355
318
} ;
356
319
let labelPosition = 'top' ;
@@ -376,7 +339,6 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
376
339
} else {
377
340
labelPosition = 'insideTop' ;
378
341
}
379
- chartElementProps . maxBarSize = 40 ;
380
342
break ;
381
343
case 'area' :
382
344
chartElementProps . dot = ! isBigDataSet ;
@@ -398,7 +360,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
398
360
name = { element . label ?? element . accessor }
399
361
label = {
400
362
isBigDataSet ? null : (
401
- < ChartDataLabel config = { element } chartType = { element . type } position = { labelPosition } />
363
+ < ChartDataLabel config = { element } chartType = { element . type } position = { labelPosition } />
402
364
)
403
365
}
404
366
stroke = { element . color ?? `var(--sapChart_OrderedColor_${ ( index % 11 ) + 1 } )` }
0 commit comments