import { h } from '/static/admin2/vendor/preact.module.js'; import htm from '/static/admin2/vendor/htm.module.js'; const html = htm.bind(h); // SVG-атрибуты, не style: CSP v2 запрещает inline-стили. // Ширина полотна ПОСТОЯННАЯ: раньше она считалась от числа точек, и при одном месяце // viewBox сжимался до единиц, а SVG с width:100% растягивался в многоэкранную полосу. const W = 600; export const Bars = ({ values, label, labels = [] }) => { const max = Math.max(1, ...values.map((v) => Math.max(0, v))); const h0 = 90; const n = Math.max(1, values.length); const slot = W / n; const bw = Math.min(48, slot * 0.6); return html`
${label}
${values.map((v, i) => html``)} ${labels.map((m, i) => html`${String(m).slice(5)}`)}
`; }; export const Line = ({ values, label }) => { const max = Math.max(1, ...values.map((v) => Math.max(0, v))); const n = values.length; const step = n > 1 ? W / (n - 1) : 0; const x = (i) => n > 1 ? i * step : W / 2; const y = (v) => 90 - Math.max(0, v) / max * 80; const pts = values.map((v, i) => `${x(i)},${y(v)}`).join(' '); return html`
${label}
${n > 1 ? html`` : html``}
`; };