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

RadarChart PolarAngleAxis getting cut off. #4266

Open
1 task
kenperregaux opened this issue Mar 5, 2024 · 5 comments
Open
1 task

RadarChart PolarAngleAxis getting cut off. #4266

kenperregaux opened this issue Mar 5, 2024 · 5 comments
Labels
enhancement Enhancement to a current API

Comments

@kenperregaux
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Wrapping only happens if there is a space in the label. I would expect it to wrap regardless. Using scaleToFit removes the label entirely with or without a width.

What is expected?

Wrapping regardless of label containing spaces or scaleToFit to work.

What is actually happening?

See example above...text wraps only if label contains a space OR scaleToFit to work.

Environment Info
Recharts v2.7.3
React 18.2
System Windows 11 Pro
Browser Chrome Version 122.0.6261.71
@ckifer
Copy link
Member

ckifer commented Mar 5, 2024

I would generally say this is an issue for margin on RadarChart to solve

Edit simple-radar-chart (forked)

margin however, does not take effect when using static cy, cx, and outerRadius. If you'd like to change those values while still having them be relative, you can change them as percentage values rather than whole numbers.

@ckifer ckifer added pending response Pending response from the issue requester question Issue that is a question about recharts rather than a bug or a feature request labels Mar 5, 2024
@kenperregaux
Copy link
Author

That is fine until you make the chart smaller (say width 350) then you have to play with the margins until it fits? This makes no sense. If I use scaleToFIt or set a width on the Text it should wrap automatically (not just when the label has spaces).

@ckifer ckifer removed the pending response Pending response from the issue requester label Mar 5, 2024
@ckifer
Copy link
Member

ckifer commented Mar 5, 2024

is using percentages an issue?

Recharts doesn't have any magic/dynamic "scale to fit" solutions for any charts at the moment besides using a ResponsiveContainer. scaleToFit is supposed to be based off of the Text component's width property. If you have a chart that changes size margin won't adjust automatically unless you make it dynamic yourself (which works well).

That being said, Text itself needs some work it seems (apologies, legacy inheritor of recharts. this functionality has been the same a long time before me).

For now I would just use something custom like the following or use a foreignObject to insert HTML and use CSS for line breaking:

        tick={(props) => {
          const { payload, ...rest } = props;
          return <text {...rest}>{payload?.value}</text>;
        }}

Here is a sandbox containing some of the not great behavior of the text component
Edit text-component-variant-issues

The transform done here is incorrect it seems https://github.com/recharts/recharts/blob/3.x/src/component/Text.tsx#L243

@ckifer ckifer added enhancement Enhancement to a current API and removed question Issue that is a question about recharts rather than a bug or a feature request labels Mar 5, 2024
@kenperregaux
Copy link
Author

kenperregaux commented Mar 5, 2024

@ckifer thanks for the responses. I tried different iterations of using Text with width and scaleToFit and no labels show up when I do that (tweak my original codesandbox above and add width). What I ended up doing is trimming the labels and concating '...' if they were too long. Not idea but it is all I could come up with.

    const getLabel = (label) => {
        const chars = 18;
        const regExpression = new RegExp(`.{1,${chars}}`, 'g');
        const pieces = label.replace(/-/g,' ').split(' ').map(s => s.match(regExpression)).flat();
        return pieces.length > 1 ? label.substring(0, chars - 1).concat('...') : label;
    }

@ckifer
Copy link
Member

ckifer commented Mar 5, 2024

Thanks for understanding!

If you'd like to contribute feel free! there's a ton of improvements to be had 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to a current API
Projects
None yet
Development

No branches or pull requests

2 participants