Skip to content
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

Fix axis padding calculation for 0 or 1 data point. Fixes #4313 #4314

Merged
merged 4 commits into from
Mar 19, 2024

Conversation

graup
Copy link
Contributor

@graup graup commented Mar 19, 2024

The padding calculation did not take into account the case when there is only 0 or 1 data point, in which case the calculatedPadding is Infinite, resulting in range() to be set to Infinite, resulting in the ticks not being drawn properly.

I have fixed this by checking for Infinite before setting calculatedPadding.

This results in at least something being drawn – behaving as if padding was undefined. An even better fix would be to calculate padding without relying on the distance between values, but that would require a big refactor.

Related Issue

#4313

How Has This Been Tested?

I added a test case. It is failing without my fix, showing that the x-axis is not drawn at all.

N.B. the same test case can also show the bug in #3640 if we look at the rendered .recharts-rectangle (it is empty even though there should be one bar).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or extended an existing story to show my changes

Copy link
Collaborator

@PavelVanecek PavelVanecek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and for the test! I would just like to see a small change in the assertion area, all good elsewhere.

Once that's done would you please also consider adding the same fix to the 3.x branch? @ckifer will prepare a bugfix release from master branch and we will want to have the fix also included in 3.x.

);

const tick = container.querySelector('.xAxis .recharts-cartesian-axis-tick-value');
expect(parseInt(tick?.getAttribute('x') as string, 10)).toEqual(180);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the test easier to read if it fails, can we do this instead?

const tick = container.querySelector('.xAxis .recharts-cartesian-axis-tick-value');
assertNonNull(tick);
expect(tick.getAttribute('x')).toEqual("180");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I did it like this

expect(tick).toBeInTheDocument();
expect(tick?.getAttribute('x')).toEqual('180');

@PavelVanecek
Copy link
Collaborator

I wonder if this problem is limited to Bar charts? Do you think it's valuable to have tests covering also other types of charts?

@graup
Copy link
Contributor Author

graup commented Mar 19, 2024

This problem will appear in all charts that use CartesianUtils I think. Only testing one is probably enough as the others will end up in the same code path.

Happy to make a PR for the 3.x branch

Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Like Pavel mentioned we'll need the same PR for 3.x so we don't forget about it.

Thank you!

@graup
Copy link
Contributor Author

graup commented Mar 19, 2024

Done. Thanks for the quick response guys.

I've also been looking into #3853, will push an updated version of that PR soonish

@ckifer ckifer merged commit e9228d4 into recharts:master Mar 19, 2024
5 checks passed
@ckifer
Copy link
Member

ckifer commented Apr 4, 2024

released in 2.12.4

renovate bot added a commit to SAP/ui5-webcomponents-react that referenced this pull request Apr 8, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [recharts](https://togithub.com/recharts/recharts) | [`2.12.3` ->
`2.12.4`](https://renovatebot.com/diffs/npm/recharts/2.12.3/2.12.4) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/recharts/2.12.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/recharts/2.12.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/recharts/2.12.3/2.12.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/recharts/2.12.3/2.12.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>recharts/recharts (recharts)</summary>

###
[`v2.12.4`](https://togithub.com/recharts/recharts/releases/tag/v2.12.4)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.12.3...v2.12.4)

#### What's Changed

Small fixes while working on v3 continued...

##### Fix

- `Accessibility`: remove role attribute from recharts-wrapper which
caused an accessibility violation with > 1 chart on the same page by
[@&#8203;julianna-langston](https://togithub.com/julianna-langston) in
[recharts/recharts#4386,
fixes [#&#8203;4384](https://togithub.com/recharts/recharts/issues/4384)
- `X/YAxis`: fix incorrect padding calculation when there is 1 datapoint
or less by [@&#8203;graup](https://togithub.com/graup) in
[recharts/recharts#4314
closes
[#&#8203;4313](https://togithub.com/recharts/recharts/issues/4313)

`className` fixes - helps slowly address
[recharts/recharts#2169:

- `Tooltip`: allow custom `className` on `cursor` by
[@&#8203;108yen](https://togithub.com/108yen) in
[recharts/recharts#4306
- `RadarChart/RadialBarChart`: allow custom `className` on
`PolarRadiusAxis`, `PolarAngleAxis`, and `Radar` dot by
[@&#8203;108yen](https://togithub.com/108yen) in
[recharts/recharts#4335
- `Pie`: allow custom `className` on `label` and `labelLine` of `Pie` by
[@&#8203;108yen](https://togithub.com/108yen) in
[recharts/recharts#4381

**Full Changelog**:
recharts/recharts@v2.12.3...v2.12.4

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/SAP/ui5-webcomponents-react).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Lukas Harbarth <lukas.harbarth@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants