EvHaus / react-pdf-charts

Allows SVG-based React charts to be rendered in react-pdf
MIT License
57 stars 3 forks source link

Angles not working #250

Open DylanBrass opened 9 months ago

DylanBrass commented 9 months ago

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

Validations

EvHaus commented 9 months ago

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 commented 9 months ago

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

urfx commented 9 months ago

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 commented 1 month ago

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.