Pie.tsx 915 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
33
34
35
36
37
38
39
40
import { scaleLinear } from "d3-scale";
import { arc, pie } from "d3-shape";
import React from "react";
import { Arc } from "./Arc";

type Props = {
  data: any;
};
export const Pie = ({ data }: Props) => {
  const width = 300;
  const height = 300;

  const pieGenerator = pie();
  const arcs = pieGenerator.padAngle(0.1)(data);

  console.log(arcs);
  return (
    <div>
      <h1>Pie</h1>
      <svg width={width} height={height}>
        <g
          transform={`translate(${width / 2},${height / 2})`}
          textAnchor="middle"
          stroke="white"
        >
          {arcs.map((arc, i) => (
            <Arc
              key={i}
              arcData={{ ...arc, innerRadius: 0, outerRadius: 100 }}
              label={String(arc.value)}
              fill={"blue"}
              stroke={"red"}
              strokeWidth={2}
            />
          ))}
        </g>
      </svg>
    </div>
  );
};