LabelList uses React context instead of reading DOM#6246
Conversation
There was a problem hiding this comment.
Now uses fill color instead of stroke, to be consistent with other chart behaviour. We can change this back if we want.
There was a problem hiding this comment.
Order changed, now labels are below the dot. We can change this with Portals but perhaps this is fine - I assume everyone will choose different positions to prevent overlapping labels anyway?
There was a problem hiding this comment.
Pie label has special behaviour, with the little label line on each label. This is the same in this PR (and recorded in multiple storybook snapshots).
If a label however has explicit position set then the LabelList takes over which is what we are seeing here.
Some labels render inside but because they inherit the same fill color as the Pie we can't see them.
| dataKey="uv" | ||
| fill="none" | ||
| stroke="green" | ||
| // @ts-expect-error typescript type says that valueAccessor is not a valid prop, but it does work |
There was a problem hiding this comment.
Fixed type bug
|
|
||
| const expectedUvLabels: ReadonlyArray<ExpectedLabel> = [ | ||
| { | ||
| height: null, |
There was a problem hiding this comment.
width and height don't do anything in text SVG element, we should remove them.
| it('should hide labels during the animation', async () => { | ||
| const { container, animationManager } = renderTestCase(); | ||
|
|
||
| return expectLabelsRemainVisible(container, animationManager); |
There was a problem hiding this comment.
This test was wrong - expects labels to hide, but tests that they are visible? Fixed.
| }; | ||
|
|
||
| render( | ||
| const { debug } = render( |
There was a problem hiding this comment.
I should remove this.
| /* | ||
| * The labels should still be hidden! But all labels now appear again. | ||
| * Why? Because the animation is not started yet, but they swap to new label values immediately. | ||
| * Unfortunately the labels still show at the old position so we have a flash of new labels at the old position. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6246 +/- ##
==========================================
- Coverage 96.63% 96.61% -0.03%
==========================================
Files 221 221
Lines 19898 20125 +227
Branches 4093 4110 +17
==========================================
+ Hits 19229 19443 +214
- Misses 663 675 +12
- Partials 6 7 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 18.66kB (0.78%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
|
| payload: point.payload, | ||
| viewBox, | ||
| /* | ||
| * Line is not passing parentViewBox to the LabelList so the labels can escape - looks like a bug, should we pass parentViewBox? |
There was a problem hiding this comment.
Does anything bad happen if we do?
There was a problem hiding this comment.
If we add parent view box then that should push labels back into the viewbox if they are peeking out. I haven't tested it though.
| ); | ||
| } | ||
|
|
||
| function ScatterLabelListProvider({ |
There was a problem hiding this comment.
I'm not sure I like that labels are now below points for scatter. Feel like words should always render on top even if both are bad. People like to render large z scatter items and then put text in those
Also why is it below for scatter but not for other charts?
There was a problem hiding this comment.
Because they are rendered together with error bars and error bars are better looking under points.
Proper fix would be portals, then we could have error bars below and labels on top.
Different default for label positions would help too.
There was a problem hiding this comment.
Ah yeah. Another thing I suppose
| * Radar provides a Cartesian label list context. Do we want to also provide a polar label list context? | ||
| * That way, users can choose to use polar positions for the Radar labels. | ||
| */ | ||
| // const labelListEntries: ReadonlyArray<PolarLabelListEntry> = points.map( |
There was a problem hiding this comment.
I think that Radar being a polar chart should also support polar label positions, so I propose to pass both viewboxes and then use one or the other depending on the position? I didn't do this here because the PR is already large enough.
| } | ||
| state[itemId].push(errorBar); | ||
| }, | ||
| replaceErrorBar: ( |
There was a problem hiding this comment.
did adding this do something for labels or fix something else?
There was a problem hiding this comment.
Fixed infinite rerender loop. Error bars and label lists are in the same {children}
Description
Switched LabelList from renderCallByParent (which was reading DOM nodes and parsing props from them) into React context.
Some visual diff in Storybook:
Related Issue
Fixes #6215
#5768
Motivation and Context
Removed one more usage of findChildrenByType - now only Cell is remaining, and then we can delete react-is dependency completely.
Types of changes
Checklist: