diff --git a/packages/charts/src/components/BarChart/index.tsx b/packages/charts/src/components/BarChart/index.tsx index c206dd66364..4c9835d62eb 100644 --- a/packages/charts/src/components/BarChart/index.tsx +++ b/packages/charts/src/components/BarChart/index.tsx @@ -18,7 +18,7 @@ import { XAxis, YAxis, } from 'recharts'; -import type { YAxisProps } from 'recharts'; +import type { LabelProps, YAxisProps } from 'recharts'; import { getValueByDataKey } from 'recharts/lib/util/ChartUtils.js'; import { useCancelAnimationFallback } from '../../hooks/useCancelAnimationFallback.js'; import { useChartMargin } from '../../hooks/useChartMargin.js'; @@ -91,6 +91,12 @@ interface DimensionConfig extends IChartDimension { } export interface BarChartProps extends IChartBaseProps { + /** + * Alignment of the labels of the data points. + * + * @default 'insideRight' + */ + alignLabels?: LabelProps['position']; /** * An array of config objects. Each object will define one dimension of the chart. * @@ -150,6 +156,7 @@ const BarChart = forwardRef((props, ref) => { syncId, ChartPlaceholder, children, + alignLabels = 'insideRight', ...rest } = props; @@ -344,7 +351,7 @@ const BarChart = forwardRef((props, ref) => { } + content={} /> {chartConfig.showStackAggregateTotals && element.stackId && diff --git a/packages/charts/src/components/BulletChart/index.tsx b/packages/charts/src/components/BulletChart/index.tsx index b64f9c0cf58..08a7af81b05 100644 --- a/packages/charts/src/components/BulletChart/index.tsx +++ b/packages/charts/src/components/BulletChart/index.tsx @@ -17,7 +17,7 @@ import { XAxis, YAxis, } from 'recharts'; -import type { YAxisProps } from 'recharts'; +import type { LabelProps, YAxisProps } from 'recharts'; import { useChartMargin } from '../../hooks/useChartMargin.js'; import { useLabelFormatter } from '../../hooks/useLabelFormatter.js'; import { useLegendItemClick } from '../../hooks/useLegendItemClick.js'; @@ -441,7 +441,7 @@ const BulletChart = forwardRef((props, ref) => const chartElementProps: any = { isAnimationActive: !noAnimation, }; - let labelPosition = 'top'; + let labelPosition: LabelProps['position'] = 'top'; switch (element.type) { case 'primary': case 'additional': diff --git a/packages/charts/src/components/ColumnChart/index.tsx b/packages/charts/src/components/ColumnChart/index.tsx index bbf0125336a..b37cb87aa29 100644 --- a/packages/charts/src/components/ColumnChart/index.tsx +++ b/packages/charts/src/components/ColumnChart/index.tsx @@ -18,7 +18,7 @@ import { XAxis, YAxis, } from 'recharts'; -import type { YAxisProps } from 'recharts'; +import type { LabelProps, YAxisProps } from 'recharts'; import { getValueByDataKey } from 'recharts/lib/util/ChartUtils.js'; import { useCancelAnimationFallback } from '../../hooks/useCancelAnimationFallback.js'; import { useChartMargin } from '../../hooks/useChartMargin.js'; @@ -74,6 +74,12 @@ interface DimensionConfig extends IChartDimension { } export interface ColumnChartProps extends IChartBaseProps { + /** + * Alignment of the labels of the data points. + * + * @default 'insideTop' + */ + alignLabels?: LabelProps['position']; /** * An array of config objects. Each object will define one dimension of the chart. * @@ -148,6 +154,7 @@ const ColumnChart = forwardRef((props, ref) => ChartPlaceholder, syncId, children, + alignLabels = 'insideTop', ...rest } = props; @@ -339,7 +346,7 @@ const ColumnChart = forwardRef((props, ref) => } + content={} /> {chartConfig.showStackAggregateTotals && element.stackId && diff --git a/packages/charts/src/components/ComposedChart/index.tsx b/packages/charts/src/components/ComposedChart/index.tsx index 29c1910a2af..d85a86b53b1 100644 --- a/packages/charts/src/components/ComposedChart/index.tsx +++ b/packages/charts/src/components/ComposedChart/index.tsx @@ -20,7 +20,7 @@ import { XAxis, YAxis, } from 'recharts'; -import type { YAxisProps } from 'recharts'; +import type { LabelProps, YAxisProps } from 'recharts'; import { getValueByDataKey } from 'recharts/lib/util/ChartUtils.js'; import { useChartMargin } from '../../hooks/useChartMargin.js'; import { useLabelFormatter } from '../../hooks/useLabelFormatter.js'; @@ -462,7 +462,7 @@ const ComposedChart = forwardRef((props, ref const chartElementProps: any = { isAnimationActive: !noAnimation, }; - let labelPosition = 'top'; + let labelPosition: LabelProps['position'] = 'top'; switch (element.type) { case 'line': diff --git a/packages/charts/src/internal/ChartDataLabel.tsx b/packages/charts/src/internal/ChartDataLabel.tsx index 337fbf8489f..4802104819e 100644 --- a/packages/charts/src/internal/ChartDataLabel.tsx +++ b/packages/charts/src/internal/ChartDataLabel.tsx @@ -1,6 +1,7 @@ import { ThemingParameters } from '@ui5/webcomponents-react-base/ThemingParameters'; import { createElement } from 'react'; import { Label } from 'recharts'; +import type { LabelProps } from 'recharts'; import type { IChartMeasure } from '../interfaces/IChartMeasure.js'; import { getTextWidth } from '../internal/Utils.js'; @@ -8,14 +9,14 @@ interface CustomDataLabelProps { config: IChartMeasure; viewBox?: any; chartType: 'bar' | 'column' | 'line' | 'radar' | 'pie' | 'area'; - position?: string; + position?: LabelProps['position']; value?: any; children?: any; isBigDataSet?: boolean; } export const ChartDataLabel = (props: CustomDataLabelProps) => { - const { config, chartType, viewBox, isBigDataSet } = props; + const { config, chartType, viewBox, isBigDataSet, ...labelProps } = props; const hideLabel = config.hideDataLabel !== false && (isBigDataSet || config.hideDataLabel || props.value == null); if (hideLabel) { @@ -42,13 +43,6 @@ export const ChartDataLabel = (props: CustomDataLabelProps) => { } return ( -