feat(ui): gráfica del laboratorio con los tokens del rediseño (D3, N4)
Solo lo visual de dibujar(): barras --grafica-vigente y --grafica-simulada con esquinas superiores de 4 px, rejilla --grafica-rejilla, ejes en IBM Plex Mono 10.5 px (--grafica-ejes), leyenda arriba al centro y alto fijo del contenedor (maintainAspectRatio: false). Los datos, las llamadas y los ganchos no cambian.
This commit is contained in:
1 parent
a91aa9622f
commit
03af182952
1 file changed
+22
-4
@@ -83,16 +83,20 @@
|
||||
);
|
||||
}
|
||||
|
||||
// Solo lo visual sale de tokens de app.css (--grafica-*, --fuente*): barras con esquinas
|
||||
// superiores de 4 px, rejilla tenue, ejes en mono y leyenda arriba al centro.
|
||||
function dibujar(vigente, simulada) {
|
||||
const lienzo = $("#lab-grafica");
|
||||
if (!window.Chart || !lienzo) return;
|
||||
const estilo = getComputedStyle(document.documentElement);
|
||||
const color = (variable) => estilo.getPropertyValue(variable).trim();
|
||||
const token = (variable) => estilo.getPropertyValue(variable).trim();
|
||||
const ejes = { color: token("--grafica-ejes"), font: { family: token("--fuente-mono"), size: 10.5 } };
|
||||
const barra = { borderRadius: 4, maxBarThickness: 44, categoryPercentage: 0.7, barPercentage: 0.9 };
|
||||
const datos = {
|
||||
labels: ["Bajo", "Medio", "Alto"],
|
||||
datasets: [
|
||||
{ label: `Vigente (${modelo.version})`, data: NIVELES.map((n) => vigente[n]), backgroundColor: color("--tono-neutro") },
|
||||
{ label: "Simulada", data: simulada ? NIVELES.map((n) => simulada[n]) : [], backgroundColor: color("--tono-acento") },
|
||||
{ ...barra, label: `Vigente (${modelo.version})`, data: NIVELES.map((n) => vigente[n]), backgroundColor: token("--grafica-vigente") },
|
||||
{ ...barra, label: "Simulada", data: simulada ? NIVELES.map((n) => simulada[n]) : [], backgroundColor: token("--grafica-simulada") },
|
||||
],
|
||||
};
|
||||
if (grafica) {
|
||||
@@ -102,7 +106,21 @@
|
||||
grafica = new window.Chart(lienzo, {
|
||||
type: "bar",
|
||||
data: datos,
|
||||
options: { animation: false, scales: { y: { beginAtZero: true, ticks: { precision: 0 } } } },
|
||||
options: {
|
||||
animation: false,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: "top",
|
||||
align: "center",
|
||||
labels: { boxWidth: 10, boxHeight: 10, padding: 16, color: token("--color-texto-suave"), font: { family: token("--fuente"), size: 12.5 } },
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
x: { grid: { display: false }, border: { color: token("--grafica-rejilla") }, ticks: ejes },
|
||||
y: { beginAtZero: true, grid: { color: token("--grafica-rejilla") }, border: { display: false }, ticks: { ...ejes, precision: 0 } },
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user