Files
Autoparts-DB/docs/design/design-system/components/grafica-barras.html
Lucy ccd3962458 feat(design): add 16 new components + update 5 pages (ronda 2)
Bloqueantes POS: modal-pago, ticket-termico, banner-cliente, fkeys-footer, columnas-costo-margen
Componentes nuevos: calculadora-cambio, panel-deslizante, badge-cfdi, arbol-colapsable, tarjeta-metrica, grafica-barras, selector-periodo, etiqueta-codigo-barras
Estados: estado-vacio, banner-offline, modal-confirmacion
Páginas actualizadas: facturación, contabilidad, dashboard, configuración, reportes
2026-04-01 07:06:34 +00:00

359 lines
11 KiB
HTML

<!DOCTYPE html>
<html lang="es" data-theme="industrial">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nexus Autoparts — Gráfica de Barras</title>
<link rel="stylesheet" href="../tokens/tokens.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: var(--font-body); background: var(--color-bg-base);
color: var(--color-text-primary); padding: var(--space-8);
transition: var(--transition-normal);
}
.theme-switcher {
position: sticky; top: 0; z-index: calc(var(--z-modal) + 10);
display: flex; gap: var(--space-2);
padding: var(--space-3) var(--space-4);
background: var(--color-bg-elevated);
border-bottom: 1px solid var(--color-border);
margin: calc(-1 * var(--space-8)); margin-bottom: var(--space-8);
}
.theme-switcher button {
padding: var(--space-2) var(--space-4);
border: 1px solid var(--color-border);
background: var(--color-bg-base); color: var(--color-text-primary);
border-radius: var(--radius-md); cursor: pointer;
font-family: var(--font-body); font-size: var(--text-body-sm);
transition: var(--transition-fast);
}
.theme-switcher button.active {
background: var(--color-primary); color: var(--color-text-inverse);
border-color: var(--color-primary);
}
h1 { font-family: var(--font-heading); font-size: var(--text-h2);
font-weight: var(--heading-weight-primary); margin-bottom: var(--space-2);
color: var(--color-text-accent); }
.subtitle { color: var(--color-text-muted); font-size: var(--text-body); margin-bottom: var(--space-8); }
section { margin-bottom: var(--space-10); }
section > h2 {
font-family: var(--font-heading); font-size: var(--text-h4);
font-weight: var(--heading-weight-secondary); color: var(--color-text-secondary);
margin-bottom: var(--space-4); padding-bottom: var(--space-2);
border-bottom: 1px solid var(--color-border);
}
/* ── Chart Container ── */
.chart-container {
background: var(--color-bg-elevated);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
padding: var(--space-6);
max-width: 800px;
}
.chart-title {
font-family: var(--font-heading);
font-size: var(--text-h5);
font-weight: var(--heading-weight-secondary);
color: var(--color-text-primary);
margin-bottom: var(--space-1);
}
.chart-subtitle {
font-size: var(--text-caption);
color: var(--color-text-muted);
margin-bottom: var(--space-6);
}
/* ── Chart Layout ── */
.chart-area {
display: flex;
gap: var(--space-2);
height: 320px;
}
/* Y-Axis */
.y-axis {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-end;
padding-bottom: 28px; /* match x-axis label space */
min-width: 52px;
}
.y-axis span {
font-size: var(--text-caption);
color: var(--color-text-muted);
font-family: var(--font-mono);
line-height: 1;
}
/* Bars Area */
.bars-area {
flex: 1;
display: flex;
flex-direction: column;
position: relative;
}
/* Grid lines */
.grid-lines {
position: absolute;
inset: 0;
bottom: 28px;
display: flex;
flex-direction: column;
justify-content: space-between;
pointer-events: none;
}
.grid-line {
width: 100%;
height: 1px;
background: var(--color-border);
}
/* Bars flex container */
.bars-row {
flex: 1;
display: flex;
align-items: flex-end;
justify-content: space-around;
gap: var(--space-2);
position: relative;
z-index: 1;
}
/* Individual bar wrapper */
.bar-wrapper {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
justify-content: flex-end;
position: relative;
}
/* Bar element */
.bar {
width: 70%;
max-width: 56px;
border-radius: var(--radius-sm) var(--radius-sm) 0 0;
background: var(--color-primary);
transition: height 0.8s var(--ease-out), background 0.15s ease;
height: 0;
cursor: pointer;
position: relative;
}
.bar:hover {
background: var(--color-primary-hover);
}
/* Tooltip */
.bar-tooltip {
position: absolute;
top: -36px;
left: 50%;
transform: translateX(-50%);
background: var(--color-bg-overlay);
color: var(--color-text-primary);
font-family: var(--font-mono);
font-size: var(--text-caption);
font-weight: var(--font-weight-semibold);
padding: var(--space-1) var(--space-2);
border-radius: var(--radius-sm);
border: 1px solid var(--color-border-strong);
box-shadow: var(--shadow-md);
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity 0.15s ease;
}
.bar-tooltip::after {
content: '';
position: absolute;
bottom: -5px;
left: 50%;
transform: translateX(-50%) rotate(45deg);
width: 8px; height: 8px;
background: var(--color-bg-overlay);
border-right: 1px solid var(--color-border-strong);
border-bottom: 1px solid var(--color-border-strong);
}
.bar:hover .bar-tooltip {
opacity: 1;
}
/* X-Axis labels */
.x-labels {
display: flex;
justify-content: space-around;
padding-top: var(--space-2);
border-top: 1px solid var(--color-border);
}
.x-labels span {
flex: 1;
text-align: center;
font-size: var(--text-caption);
color: var(--color-text-muted);
font-weight: var(--font-weight-semibold);
text-transform: uppercase;
letter-spacing: var(--tracking-wide);
}
/* ── Chart footer / total ── */
.chart-footer {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: var(--space-4);
padding-top: var(--space-3);
border-top: 1px solid var(--color-border);
}
.chart-total {
font-family: var(--font-heading);
font-size: var(--text-h5);
font-weight: var(--heading-weight-primary);
color: var(--color-text-accent);
}
.chart-total-label {
font-size: var(--text-caption);
color: var(--color-text-muted);
text-transform: uppercase;
letter-spacing: var(--tracking-wider);
}
.chart-avg {
font-size: var(--text-body-sm);
color: var(--color-text-secondary);
}
.chart-avg strong {
font-family: var(--font-mono);
color: var(--color-text-primary);
}
/* Highlight best day */
.bar.best {
background: var(--color-success);
}
.bar.best:hover {
background: var(--color-success-dark);
}
.bar.worst {
opacity: 0.65;
}
</style>
</head>
<body>
<div class="theme-switcher">
<button class="active" onclick="document.documentElement.dataset.theme='industrial'; this.classList.add('active'); this.nextElementSibling.classList.remove('active')">🔧 Industrial</button>
<button onclick="document.documentElement.dataset.theme='modern'; this.classList.add('active'); this.previousElementSibling.classList.remove('active')">⚡ Moderno</button>
</div>
<h1>Gráfica de Barras</h1>
<p class="subtitle">Gráfica de barras verticales pura CSS/JS. Animación al cargar, tooltips al hover.</p>
<section>
<h2>Ventas Semanales</h2>
<div class="chart-container">
<div class="chart-title">Ventas por Día</div>
<div class="chart-subtitle">Semana del 24 al 30 de marzo 2026</div>
<div class="chart-area">
<div class="y-axis" id="yAxis"></div>
<div class="bars-area">
<div class="grid-lines" id="gridLines"></div>
<div class="bars-row" id="barsRow"></div>
<div class="x-labels" id="xLabels"></div>
</div>
</div>
<div class="chart-footer">
<div>
<div class="chart-total-label">Total semanal</div>
<div class="chart-total" id="totalValue"></div>
</div>
<div class="chart-avg">Promedio diario: <strong id="avgValue"></strong></div>
</div>
</div>
</section>
<script>
const data = [
{ day: 'Lun', value: 12500 },
{ day: 'Mar', value: 18300 },
{ day: 'Mié', value: 15700 },
{ day: 'Jue', value: 22100 },
{ day: 'Vie', value: 28500 },
{ day: 'Sáb', value: 31200 },
{ day: 'Dom', value: 8900 },
];
const maxVal = Math.max(...data.map(d => d.value));
const bestIdx = data.indexOf(data.find(d => d.value === maxVal));
const worstIdx = data.indexOf(data.find(d => d.value === Math.min(...data.map(d => d.value))));
// Round up max to nearest nice number for Y-axis
const yMax = Math.ceil(maxVal / 5000) * 5000;
const ySteps = 5;
// Build Y-axis labels
const yAxis = document.getElementById('yAxis');
for (let i = ySteps; i >= 0; i--) {
const val = (yMax / ySteps) * i;
const span = document.createElement('span');
span.textContent = '$' + (val / 1000).toFixed(0) + 'k';
yAxis.appendChild(span);
}
// Build grid lines
const gridLines = document.getElementById('gridLines');
for (let i = 0; i <= ySteps; i++) {
const line = document.createElement('div');
line.className = 'grid-line';
gridLines.appendChild(line);
}
// Build bars
const barsRow = document.getElementById('barsRow');
const xLabels = document.getElementById('xLabels');
data.forEach((d, i) => {
const wrapper = document.createElement('div');
wrapper.className = 'bar-wrapper';
const bar = document.createElement('div');
bar.className = 'bar';
if (i === bestIdx) bar.classList.add('best');
if (i === worstIdx) bar.classList.add('worst');
bar.dataset.height = ((d.value / yMax) * 100).toFixed(1);
const tooltip = document.createElement('div');
tooltip.className = 'bar-tooltip';
tooltip.textContent = '$' + d.value.toLocaleString('es-MX');
bar.appendChild(tooltip);
wrapper.appendChild(bar);
barsRow.appendChild(wrapper);
const label = document.createElement('span');
label.textContent = d.day;
xLabels.appendChild(label);
});
// Totals
const total = data.reduce((s, d) => s + d.value, 0);
document.getElementById('totalValue').textContent = '$' + total.toLocaleString('es-MX');
document.getElementById('avgValue').textContent = '$' + Math.round(total / data.length).toLocaleString('es-MX');
// Animate bars on load
window.addEventListener('DOMContentLoaded', () => {
setTimeout(() => {
document.querySelectorAll('.bar').forEach(bar => {
bar.style.height = bar.dataset.height + '%';
});
}, 150);
});
</script>
</body>
</html>