@@ -7,7 +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 React , { FC , forwardRef , Ref , useCallback , useState } from 'react' ;
10
+ import React , { FC , forwardRef , Ref , useCallback , useState , useMemo } from 'react' ;
11
11
import {
12
12
Area ,
13
13
Bar ,
@@ -28,7 +28,7 @@ import { useTooltipFormatter } from '../../hooks/useTooltipFormatter';
28
28
import { IChartDimension } from '../../interfaces/IChartDimension' ;
29
29
import { IChartMeasure } from '../../interfaces/IChartMeasure' ;
30
30
import { RechartBaseProps } from '../../interfaces/RechartBaseProps' ;
31
- import { tickLineConfig , tooltipContentStyle } from '../../internal/staticProps' ;
31
+ import { tickLineConfig , tooltipContentStyle , tooltipFillOpacity } from '../../internal/staticProps' ;
32
32
33
33
const dimensionDefaults = {
34
34
formatter : ( d ) => d
@@ -116,29 +116,6 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
116
116
noLegend = false ,
117
117
onLegendClick,
118
118
layout = 'horizontal' ,
119
- chartConfig = {
120
- margin : { } ,
121
- yAxisVisible : false ,
122
- xAxisVisible : true ,
123
- gridStroke : ThemingParameters . sapList_BorderColor ,
124
- gridHorizontal : true ,
125
- gridVertical : false ,
126
- yAxisId : '' ,
127
- yAxisColor : ThemingParameters . sapList_BorderColor ,
128
- legendPosition : 'top' ,
129
- zoomingTool : false ,
130
- barGap : undefined ,
131
- referenceLine : {
132
- label : undefined ,
133
- value : undefined ,
134
- color : undefined
135
- } ,
136
- secondYAxis : {
137
- name : undefined ,
138
- dataKey : undefined ,
139
- color : undefined
140
- }
141
- } ,
142
119
style,
143
120
className,
144
121
tooltip,
@@ -150,6 +127,19 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
150
127
dataset . some ( ( { type } ) => type === 'bar' ) ? BAR_DEFAULT_PADDING : 0
151
128
) ;
152
129
130
+ const chartConfig = useMemo ( ( ) => {
131
+ return {
132
+ yAxisVisible : false ,
133
+ xAxisVisible : true ,
134
+ gridStroke : ThemingParameters . sapList_BorderColor ,
135
+ gridHorizontal : true ,
136
+ gridVertical : false ,
137
+ legendPosition : 'top' ,
138
+ zoomingTool : false ,
139
+ ...props . chartConfig
140
+ } ;
141
+ } , [ props . chartConfig ] ) ;
142
+
153
143
const { dimensions, measures } = usePrepareDimensionsAndMeasures (
154
144
props . dimensions ,
155
145
props . measures ,
@@ -164,7 +154,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
164
154
165
155
const dataKeys = measures . map ( ( { accessor } ) => accessor ) ;
166
156
const colorSecondY = chartConfig . secondYAxis
167
- ? dataKeys . findIndex ( ( key ) => key === chartConfig . secondYAxis . dataKey )
157
+ ? dataKeys . findIndex ( ( key ) => key === chartConfig . secondYAxis ? .dataKey )
168
158
: 0 ;
169
159
170
160
const onDataPointClickInternal = useCallback (
@@ -217,7 +207,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
217
207
) ;
218
208
219
209
const measureAxisProps = {
220
- axisLine : chartConfig . yAxisVisible ?? false ,
210
+ axisLine : chartConfig . yAxisVisible ,
221
211
tickLine : tickLineConfig ,
222
212
tickFormatter : primaryMeasure ?. formatter ,
223
213
interval : 0
@@ -259,11 +249,11 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
259
249
>
260
250
< ComposedChartLib margin = { marginChart } data = { dataset } layout = { layout } >
261
251
< CartesianGrid
262
- vertical = { chartConfig . gridVertical ?? false }
252
+ vertical = { chartConfig . gridVertical }
263
253
horizontal = { chartConfig . gridHorizontal }
264
- stroke = { chartConfig . gridStroke ?? ThemingParameters . sapList_BorderColor }
254
+ stroke = { chartConfig . gridStroke }
265
255
/>
266
- { ( chartConfig . xAxisVisible ?? true ) &&
256
+ { chartConfig . xAxisVisible &&
267
257
dimensions . map ( ( dimension , index ) => {
268
258
let AxisComponent ;
269
259
const axisProps = {
@@ -302,7 +292,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
302
292
/>
303
293
) }
304
294
305
- { chartConfig . secondYAxis && chartConfig . secondYAxis . dataKey && layout === 'horizontal' && (
295
+ { chartConfig . secondYAxis ? .dataKey && layout === 'horizontal' && (
306
296
< YAxis
307
297
dataKey = { chartConfig . secondYAxis . dataKey }
308
298
stroke = { chartConfig . secondYAxis . color ?? `var(--sapChart_OrderedColor_${ ( colorSecondY % 11 ) + 1 } )` }
@@ -312,7 +302,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
312
302
yAxisId = "secondary"
313
303
/>
314
304
) }
315
- { chartConfig . secondYAxis && chartConfig . secondYAxis . dataKey && layout === 'vertical' && (
305
+ { chartConfig . secondYAxis ? .dataKey && layout === 'vertical' && (
316
306
< XAxis
317
307
dataKey = { chartConfig . secondYAxis . dataKey }
318
308
stroke = { chartConfig . secondYAxis . color ?? `var(--sapChart_OrderedColor_${ ( colorSecondY % 11 ) + 1 } )` }
@@ -333,8 +323,8 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
333
323
xAxisId = { layout === 'vertical' ? 'primary' : undefined }
334
324
/>
335
325
) }
336
- < Tooltip cursor = { { fillOpacity : 0.3 } } formatter = { tooltipValueFormatter } contentStyle = { tooltipContentStyle } />
337
- { ! noLegend && < Legend verticalAlign = { chartConfig . legendPosition ?? 'top' } onClick = { onItemLegendClick } /> }
326
+ < Tooltip cursor = { tooltipFillOpacity } formatter = { tooltipValueFormatter } contentStyle = { tooltipContentStyle } />
327
+ { ! noLegend && < Legend verticalAlign = { chartConfig . legendPosition } onClick = { onItemLegendClick } /> }
338
328
{ measures ?. map ( ( element , index ) => {
339
329
const ChartElement = ( ChartTypes [ element . type ] as any ) as FC < any > ;
340
330
@@ -375,11 +365,9 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
375
365
}
376
366
377
367
if ( layout === 'vertical' ) {
378
- chartElementProps . xAxisId =
379
- chartConfig ?. secondYAxis ?. dataKey === element . accessor ? 'secondary' : 'primary' ;
368
+ chartElementProps . xAxisId = chartConfig . secondYAxis ?. dataKey === element . accessor ? 'secondary' : 'primary' ;
380
369
} else {
381
- chartElementProps . yAxisId =
382
- chartConfig ?. secondYAxis ?. dataKey === element . accessor ? 'secondary' : 'primary' ;
370
+ chartElementProps . yAxisId = chartConfig . secondYAxis ?. dataKey === element . accessor ? 'secondary' : 'primary' ;
383
371
}
384
372
return (
385
373
< ChartElement
0 commit comments