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

VictoryPie curved text labels #405

Open
InsidersByte opened this issue Oct 24, 2016 · 2 comments
Open

VictoryPie curved text labels #405

InsidersByte opened this issue Oct 24, 2016 · 2 comments
Assignees
Labels
Issue: Accepted The submitted issue has been confirmed by the Victory core team Type: Enhancement ✏️ An enhancement or feature proposal that will be addressed after the next release

Comments

@InsidersByte
Copy link

InsidersByte commented Oct 24, 2016

I would like to have curved text labels on a pie chart. I spoke both @boygirl and Jani about this at a recent meetup.

I am more than happy to contribute, but as I mentioned I am not sure how best this would fit in.

I created a pen that shows a basic example of this.

The most important bit is this snippet which creates the segments.

const segments = (pie(data)).map((d, i) => (
  <g key={i}>
    <path fill={colours(i)} d={segmentArc(d)} />
    <path d={textArc(d)} id={`${id}-${i}`} />
    <text style={styles.label}>
      <textPath startOffset="25%" xlinkHref={`${window.location.href.replace(window.location.hash, "")}#${id}-${i}`}>
        {d.data.name}
      </textPath>
    </text>
  </g>
 ));

One thing to note is that I had to figure out was how to get this to work when you have HTML5 based navigation. I originally had xlinkHref={#${id}-${i}} and it worked fine with hashbang navigation, but broke when used with HTML5 based navigation.

I am not an SVG wiz so not sure if there is a better way to fix it, but I ended up having to prepend ${window.location.href.replace(window.location.hash, "")} to the xlinkHref. (see here)

screen shot 2016-10-24 at 11 53 04
(example pie chart)

This tutorial helped me understand how to place text on an arc http://www.visualcinnamon.com/2015/09/placing-text-on-arcs.html

@boygirl
Copy link
Contributor

boygirl commented Oct 24, 2016

@InsidersByte Thanks! I think we can get this done by creating some curved label primitive that renders a path or arc in a <defs> and then references it in the textPath. We're already calculating a label radius, so it shouldn't be a lot of work to calculate an arc or path to pass to the curved label. Also, I was doing a tiny bit of reading on the <defs> spec, and I think it may potentially solve your HTML5 nav problem https://www.w3.org/TR/SVG/struct.html#Head

@InsidersByte
Copy link
Author

InsidersByte commented Oct 26, 2016

@boygirl thanks, using <defs> did solve the base tag problem 👍 (http://codepen.io/insidersbyte/pen/pEYAPa?editors=0010)

@boygirl boygirl added the Type: Enhancement ✏️ An enhancement or feature proposal that will be addressed after the next release label Mar 11, 2017
@acharyakavita acharyakavita self-assigned this Jan 26, 2024
@carbonrobot carbonrobot added the Issue: Accepted The submitted issue has been confirmed by the Victory core team label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Accepted The submitted issue has been confirmed by the Victory core team Type: Enhancement ✏️ An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants