@@ -4,7 +4,8 @@ import { ThemingParameters, useStylesheet } from '@ui5/webcomponents-react-base'
4
4
import { clsx } from 'clsx' ;
5
5
import type { CSSProperties } from 'react' ;
6
6
import { forwardRef , useId } from 'react' ;
7
- import type { TooltipProps , YAxisProps } from 'recharts' ;
7
+ import type { DefaultLegendContentProps , YAxisProps } from 'recharts' ;
8
+ import { DefaultLegendContent } from 'recharts' ;
8
9
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel.js' ;
9
10
import { usePrepareDimensionsAndMeasures } from '../../hooks/usePrepareDimensionsAndMeasures.js' ;
10
11
import { usePrepareTrendMeasures } from '../../hooks/usePrepareTrendMeasures.js' ;
@@ -51,10 +52,7 @@ interface DimensionConfig extends IChartDimension {
51
52
}
52
53
53
54
export interface ColumnChartWithTrendProps
54
- extends Omit <
55
- IChartBaseProps < Omit < ICartesianChartConfig , 'secondYAxis' | 'secondYAxisConfig' > > ,
56
- 'syncId' | 'tooltipConfig'
57
- > {
55
+ extends Omit < IChartBaseProps < Omit < ICartesianChartConfig , 'secondYAxis' | 'secondYAxisConfig' > > , 'syncId' > {
58
56
/**
59
57
* An array of config objects. Each object will define one dimension of the chart.
60
58
*
@@ -101,8 +99,6 @@ const measureDefaults = {
101
99
opacity : 1 ,
102
100
} ;
103
101
104
- const lineTooltipConfig = { wrapperStyle : { visibility : 'hidden' } } as TooltipProps < any , any > ;
105
-
106
102
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
107
103
type AvailableChartTypes = 'line' | 'bar' | string ;
108
104
/**
@@ -120,12 +116,12 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
120
116
onDataPointClick,
121
117
onLegendClick,
122
118
ChartPlaceholder,
119
+ tooltipConfig,
123
120
...rest
124
121
} = props ;
125
122
const syncId = useId ( ) ;
126
123
127
124
useStylesheet ( content , ColumnChartWithTrend . displayName ) ;
128
-
129
125
const chartConfig : ColumnChartWithTrendProps [ 'chartConfig' ] = {
130
126
yAxisVisible : false ,
131
127
xAxisVisible : true ,
@@ -147,21 +143,8 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
147
143
measureDefaults ,
148
144
) ;
149
145
150
- const { lineMeasures, columnMeasures, columnDataset } = usePrepareTrendMeasures ( measures , dataset ) ;
151
- const [ yAxisWidth ] = useLongestYAxisLabel ( columnDataset , columnMeasures , chartConfig . legendPosition ) ;
152
-
153
- const columnTooltipConfig = {
154
- formatter : ( value , name , tooltipProps ) => {
155
- const line = lineMeasures . find (
156
- ( currLine ) => currLine . type === 'line' && currLine . accessor === tooltipProps . dataKey ,
157
- ) ;
158
- if ( line ) {
159
- return line . formatter ( tooltipProps . payload [ `__${ line . accessor } ` ] ) ;
160
- }
161
- const column = columnMeasures . find ( ( currLine ) => currLine . accessor === tooltipProps . dataKey ) ;
162
- return column . formatter ( value , name , tooltipProps ) ;
163
- } ,
164
- } as TooltipProps < any , any > ;
146
+ const { lineMeasures, columnMeasures } = usePrepareTrendMeasures ( measures ) ;
147
+ const [ yAxisWidth ] = useLongestYAxisLabel ( dataset , columnMeasures , chartConfig . legendPosition ) ;
165
148
166
149
const { chartConfig : _0 , dimensions : _1 , measures : _2 , ...propsWithoutOmitted } = rest ;
167
150
@@ -173,7 +156,7 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
173
156
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined ,
174
157
classNames . trendContainer ,
175
158
) }
176
- tooltipConfig = { lineTooltipConfig }
159
+ tooltipConfig = { { ... tooltipConfig , wrapperStyle : { visibility : 'hidden' } } }
177
160
noAnimation = { noAnimation }
178
161
loading = { loading }
179
162
loadingDelay = { loadingDelay }
@@ -201,7 +184,10 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
201
184
classNames . chartContainer ,
202
185
) }
203
186
onLegendClick = { onLegendClick }
204
- tooltipConfig = { columnTooltipConfig }
187
+ tooltipConfig = { {
188
+ includeHidden : true ,
189
+ ...tooltipConfig ,
190
+ } }
205
191
noAnimation = { noAnimation }
206
192
noLegend = { noLegend }
207
193
loading = { loading }
@@ -210,10 +196,13 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
210
196
onDataPointClick = { onDataPointClick }
211
197
syncId = { syncId }
212
198
ChartPlaceholder = { ChartPlaceholder ?? ColumnChartWithTrendPlaceholder }
213
- dataset = { columnDataset }
199
+ dataset = { dataset }
214
200
measures = { columnMeasures }
215
201
dimensions = { dimensions }
216
- chartConfig = { chartConfig }
202
+ chartConfig = { {
203
+ ...chartConfig ,
204
+ legendConfig : { ...chartConfig ?. legendConfig , content : < DefaultLegendContentWithoutInactive /> } ,
205
+ } }
217
206
/>
218
207
</ div >
219
208
) ;
@@ -222,3 +211,17 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
222
211
ColumnChartWithTrend . displayName = 'ColumnChartWithTrend' ;
223
212
224
213
export { ColumnChartWithTrend } ;
214
+
215
+ /**
216
+ * Helper component to always keep legend items interactive.
217
+ * This is required, as otherwise internally hidden measures are greyed out in the Legend.
218
+ */
219
+ const DefaultLegendContentWithoutInactive = ( props : DefaultLegendContentProps ) => {
220
+ const updatedPayload = props . payload . map ( ( item ) => {
221
+ return { ...item , inactive : undefined } ;
222
+ } ) ;
223
+ // @ts -expect-error: Type doesn't seem to allow class components which `DefaultLegendContent` is.
224
+ return < DefaultLegendContent { ...props } payload = { updatedPayload } /> ;
225
+ } ;
226
+
227
+ DefaultLegendContentWithoutInactive . displayName = 'DefaultLegendContentWithoutInactive' ;
0 commit comments