Skip to content

Commit 39a056e

Browse files
authored
feat(Line- & BulletChart): allow showing data labels for large datasets (#8150)
Closes #8148 Per default for `LineChart` and `BulletChart` (and the respective implementation in the `ComposedChart`) with many data points, the labels for the points are hidden. Setting `hideDataLabel: false` will now allow showing them again.
1 parent e647d41 commit 39a056e

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

packages/charts/src/components/BulletChart/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,12 @@ const BulletChart = forwardRef<HTMLDivElement, BulletChartProps>((props, ref) =>
479479
key={element.reactKey}
480480
name={element.label ?? element.accessor}
481481
label={
482-
isBigDataSet ? null : <ChartDataLabel config={element} chartType={'bar'} position={labelPosition} />
482+
<ChartDataLabel
483+
config={element}
484+
chartType={'bar'}
485+
position={labelPosition}
486+
isBigDataSet={isBigDataSet}
487+
/>
483488
}
484489
stroke={element.color ?? `var(--sapChart_OrderedColor_${(index % 12) + 1})`}
485490
fill={element.color ?? `var(--sapChart_OrderedColor_${(index % 12) + 1})`}

packages/charts/src/components/ComposedChart/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,13 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
492492
key={element.reactKey}
493493
name={element.label ?? element.accessor}
494494
label={
495-
element.type === 'bar' || isBigDataSet ? undefined : (
496-
<ChartDataLabel config={element} chartType={element.type} position={labelPosition} />
495+
element.type === 'bar' ? undefined : (
496+
<ChartDataLabel
497+
config={element}
498+
chartType={element.type}
499+
position={labelPosition}
500+
isBigDataSet={isBigDataSet}
501+
/>
497502
)
498503
}
499504
stroke={element.color ?? `var(--sapChart_OrderedColor_${(index % 12) + 1})`}

packages/charts/src/components/LineChart/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
305305
key={element.reactKey}
306306
name={element.label ?? element.accessor}
307307
strokeOpacity={element.opacity}
308-
label={isBigDataSet ? false : <ChartDataLabel config={element} chartType="line" position="top" />}
308+
label={<ChartDataLabel config={element} chartType="line" position="top" isBigDataSet={isBigDataSet} />}
309309
type="monotone"
310310
dataKey={element.accessor}
311311
stroke={element.color ?? `var(--sapChart_OrderedColor_${(index % 12) + 1})`}

packages/charts/src/internal/ChartDataLabel.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ interface CustomDataLabelProps {
1111
position?: string;
1212
value?: any;
1313
children?: any;
14+
isBigDataSet?: boolean;
1415
}
1516

1617
export const ChartDataLabel = (props: CustomDataLabelProps) => {
17-
const { config, chartType, viewBox } = props;
18-
if (config.hideDataLabel) {
18+
const { config, chartType, viewBox, isBigDataSet } = props;
19+
const hideLabel = config.hideDataLabel !== false && (isBigDataSet || config.hideDataLabel || props.value == null);
20+
21+
if (hideLabel) {
1922
return null;
2023
}
2124

0 commit comments

Comments
 (0)