Arc.tsx 847 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from "react";
import { arc, DefaultArcObject, PieArcDatum } from "d3-shape";
// import { DefaultArcObject } from "d3";

interface Props {
  arcData: DefaultArcObject & PieArcDatum<any>;
  label?: string;
  [rest: string]: any;
}

export const Arc = ({ arcData, label, ...rest }: Props) => {
  console.log("rest:", rest);
  const arcGenerator = arc();
  arcGenerator.cornerRadius(5.2);
  const centroid = arcGenerator.centroid({
    ...arcData,
    // startAngle: arcData.startAngle,
    // endAngle: arcData.endAngle,
  });
  const pathData = arcGenerator(arcData);
  // console.log("arcdata:", arcData, "path data:", pathData);
  return (
    <>
      <path d={pathData ?? ""} {...rest}></path>
      {label && (
        <text x={centroid[0]} y={centroid[1]} dy={"0.33em"}>
          {label}
        </text>
      )}
    </>
  );
};