-
Notifications
You must be signed in to change notification settings - Fork 823
Charts: Add standalone Legend component with Chart Context system #44245
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
Draft
annacmc
wants to merge
42
commits into
trunk
Choose a base branch
from
add/charts-50-standalone-legend-component
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+748
−104
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
a3155a6
Add useChartLegendData hook and types for standalone legend component
annacmc 7f488d8
Add ChartLegend standalone component
annacmc eb072e6
Refactor LineChart to use useChartLegendData hook
annacmc 301b80a
Refactor BarChart to use useChartLegendData hook
annacmc 0348c8e
Refactor PieChart and PieSemiCircleChart to use useChartLegendData hook
annacmc 36fe909
Add ChartLegend exports to package API
annacmc f29b9c0
Add comprehensive stories and tests for ChartLegend
annacmc ad3bb4a
changelog
annacmc cf952ea
Fix rebase conflicts and Storybook build errors
f384eb9
Complete ChartLegend component implementation
dbe4296
Add shared validation utilities
annacmc 5da4e04
Add context-aware Legend component
annacmc 266da39
Refactor useChartLegendData hook for better maintainability
annacmc 16b3593
Update Legend component infrastructure
annacmc 6e8dc22
Export ChartContext for direct usage
annacmc efbfd05
Replace duplicated validation with shared utilities
annacmc e786906
Remove separate ChartLegend component
annacmc 0541cde
Update main exports for consolidated legend system
annacmc 53b138d
Add comprehensive Storybook documentation for Legend
annacmc 0ddf4db
Fix linting issues in legend hook
annacmc a41fd43
Revert "Replace duplicated validation with shared utilities"
annacmc d1ff1cc
Revert "Add shared validation utilities"
annacmc 2ee14c3
Fix imports after validation revert
annacmc ff6cf8e
Fix standalone legend reactivity issue
annacmc 385b20d
Fix infinite re-render loop in ChartProvider
annacmc 073be67
Add comprehensive test coverage for Legend component
annacmc 6faf5d8
Fix standalone legend reactivity issue
annacmc 2b8e6da
Fix LineChart to reuse existing ChartProvider context
annacmc f6fda18
Fix PieChart to reuse existing ChartProvider context
annacmc fc3e9b2
Add space between legend label and value
annacmc 71643f6
Fix BarChart to reuse existing ChartProvider context
annacmc 57d4fb1
Fix pie chart container overflow issues
annacmc bacb6c0
Fix showValues default to preserve previous behavior
annacmc 50cc059
Keep necessary lint suppression for useMemo dependencies
annacmc da0a72f
Add comprehensive unit tests for useChartLegendData hook
annacmc 35691cc
Fix TypeScript errors in CI/CD
annacmc 2b9e9e9
add missing tickLength and
annacmc cd05c7b
Revert "add missing tickLength and"
annacmc 1d3463e
Remove test additions to reduce PR size
annacmc 291e343
Complete test file removal for PR size reduction
annacmc 5511c11
Clean up unused imports and variables from HighlightTooltip removal
annacmc 557729d
Fix legend regression caused by removed ChartProvider version state
annacmc 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
4 changes: 4 additions & 0 deletions
4
projects/js-packages/charts/changelog/add-charts-50-standalone-legend-component
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,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Charts: adds a standalone chart legend component |
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,2 +1,5 @@ | ||
export { BaseLegend as Legend } from './base-legend'; | ||
export type { LegendProps } from './types'; | ||
export { Legend } from './legend'; | ||
export { BaseLegend } from './base-legend'; | ||
export { useChartLegendData } from './use-chart-legend-data'; | ||
export type { LegendProps, BaseLegendProps } from './types'; | ||
export type { ChartLegendOptions } from './use-chart-legend-data'; |
24 changes: 24 additions & 0 deletions
24
projects/js-packages/charts/src/components/legend/legend.tsx
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,24 @@ | ||
import { useContext, useMemo } from 'react'; | ||
import { ChartContext } from '../../providers/chart-context/chart-context'; | ||
import { BaseLegend } from './base-legend'; | ||
import type { LegendProps } from './types'; | ||
import type { FC } from 'react'; | ||
|
||
export const Legend: FC< LegendProps > = ( { chartId, items, ...props } ) => { | ||
// Get context but don't throw if it doesn't exist | ||
const context = useContext( ChartContext ); | ||
|
||
// Use useMemo to ensure re-rendering when context changes | ||
const contextItems = useMemo( () => { | ||
return chartId && context ? context.getChartData( chartId )?.legendItems : undefined; | ||
}, [ chartId, context ] ); | ||
|
||
// Use context items if available, otherwise fall back to provided items | ||
const legendItems = ( contextItems || items ) as typeof items; | ||
|
||
if ( ! legendItems ) { | ||
return null; | ||
} | ||
|
||
return <BaseLegend items={ legendItems } { ...props } />; | ||
}; |
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.
The default
showValues
istrue
, which will display number of data points next to each series, differing from the previous blank values. AddshowValues: false
to match existing behavior.Copilot uses AI. Check for mistakes.