import { valueof, textof, applyMargins } from "../../helpers";
import { LinePlotProps } from "./LinePlotProps";
export const LinePlot = ({ data, axis, chart }: LinePlotProps) => {
const { min: [minx, miny], max: [maxx, maxy], size: [sx, sy], margins: { margin: [mx, my], startOffset: [ox, oy] } } = axis;
const { x1, x2, y1, y2 } = applyMargins(chart, axis.margins);
const points = data.map((i, index) => {
const [x, y] = valueof(i);
const [textx, texty] = textof(i);
const _cx = (x - minx) * (sx) / (maxx - minx) + ox;
const _cy = (y - miny) * (sy) / (maxy - miny) + oy;
const cx = _cx + mx;
const cy = y1 - _cy;
return { cx, cy, textx, texty };
});
const pointsPath = points.map(p => `${p.cx},${p.cy}`).join(' ');
return <>
{points.map(({ cx, cy }, index) => {
return
})}
{points.map(({ cx, cy, textx, texty }, index) => {
return
{textx}
{texty}
})}
>;
};