-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[@mantine/charts] Add yAxisId="left" to each <CartesianGrid> #8121
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
[@mantine/charts] Add yAxisId="left" to each <CartesianGrid> #8121
Conversation
|
Please fix errors in tests |
|
So the problem is |
|
If there is a reliable way of differentiating those versions, then it should be used. Otherwise, I think it is better to introduce these changes in 9.0 version planned for the next year. |
|
I think this check would work: import * as Recharts from 'recharts';
function isRechartsV3() {
return typeof (Recharts as any).useActiveTooltipLabel === 'function';
}
<CartesianGrid
strokeDasharray={strokeDasharray}
vertical={gridAxis === 'y' || gridAxis === 'xy'}
horizontal={gridAxis === 'x' || gridAxis === 'xy'}
{...(isRechartsV3() && { yAxisId: 'left' })}
{...getStyles('grid')}
{...gridProps}
/>I don't know how you feel about adding the |
|
Used detection of |
|
Thanks for the quick fix and the helpful context from the Recharts 3 migration guide! A few suggestions and potential issues to consider:
Overall, the change looks good and aligns with the v3 requirement. Addressing the right-only axis case and deduping the version check would polish it nicely. |
|
|
Ignored number 1 based on the request by @rtivital to avoid calculations. Ignored number 2 because it should be completely unnecessary. Did number 3. Did number 4. Per number 5, added docs notes anywhere changing the yAxisId of the series was mentioned in the docs. If the lightweight unit test is deemed necessary, I'd like help writing it. Otherwise, this should be ready for re-review. |
|
Made a test for this, I'm checking the return of |
|
This PR should be ready for re-review. |
|
Well, the test worked locally with the import, but I guess with the CI build it didn't work to mock recharts, I think the update should let the test work. |
4780572 to
e87bc52
Compare
e87bc52 to
137db1d
Compare
|
Came back to this with a fresh mind a week later, https://jestjs.io/docs/jest-object#jestisolatemodulesasyncfn proved to be the function I needed so the installed recharts version wouldn't interfere with my mock in the test. Edit: I guess I still need the |
|
...I swear I'm testing my changes locally, and locally they usually work. I have no idea what the difference is in CI. |
|
Created this shell script, ran it a few times with my old code, and #!/usr/bin/env bash
set -euo pipefail
echo "🔹 Removing node_modules..."
rm -rf node_modules
echo "🔹 Clearing Yarn cache..."
rm -rf ~/.cache/yarn
echo "🔹 Cleaning build artifacts (esm, cjs, styles.css)..."
find packages -type d -name esm -exec rm -rf {} +
find packages -type d -name cjs -exec rm -rf {} +
find packages -type f -name styles.css -delete
echo "🔹 Installing dependencies..."
yarn install --frozen-lockfile
echo "🔹 Running setup..."
npm run setup
echo "🔹 Building packages..."
npm run build all
echo "🔹 Running tests..."
CI=true npm testWith my new code, I ran that script 5 times and |
|
Darn, no luck with CI... |
e8cc1b1 to
232afd3
Compare
|
Ok, I'm fairly sure there's no good way to fix the test because the tests run in parallel. As such, if a test that imports the real recharts runs concurrently with this test file, the real recharts may be taken into account instead of the mocked recharts. |
6ac1646 to
52996cd
Compare
|
I wouldn't trust the latest CI success, it was still flaky for me locally. |
|
Ran this on the current PR: #!/usr/bin/env bash
set -euo pipefail
SUCCESS=0
FAIL=0
for i in {1..5}; do
echo "========================================"
echo "▶️ Run $i of 5"
echo "========================================"
if ./ci-clean-test.sh; then
echo "✅ Run $i succeeded"
SUCCESS=$((SUCCESS + 1))
else
echo "❌ Run $i failed"
FAIL=$((FAIL + 1))
fi
done
echo "========================================"
echo "Summary:"
echo " Successes: $SUCCESS"
echo " Failures : $FAIL"
echo "========================================"
# Exit with failure if any run failed
if [ "$FAIL" -gt 0 ]; then
exit 1
fiUnfortunately: |
|
I think I'll keep it as is for now and wait for Mantine 9.0 to introduce recharts 3 only version. |
|
Thanks for submitting the PR and your research work. Today, I've integrated these changes in 9.0 release which supports recharts 3 only. Currently, there is no plan of fixing bugs with reacts 3 + Mantine 8.x. |
Fixes #8110
According to https://github.com/recharts/recharts/wiki/3.0-migration-guide#other-breaking-changes:
CartesianGridhas new propertiesx/yAxisIdthat correspond tox/yAxisIds on theX/YAxiscomponents respectively. With a different ID than default,CartesianGridlines will fail to render. This makes the grid rendering deterministic rather than just selecting the first axis it finds (Some grid lines are missing on BarChart with Recharts 3 when using yAxisId="left" recharts/recharts#6149)They seem to tie to the
<Bar>/<Line>/etc. elements too, whether or not there existsxAxisId/yAxisIdonXAxis/YAxis.From testing when all
<Bar>s have "right"yAxidIds, theCartesianGriddoes not show axis lines unless the<CartesianGrid>also has a "right"yAxisId, but on Discord vitaly noted "I’d rather just set it statically without calculations. It can be overridden with gridProps."