Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/charts/src/components/ColumnChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ interface DimensionConfig extends IChartDimension {
}

export interface ColumnChartProps extends IChartBaseProps {
/**
* Alignment of the labels of the data points. Can be one of the following: `"center"`, `"insideTop"`, `"insideTopRight"`, `"insideRight"`, `"insideBottomRight"`, `"insideBottom"`, `"insideBottomLeft"`, `"insideLeft"`, `"insideTopLeft"`
*
* @default 'center'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded position was 'insideTop', but the new default is 'center'. This silently changes rendering for existing users. Please change the default to 'insideTop'.

Suggested change
* @default 'center'
* @default 'insideTop'

*/
alignLabels:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prop should be optional.

Suggested change
alignLabels:
alignLabels?:

| 'center'
| 'insideTop'
| 'insideTopRight'
| 'insideRight'
| 'insideBottomRight'
| 'insideBottom'
| 'insideBottomLeft'
| 'insideLeft'
| 'insideTopLeft';
Comment on lines +83 to +91
Copy link
Copy Markdown
Contributor

@Lukas742 Lukas742 May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is only a pass through implementation of the recharts prop, you can reuse the type here.

import type { LabelProps } from 'recharts';
alignLabels?: LabelProps['position'];

/**
* An array of config objects. Each object will define one dimension of the chart.
*
Expand Down Expand Up @@ -148,6 +163,7 @@ const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) =>
ChartPlaceholder,
syncId,
children,
alignLabels = 'center',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value change. (see comment above)

Suggested change
alignLabels = 'center',
alignLabels = 'insideTop',

...rest
} = props;

Expand Down Expand Up @@ -339,7 +355,7 @@ const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) =>
<LabelList
data={dataset}
valueAccessor={valueAccessor(element.accessor)}
content={<ChartDataLabel config={element} chartType="column" position={'insideTop'} />}
content={<ChartDataLabel config={element} chartType="column" position={alignLabels} />}
/>
{chartConfig.showStackAggregateTotals &&
element.stackId &&
Expand Down
14 changes: 3 additions & 11 deletions packages/charts/src/internal/ChartDataLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ThemingParameters } from '@ui5/webcomponents-react-base/ThemingParameters';
import { createElement } from 'react';
import { Label } from 'recharts';
import type { LabelPosition } from 'recharts/types/component/Label.js';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid deep imports when possible, as they are mostly not considered stable. The import could break if the internal structure of the recharts library changes for example.

import type { LabelProps } from 'recharts';
position?: LabelProps['position'];

import type { IChartMeasure } from '../interfaces/IChartMeasure.js';
import { getTextWidth } from '../internal/Utils.js';

interface CustomDataLabelProps {
config: IChartMeasure;
viewBox?: any;
chartType: 'bar' | 'column' | 'line' | 'radar' | 'pie' | 'area';
position?: string;
position?: LabelPosition;
value?: any;
children?: any;
isBigDataSet?: boolean;
Expand Down Expand Up @@ -41,14 +42,5 @@ export const ChartDataLabel = (props: CustomDataLabelProps) => {
fill = ThemingParameters.sapTextColor; // label is displayed outside of the colored element
}

return (
<Label
viewBox={viewBox}
{...(props as any)}
fill={fill}
stroke={'none'}
content={undefined}
value={formattedLabel}
/>
);
return <Label viewBox={viewBox} {...props} fill={fill} stroke={'none'} content={undefined} value={formattedLabel} />;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pre-existing issue, but since you're already in this file: the old {...(props as any)} hid the fact that config, chartType, isBigDataSet get spread onto <Label>. Now that as any is removed, could you also destructure those out?

const { config, chartType, isBigDataSet, ...labelProps } = props;
return <Label viewBox={viewBox} {...labelProps} fill={fill} stroke={'none'} content={undefined} value={formattedLabel} />;

};
Loading