-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[charts] Add barLabel to bar series. Deprecate barLabel in BarPlot.
#20184
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
Merged
bernardobelchior
merged 7 commits into
mui:master
from
bernardobelchior:series-bar-label
Nov 5, 2025
+201
−50
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b283827
[charts] Add `barLabel` to bar series. Deprecate `barLabel` in `BarPl…
bernardobelchior fef2807
Add tests
bernardobelchior a9078ed
Avoid "we"
bernardobelchior 205eba0
Fix bar labels rendering below next series bars
bernardobelchior 3748022
Add tests to BarPlot
bernardobelchior 990f347
Gen static
bernardobelchior 4814fe0
Fix tests
bernardobelchior File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| <BarChart | ||
| xAxis={[{ data: ['group A', 'group B', 'group C'] }]} | ||
| series={[{ data: [4, 3, 5] }, { data: [1, 6, 3] }, { data: [2, 5, 6] }]} | ||
| series={[ | ||
| { data: [4, 3, 5], barLabel: 'value' }, | ||
| { | ||
| data: [1, 6, 3], | ||
| barLabel: (item) => dollarFormatter.format(item.value!), | ||
| }, | ||
| { data: [2, 5, 6] }, | ||
| ]} | ||
| height={300} | ||
| barLabel="value" | ||
| margin={{ left: 0 }} | ||
| yAxis={[{ width: 30 }]} | ||
| /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { screen, createRenderer } from '@mui/internal-test-utils'; | ||
| import * as React from 'react'; | ||
| import { ChartContainer } from '../ChartContainer'; | ||
| import { BarPlot } from './BarPlot'; | ||
|
|
||
| describe('BarPlot', () => { | ||
| const { render } = createRenderer(); | ||
|
|
||
| it('`barLabel` prop works', () => { | ||
| render( | ||
| <ChartContainer | ||
| series={[{ type: 'bar', data: [1] }]} | ||
| width={100} | ||
| height={100} | ||
| xAxis={[{ scaleType: 'band', data: ['A'] }]} | ||
| yAxis={[]} | ||
| > | ||
| <BarPlot barLabel={() => 'Bar label from prop'} /> | ||
| </ChartContainer>, | ||
| ); | ||
|
|
||
| expect(screen.getByText('Bar label from prop')).toBeVisible(); | ||
| }); | ||
|
|
||
| it('prioritizes `barLabel` from series over `barLabel` prop', () => { | ||
| render( | ||
| <ChartContainer | ||
| series={[{ type: 'bar', data: [1], barLabel: () => 'Bar label from series' }]} | ||
| width={100} | ||
| height={100} | ||
| xAxis={[{ scaleType: 'band', data: ['A'] }]} | ||
| yAxis={[]} | ||
| > | ||
| <BarPlot barLabel={() => 'Bar label from prop'} /> | ||
| </ChartContainer>, | ||
| ); | ||
|
|
||
| expect(screen.getByText('Bar label from series')).toBeVisible(); | ||
| }); | ||
|
|
||
| it("defaults to `barLabel` prop when `barLabel` from series isn't defined", () => { | ||
| render( | ||
| <ChartContainer | ||
| series={[ | ||
| { type: 'bar', data: [1] }, | ||
| { type: 'bar', data: [1], barLabel: () => 'Bar label from 2nd series' }, | ||
| ]} | ||
| width={100} | ||
| height={100} | ||
| xAxis={[{ scaleType: 'band', data: ['A'] }]} | ||
| yAxis={[]} | ||
| > | ||
| <BarPlot barLabel={() => 'Bar label from prop'} /> | ||
| </ChartContainer>, | ||
| ); | ||
|
|
||
| expect(screen.getByText('Bar label from prop')).toBeVisible(); | ||
| expect(screen.getByText('Bar label from 2nd series')).toBeVisible(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is to allow composition?
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.
If not, we probably need to have a test for users that are currently passing barLabel in the composition of the
BarPlotThere 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.
No, the goal is to maintain the current API without breaking changes.
We're indirectly testing this through the
BarCharttests that I added. Do you think it makes sense to test it separately for theBarPlot?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.
My point is that we should keep compatibility for users providing this through composition to the BarPlot, so it would be good to have a test of the composition working to ensure we don't create a regression.
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.
Done 👍