import React from "react"; import type { GuideLayerSpec, ViewportTransform } from "./types"; interface GuideLayerProps { guides?: GuideLayerSpec[]; viewport: ViewportTransform; showPointDrops?: boolean; } export const GuideLayer: React.FC = ({ guides, viewport, showPointDrops = true, }) => { if (!guides || guides.length === 0) return null; const placedTopLabels: number[] = []; return ( {guides.map((guide) => { const color = guide.color ?? "#94a3b8"; const isDashed = guide.dashed !== false; const dashArray = isDashed ? "4,4" : undefined; let topLabelYOffset = 10; if (guide.verticalX !== undefined && guide.topLabel) { const sx = viewport.toScreenX(guide.verticalX); const collides = placedTopLabels.some((prevX) => Math.abs(prevX - sx) < 85); if (collides) { topLabelYOffset = 26; } placedTopLabels.push(sx); } return ( {showPointDrops && guide.point && ( <> {/* Đường gióng dọc xuống trục hoành */} {/* Đường gióng ngang sang trục tung */} )} {guide.verticalX !== undefined && ( <> {guide.topLabel && ( {guide.topLabel} )} )} {guide.horizontalY !== undefined && ( )} ); })} ); };