From 03af182952541f2cb182ca52f9ccb6dfaa9b6488 Mon Sep 17 00:00:00 2001 From: Fernando Davila Date: Fri, 9 Oct 2026 12:46:31 -0600 Subject: [PATCH] =?UTF-8?q?feat(ui):=20gr=C3=A1fica=20del=20laboratorio=20?= =?UTF-8?q?con=20los=20tokens=20del=20redise=C3=B1o=20(D3,=20N4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/static/laboratorio.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/static/laboratorio.js b/app/static/laboratorio.js index b9a105a..661db72 100644 --- a/app/static/laboratorio.js +++ b/app/static/laboratorio.js @@ -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 } }, + }, + }, }); } }