@@ -4,7 +4,8 @@ import { ThemingParameters, useStylesheet } from '@ui5/webcomponents-react-base'
44import { clsx } from 'clsx' ;
55import type { CSSProperties } from 'react' ;
66import { forwardRef , useId } from 'react' ;
7- import type { TooltipProps , YAxisProps } from 'recharts' ;
7+ import type { DefaultLegendContentProps , YAxisProps } from 'recharts' ;
8+ import { DefaultLegendContent } from 'recharts' ;
89import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel.js' ;
910import { usePrepareDimensionsAndMeasures } from '../../hooks/usePrepareDimensionsAndMeasures.js' ;
1011import { usePrepareTrendMeasures } from '../../hooks/usePrepareTrendMeasures.js' ;
@@ -51,10 +52,7 @@ interface DimensionConfig extends IChartDimension {
5152}
5253
5354export interface ColumnChartWithTrendProps
54- extends Omit <
55- IChartBaseProps < Omit < ICartesianChartConfig , 'secondYAxis' | 'secondYAxisConfig' > > ,
56- 'syncId' | 'tooltipConfig'
57- > {
55+ extends Omit < IChartBaseProps < Omit < ICartesianChartConfig , 'secondYAxis' | 'secondYAxisConfig' > > , 'syncId' > {
5856 /**
5957 * An array of config objects. Each object will define one dimension of the chart.
6058 *
@@ -101,8 +99,6 @@ const measureDefaults = {
10199 opacity : 1 ,
102100} ;
103101
104- const lineTooltipConfig = { wrapperStyle : { visibility : 'hidden' } } as TooltipProps < any , any > ;
105-
106102// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
107103type AvailableChartTypes = 'line' | 'bar' | string ;
108104/**
@@ -120,12 +116,12 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
120116 onDataPointClick,
121117 onLegendClick,
122118 ChartPlaceholder,
119+ tooltipConfig,
123120 ...rest
124121 } = props ;
125122 const syncId = useId ( ) ;
126123
127124 useStylesheet ( content , ColumnChartWithTrend . displayName ) ;
128-
129125 const chartConfig : ColumnChartWithTrendProps [ 'chartConfig' ] = {
130126 yAxisVisible : false ,
131127 xAxisVisible : true ,
@@ -147,21 +143,8 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
147143 measureDefaults ,
148144 ) ;
149145
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 ) ;
165148
166149 const { chartConfig : _0 , dimensions : _1 , measures : _2 , ...propsWithoutOmitted } = rest ;
167150
@@ -173,7 +156,7 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
173156 typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined ,
174157 classNames . trendContainer ,
175158 ) }
176- tooltipConfig = { lineTooltipConfig }
159+ tooltipConfig = { { ... tooltipConfig , wrapperStyle : { visibility : 'hidden' } } }
177160 noAnimation = { noAnimation }
178161 loading = { loading }
179162 loadingDelay = { loadingDelay }
@@ -201,7 +184,10 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
201184 classNames . chartContainer ,
202185 ) }
203186 onLegendClick = { onLegendClick }
204- tooltipConfig = { columnTooltipConfig }
187+ tooltipConfig = { {
188+ includeHidden : true ,
189+ ...tooltipConfig ,
190+ } }
205191 noAnimation = { noAnimation }
206192 noLegend = { noLegend }
207193 loading = { loading }
@@ -210,10 +196,13 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
210196 onDataPointClick = { onDataPointClick }
211197 syncId = { syncId }
212198 ChartPlaceholder = { ChartPlaceholder ?? ColumnChartWithTrendPlaceholder }
213- dataset = { columnDataset }
199+ dataset = { dataset }
214200 measures = { columnMeasures }
215201 dimensions = { dimensions }
216- chartConfig = { chartConfig }
202+ chartConfig = { {
203+ ...chartConfig ,
204+ legendConfig : { ...chartConfig ?. legendConfig , content : < DefaultLegendContentWithoutInactive /> } ,
205+ } }
217206 />
218207 </ div >
219208 ) ;
@@ -222,3 +211,17 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
222211ColumnChartWithTrend . displayName = 'ColumnChartWithTrend' ;
223212
224213export { 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