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

Angles not working #250

Open
3 tasks done
DylanBrass opened this issue Feb 10, 2024 · 7 comments
Open
3 tasks done

Angles not working #250

DylanBrass opened this issue Feb 10, 2024 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@DylanBrass
Copy link

DylanBrass commented Feb 10, 2024

Describe the bug

Whenever you put an angle like so :

<XAxis dataKey="serviceName" name={"Service"}
                               interval={0} angle={-45}
                               textAnchor="end" height={200}/>

It will either disapear (when -90 or 90 +) or got to the middle.

I am using React and Typescript, plus Rechart, all newest versions.

Reproduction

  • Simply add an angle on an axis or even label

Validations

@DylanBrass DylanBrass added the bug Something isn't working label Feb 10, 2024
@EvHaus EvHaus added the help wanted Extra attention is needed label Feb 11, 2024
@EvHaus
Copy link
Owner

EvHaus commented Feb 11, 2024

Confirmed. I took a look, and I'm not entirely sure what's wrong here. It almost seems like the transform origin is set incorrectly for <Text> elements inside react-pdf. You can see the labels rotate, but not relative to their element.

image

@DylanBrass
Copy link
Author

Thank you, I thought I was going crazy haha, I wish I could help but I have near 0 experience with SVG's.

@urfx
Copy link

urfx commented Feb 28, 2024

looks like you are adding an angle to a group of text items (as you said the axis) rather to each text item (ie the label)...

btw this helped me find my issue which I can fix. (not sure I can fix yours but will revert if I do)

@kylekz
Copy link

kylekz commented Oct 30, 2024

This is going to sound really dumb, but I fixed my radar chart issue with a small pnpm patch that resets the text transform rotate to 0 for elements with a specific class.

You can see the <PolarRadiusAxis> ticks being completely off here:
image

When I set the angle to 90, it's fixed, but I don't want the angle to be in the center:
image

https://github.com/EvHaus/react-pdf-charts/blob/dev/src/index.tsx#L305

case "text":
  if (baseProps.transform && attribs.class ===
    "recharts-text recharts-polar-radius-axis-tick-value") {
     baseProps.transform = baseProps.transform.replace(/rotate\(60(?=,)/g, 'rotate(0')
  }
  return renderTextElement({
    baseProps,
    chartStyle,
    children: children2,
    node
});

{BB9DD157-F86E-40FC-AE5B-BA272714274B}

This is by no means perfect, but it's close enough for me. Not sure if this helps in diagnosing the root issue.

@JElgar
Copy link

JElgar commented Dec 23, 2024

I noticed the same behavior when using a rotation on the YAxis label. I.e.

<YAxis
	label={{
		value: `My y axis label`,
		style: { textAnchor: 'middle' },
		angle: -90,
		position: 'left',
		offset: 0,
	}}
/>

Currently the rotated label ends up on the chart rather than to the left of it.

@jontesen
Copy link

Hi,
I’ve noticed the same issue with the YAxis label. Adding angle: -90 not only rotates the text but also translates it above the Y-axis, which shouldn’t happen.

I’m wondering if there’s been any update or potential fix for this issue?

@EvHaus
Copy link
Owner

EvHaus commented Jan 14, 2025

This is mostly a note to myself. Here's a minimal repro of the issue:

An <svg> element with some angled text in regular HTML renders them on the bottom and rotated: REPL Link

Screenshot 2025-01-13 at 8 29 19 PM

In react-pdf the same equivalent <Svg /> code generates wrong positioning: REPL Link

Screenshot 2025-01-13 at 8 29 27 PM

Some theories that need testing:

  • It's either the rotate() function in the transform attribute that's broken in react-pdf, or
  • It's the positioning in the tspan elements that isn't working. react-pdf is known to have limited support for tspan elements, or
  • It would be something else too.

Needs further investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants