import React from "react"; import type { PolylineLayerSpec, ViewportTransform } from "./types"; interface PolylineLayerProps { polylines?: PolylineLayerSpec[]; viewport: ViewportTransform; } export const PolylineLayer: React.FC = ({ polylines, viewport }) => { if (!polylines || polylines.length === 0) return null; return ( {polylines.map((poly) => { if (poly.points.length < 2) return null; const screenPoints = poly.points.map((p) => ({ x: viewport.toScreenX(p.x), y: viewport.toScreenY(p.y), })); const pointsAttr = screenPoints.map((p) => `${p.x},${p.y}`).join(" "); // Chỉ vẽ nhãn trên đường thẳng nếu kịch bản chỉ định rõ tọa độ đặt nhãn (labelPos), // vì tên các đường ngân sách đã có trên thanh Chú giải (Legend) phía trên đồ thị. const hasExplicitPos = Boolean(poly.label && poly.labelPos); const labelX = poly.labelPos ? viewport.toScreenX(poly.labelPos.x) : 0; const labelY = poly.labelPos ? viewport.toScreenY(poly.labelPos.y) : 0; return ( {hasExplicitPos && poly.label && ( {poly.label} )} ); })} ); };