-
Notifications
You must be signed in to change notification settings - Fork 113
feat(ColumnChart): add alignLabels property #8534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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' | ||||||
| */ | ||||||
| alignLabels: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prop should be optional.
Suggested change
|
||||||
| | 'center' | ||||||
| | 'insideTop' | ||||||
| | 'insideTopRight' | ||||||
| | 'insideRight' | ||||||
| | 'insideBottomRight' | ||||||
| | 'insideBottom' | ||||||
| | 'insideBottomLeft' | ||||||
| | 'insideLeft' | ||||||
| | 'insideTopLeft'; | ||||||
|
Comment on lines
+83
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is only a pass through implementation of the |
||||||
| /** | ||||||
| * An array of config objects. Each object will define one dimension of the chart. | ||||||
| * | ||||||
|
|
@@ -148,6 +163,7 @@ const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) => | |||||
| ChartPlaceholder, | ||||||
| syncId, | ||||||
| children, | ||||||
| alignLabels = 'center', | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default value change. (see comment above)
Suggested change
|
||||||
| ...rest | ||||||
| } = props; | ||||||
|
|
||||||
|
|
@@ -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 && | ||||||
|
|
||||||
| 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'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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; | ||
|
|
@@ -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} />; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 const { config, chartType, isBigDataSet, ...labelProps } = props;
return <Label viewBox={viewBox} {...labelProps} fill={fill} stroke={'none'} content={undefined} value={formattedLabel} />; |
||
| }; | ||
There was a problem hiding this comment.
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'.