informe-comercial-alfa/app/components/nuevas/CohMatriz.js
Marco A. Montenegro Mercado 390fd02a2a Re-crea el repo desde C:\dev\informe-comercial — versión real en producción
La carpeta con .git (C:\Mis Aplicaciones\informe-comercial) quedó desactualizada
frente a lo que corre hoy en Coolify (deploy directo por Foundry desde esta
carpeta, sin paso por git). Este commit fija esta carpeta como fuente de verdad
del repo, con Renovaciones, Actividades, Agenda, Admin/Metas y Nuevas
Oportunidades que la copia vieja no tenía.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-28 10:38:16 -06:00

99 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 (
<div className="panel">
<h3>Matriz de calor — {dim.lbl} × mes de creación</h3>
<p className="hint">
La intensidad del color es el valor de la celda dentro de esta tabla · clic en una fila o celda filtra por
esa categoría · solo se muestran las 14 categorías con más volumen creado
</p>
<p className="hint" style={{ marginTop: -6 }}>
⚠ Un 100% sobre 2 oportunidades pinta igual de intenso que uno sobre 40 — pasá el cursor por la celda para
ver el conteo real antes de sacar conclusiones.
</p>
<div style={{ marginBottom: 8 }}>
<SegTabs tabs={dims.map((d) => ({ k: d.k, lbl: d.lbl }))} activeKey={dim.k} paramName="cohd" />
</div>
<div style={{ marginBottom: 12 }}>
<SegTabs tabs={metricas.map((m) => ({ k: m.k, lbl: m.lbl }))} activeKey={met.k} paramName="cohm" />
</div>
<div
className="mze"
style={{ gridTemplateColumns: `minmax(130px,1.5fr) repeat(${meses.length},minmax(56px,1fr)) minmax(70px,.85fr)` }}
>
<div className="mze-h eje" />
{meses.map((m) => <div className="mze-h" key={m}>{mesLbl(m).slice(0, 3)}</div>)}
<div className="mze-h tot">Total</div>
{cats.map((c) => {
const totA = arr.filter((o) => (o[dim.k] || "(sin dato)") === c.k);
return (
<React.Fragment key={c.k}>
<FilterableRow as="div" pairs={[[dim.k, c.k]]} className="mze-r" title={`Ver solo ${c.k}`}>
{c.k}
</FilterableRow>
{meses.map((m) => {
const a = cel(c.k, m);
const v = met.calc(a);
const h = heat(v);
return (
<FilterableRow
as="div"
key={`${c.k}-${m}`}
pairs={[[dim.k, c.k]]}
className={`mze-c${a.length ? "" : " vacia"}`}
style={{ background: h.bg, color: h.fg }}
title={`${c.k} · ${mesLbl(m)} — ${a.length} creada(s), ${a.filter((o) => o.estado === "Ganada").length} ganada(s), ${a.filter((o) => o.estado === "Perdida").length} perdida(s), ${a.filter((o) => o.estado === "Abierta").length} abierta(s)`}
>
<span className="n">{met.fmt(v)}</span>
</FilterableRow>
);
})}
<div className="mze-c tot">
<span className="n">{met.fmt(met.calc(totA))}</span>
<span className="v">{totA.length} creadas</span>
</div>
</React.Fragment>
);
})}
<div className="mze-r tot">Total</div>
{meses.map((m) => {
const a = arr.filter((o) => o.mesCohorte === m);
return (
<div className="mze-c tot" key={`pie-${m}`}>
<span className="n">{met.fmt(met.calc(a))}</span>
<span className="v">{a.length}</span>
</div>
);
})}
<div className="mze-c tot">
<span className="n">{met.fmt(met.calc(arr))}</span>
<span className="v">{arr.length}</span>
</div>
</div>
</div>
);
}