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

[Question] Annotating Donut chart #472

Closed
niwsa opened this issue May 16, 2019 · 2 comments
Closed

[Question] Annotating Donut chart #472

niwsa opened this issue May 16, 2019 · 2 comments

Comments

@niwsa
Copy link

niwsa commented May 16, 2019

image
As shown in the above fusion chart original link
Is it possible to put annotations at the center of a donut chart ? And change it on hover over a piece ?

Sorry if this turns out to be a dumb question.Running out of time ..Appreciate any pointers in right direction :)

@niwsa
Copy link
Author

niwsa commented May 16, 2019

Ok I am getting it right.Posting the code.
image

import ResponsiveOrdinalFrame from "semiotic/lib/ResponsiveOrdinalFrame";

const frameProps = {
  // Data
  data: [
    { user: "Jason", tweets: 40, retweets: 5, favorites: 15, color: "#64e2c2" },
    { user: "Susie", tweets: 5, retweets: 25, favorites: 100, color: "#f7e53b" }
  ],

  /* --- Size --- */
  margin: 70,

  /* --- Layout --- */
  type: { type: "bar", innerRadius: 70 },
  projection: "radial",
  dynamicColumnWidth: "tweets",
  /* --- Process --- */
  oAccessor: "user",

  /* --- Customize --- */
  //   style: { fill: "#ac58e5", stroke: "white" },
  style: d => ({ fill: d.color }),
  title: "Tweets",

  /* --- Annotate --- */
  oLabel: true,
  annotations: [
    { type: "custom", note: { title: "Total" } }
  ]
};
class DonutSemiotic extends Component {
  render() {
    const { halfDonut } = this.props;
    if (halfDonut) {
      frameProps.type.angleRange = [-90, 90];
    }
    return (
      <ResponsiveOrdinalFrame
        {...frameProps}
        svgAnnotationRules={d => {
          console.log(d);
          // Catch annotation with type="r"
          if (d.d.type === "custom") {
            return (
              <g
                fontSize="12"
                textAnchor="middle"
                fontWeight="bold"
                fill={"pink"}
                transform={`translate(${d.adjustedSize[0] / 2}
                 ${d.adjustedSize[0] / 2})`}
              >
                <text>{d.d.note.title}</text>
              </g>
            );
          }

          return null;
        }}
      />
    );
  }
}
export default DonutSemiotic;

@emeeks I have used or atleast tried using many charting libraries but semiotic has been my favorite so far.At times struggle with it but in the end its worth the struggle.Somehow got the feeling that semiotic is flexible in its approach...Keep up the good work :)

@emeeks
Copy link
Member

emeeks commented Sep 3, 2019

Thanks so much! Sorry I didn't respond to this while you were struggling with it and glad you're enjoying the library. I was switching jobs and such and that's why I haven't been as responsive to issues but now I'm getting it together, so please post more issues or ping me if I haven't answered your questions.

@emeeks emeeks closed this as completed Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants