import { Axis, Orient } from "./Axis"; import { BottomAxis } from "./BottomAxis"; import rawData from "../data/data.json"; import { scaleUtc, scaleLinear } from "d3-scale"; import { line } from "d3-shape"; import { max, extent } from "d3"; import useResizeObserver from "../hooks/useResizeObserver"; import { useSize } from "../hooks/useSize"; import { useRef } from "react"; import { useChartDimensions } from "../hooks/useChartDimensions"; import { Comment } from "../commons"; type Record = { date: Date; value: number; }; const data = rawData.map((d: any) => { return { date: new Date(d.date), value: +d.value, }; }) as Record[]; export const AxisExamples = () => { const [target, dimensions] = useChartDimensions({ marginTop: 20, marginBottom: 30, marginLeft: 30, marginRight: 20, }); // console.log("dimensions height=", dimensions.height); // const target = useRef(null); // const size = useSize(target); // console.log("size height=", size?.height); // const width = 600; // const height = 400; const width = dimensions.width || 600; const height = dimensions.height || 400; const margin = { top: dimensions.marginTop, right: dimensions.marginRight, bottom: dimensions.marginBottom, left: dimensions.marginLeft, }; // const width = size?.width || 600; // const height = size?.height || 400; // const margin = { // top: 20, // right: 20, // bottom: 30, // left: 30, // }; const x = scaleUtc() .domain(extent(data, (d) => d.date) as [Date, Date]) .range([margin.left, width - margin.right]); const y = scaleLinear() .domain([0, max(data, (d) => d.value)] as [number, number]) .nice() .range([height - margin.bottom, margin.top]); const lineXY = line() .defined((d) => !isNaN(d.value)) .x((d) => x(d.date)) .y((d) => y(d.value)); return (

Axis Examples

Resizable element 적용
); };