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

ReferenceDot with a custom shape #469

Closed
3 tasks done
sglza opened this issue Sep 25, 2024 · 5 comments
Closed
3 tasks done

ReferenceDot with a custom shape #469

sglza opened this issue Sep 25, 2024 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sglza
Copy link

sglza commented Sep 25, 2024

Describe the bug

I'm unable to render a custom ReferenceDot on a ScatterChart, as there seems to be an issue with the use of the <svg/> tag.

Reproduction

https://stackblitz.com/edit/react-pdf-charts-starter-wzl2bp?file=src%2FApp.tsx

const CustomShape = (props) => {
  const { cx, cy } = props;
  return (
    <svg x={cx - 10} y={cy - 10} width={20} height={20} fill="red" viewBox="0 0 24 24">
      <path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z" />
    </svg>
  );
}

<ReferenceDot x={500} y={500} shape={CustomShape} />

Validations

@sglza sglza added the bug Something isn't working label Sep 25, 2024
@sglza
Copy link
Author

sglza commented Sep 25, 2024

I'm not sure I would mark this as solved, but I'm leaving this as it might be useful for others

I was able to go around the issue by using a group tag with the transform property, more or less like this:

const CustomDot = (props) => {
  const { cx, cy } = props;
  return (
    <g transform={`translate(${cx - 12},${cy - 12})`} width={20} height={20} fill="red" viewBox="0 0 24 24">
      <path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z" />
    </g>
  );
};

@EvHaus
Copy link
Owner

EvHaus commented Sep 27, 2024

Are you using server-side rendering or web-rendering? Your original code is working fine for me on the server.

Any chance you can give me a full reproducible example?

@EvHaus EvHaus added the help wanted Extra attention is needed label Sep 27, 2024
@sglza
Copy link
Author

sglza commented Sep 27, 2024

I've updated with a link to stackblitz:
https://stackblitz.com/edit/react-pdf-charts-starter-wzl2bp?file=src%2FApp.tsx

You can try it out yourself. The chart wont render until you take out the shape prop from ReferenceDot.

@EvHaus
Copy link
Owner

EvHaus commented Sep 28, 2024

Thanks, that was helpful. The issue is with react-pdf itself. It doesn't supported nested <Svg> elements (see diegomura/react-pdf#943).

For react-pdf-charts, I suppose I could automatically convert nested <svg> elements to <g> but that might not deliver the desired results as <g> doesn't support custom dimensions.

@sglza
Copy link
Author

sglza commented Sep 29, 2024

agreed
could just be added to the known issues and call it a day

@EvHaus EvHaus closed this as completed Sep 29, 2024
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

2 participants