import React from "react"; import FilterableRow from "../FilterableRow"; import SegTabs from "../SegTabs"; // Matriz de calor dimensión × mes de creación — puerto de cohMatriz()/cohHeat() // (App Informe/assets/js/pages/nuevas.js). `dims`/`metricas` traen `calc`/`fmt` (y `rgb` para el // color); el heat se computa acá mismo contra el máximo de la tabla completa. export default function CohMatriz({ arr, meses, dims, metricas, activeDimKey, activeMetKey, mesLbl }) { const dim = dims.find((d) => d.k === activeDimKey) || dims[0]; const met = metricas.find((m) => m.k === activeMetKey) || metricas[0]; const cats = [...new Set(arr.map((o) => o[dim.k] || "(sin dato)"))] .map((k) => ({ k, n: arr.filter((o) => (o[dim.k] || "(sin dato)") === k).length })) .sort((a, b) => b.n - a.n) .slice(0, 14); const cel = (k, m) => arr.filter((o) => (o[dim.k] || "(sin dato)") === k && o.mesCohorte === m); const valores = cats.flatMap((c) => meses.map((m) => met.calc(cel(c.k, m)))).filter((v) => v != null); const max = Math.max(...valores, 0); function heat(v) { if (v == null) return { bg: "", fg: "var(--tinta-suave)" }; const r = max > 0 ? Math.max(0, v) / max : 0; const a = v === 0 ? 0 : 0.06 + 0.74 * r; return { bg: a ? `rgba(${met.rgb},${a.toFixed(2)})` : "", fg: a > 0.48 ? "#fff" : "var(--tinta)" }; } return (
Clic en una fila o celda filtra · solo las 14 categorías con más volumen · ⚠ un 100% sobre 2 oportunidades pinta igual que sobre 40: pasa el cursor para ver el conteo real