Bar.tsx 728 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
import { ScaleBand, ScaleLinear } from "d3-scale";
import React from "react";

type Props = {
  dataset: number[];
  height: number;
  xScale: ScaleBand<number>;
  yScale: ScaleLinear<number, number>;
};

export const Bar = ({ dataset, height, xScale, yScale }: Props) => {
  // console.log("dataset:", dataset);
  return (
    <g>
      {dataset.map((d, i) => {
        console.log("d", d, "i", i, "x:", xScale(i), "y", yScale(d));
        return (
          <rect
            key={i}
            x={xScale(i)}
            y={height - yScale(d)}
            width={xScale.bandwidth()}
            height={yScale(d)}
            fill={`rgb(0, 0, ${Math.round(d * 10)})`}
          ></rect>
        );
      })}
    </g>
  );
};