// Planu — Shared SVG chart utilities
/** 8 visually distinct colours for chart series. */
export const CHART_COLORS = [
    '#e94560',
    '#0891b2',
    '#059669',
    '#d97706',
    '#7c3aed',
    '#6366f1',
    '#0f766e',
    '#b45309',
    '#db2777',
    '#2563eb',
];
/**
 * Create a linear scale function that maps values from [domainMin, domainMax]
 * to [rangeMin, rangeMax].
 */
export function scaleLinear(domain, range) {
    const [d0, d1] = domain;
    const [r0, r1] = range;
    const domainSpan = d1 - d0;
    if (domainSpan === 0) {
        return () => r0;
    }
    return (val) => r0 + ((val - d0) / domainSpan) * (r1 - r0);
}
/** Render an SVG <text> element. */
export function svgText(x, y, text, opts) {
    const fontSize = opts?.fontSize ?? 12;
    const anchor = opts?.anchor ?? 'start';
    const fill = opts?.fill ?? '#2d3436';
    const escaped = escapeXml(text);
    return `<text x="${x}" y="${y}" font-size="${fontSize}" text-anchor="${anchor}" fill="${fill}">${escaped}</text>`;
}
/** Escape XML special chars for safe SVG embedding. */
export function escapeXml(str) {
    return str
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&apos;');
}
//# sourceMappingURL=chart-utils.js.map