Alberto ha chiesto una Dashboard compressa, su cui restare a guardare il motore che lavora. Il confronto delle schermate del 25/11 aveva lasciato aperti quattro difetti. - Anteprima: tiene le proporzioni 420 × 236 e si stringe con la pagina (fra 220 e 420 px, il 38% del cruscotto) restando accanto allo stato; i tetti vanno in due per due quando la colonna dello stato è stretta (@container). A 860 × 900 come a 1440 × 900 anteprima, stato, tetti e prima riga della cronologia stanno nel primo schermo; al telefono una colonna sola come prima. - Striscia della giornata: alta 30 px, le sessioni sono barre di quasi tutta l'altezza (margini in percentuale), non più punti; titolo e riassunto senza il vuoto quando vanno a capo. - «Mostra tutta (N)» della coda: margine interno delle righe (la regola di .btn.collegamento lo azzerava). - layout-dashboard.svg ridisegnata in casa: un tachimetro in un riquadro, diversa dai quattro quadrati della Libreria. Schermate 06, 11 e 14 rifatte con tools/Febe.Schermate e differenze.md aggiornato (che cosa ora combacia, che cosa resta diverso). DashboardInterfaceTests controlla a 860 × 900 l'anteprima accanto allo stato, le proporzioni, la prima riga della cronologia nel primo schermo, il margine di «Mostra tutta» e le barre alte; al telefono la colonna sola. Una riga in docs/decisioni.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
3.9 KiB
JavaScript
93 lines
3.9 KiB
JavaScript
// The strip of the day (spec §10.1, §7.9; mockups 06 and 11): a 24-hour bar with the sessions as irregular strokes,
|
|
// the current session highlighted, the planned ones dashed (indicative), night and outside-window hatched, throttles
|
|
// in amber, stops as a red hatch, the «adesso» line, hour ticks and a legend. Every stretch keeps its Italian label
|
|
// from the server as a tooltip; a hidden list repeats them for screen readers.
|
|
|
|
import { h } from '../core/dom.js';
|
|
import { t } from '../core/text.js';
|
|
|
|
const HOURS = [0, 3, 6, 9, 12, 15, 18, 21, 24];
|
|
|
|
/** Milliseconds of a time from the API (ISO text or number). */
|
|
export function ms(value) {
|
|
return typeof value === 'number' ? value : Date.parse(value);
|
|
}
|
|
|
|
/** A small deterministic wobble (0..1) from a number: strokes look drawn by hand but stay put between updates. */
|
|
function wobble(n) {
|
|
const x = Math.sin(n * 12.9898) * 43758.5453;
|
|
return x - Math.floor(x);
|
|
}
|
|
|
|
/**
|
|
* Draws the strip of a DayStrip. Options: stopOpen (an open stop runs to the end of the day, mockup 11).
|
|
* Returns { strip, hours, legend } so the page can place the legend in its header row.
|
|
*/
|
|
export function dayStrip(day, { stopOpen = false } = {}) {
|
|
const start = ms(day.start);
|
|
const end = ms(day.end);
|
|
const now = ms(day.now);
|
|
const span = Math.max(1, end - start);
|
|
const pos = (value) => Math.min(100, Math.max(0, ((ms(value) - start) / span) * 100));
|
|
const bar = h('div.striscia', { role: 'img', 'aria-label': `${t('attivita.striscia')}: ${day.summary}` });
|
|
for (const hour of HOURS.slice(1, -1)) bar.append(h('span.tacca', { style: { left: `${(hour / 24) * 100}%` } }));
|
|
|
|
const kinds = new Set();
|
|
const spoken = [];
|
|
for (const s of day.spans) {
|
|
const left = pos(s.start);
|
|
let right = pos(s.end);
|
|
if (s.kind === 'Stop' && stopOpen && ms(s.end) >= now - 60000) right = 100;
|
|
const width = Math.max(0, right - left);
|
|
const style = { left: `${left}%`, width: `${width}%` };
|
|
let el = null;
|
|
switch (s.kind) {
|
|
case 'OutsideWindow':
|
|
el = h('span.notte', { style });
|
|
kinds.add('riposo');
|
|
break;
|
|
case 'Session':
|
|
case 'CurrentSession':
|
|
case 'PlannedSession': {
|
|
// Bars of nearly the whole height, uneven by a few percent (mockup 06): in proportion to the strip, so that
|
|
// the lower strip of the Dashboard draws bars and not dots.
|
|
const w = wobble(ms(s.start) / 60000);
|
|
el = h(`span.sess${s.kind === 'CurrentSession' ? '.ora' : ''}${s.kind === 'PlannedSession' ? '.prev' : ''}`,
|
|
{ style: { ...style, top: `${(10 + w * 8).toFixed(1)}%`, bottom: `${(10 + (1 - w) * 8).toFixed(1)}%` } });
|
|
kinds.add(s.kind === 'PlannedSession' ? 'prossime' : 'sessione');
|
|
break;
|
|
}
|
|
case 'Throttle':
|
|
el = h('span.freno', { style });
|
|
kinds.add('rallentamento');
|
|
break;
|
|
case 'Stop':
|
|
el = h('span.fermo', { style });
|
|
kinds.add('fermo');
|
|
break;
|
|
default:
|
|
break; // rest between sessions is the plain background
|
|
}
|
|
if (el) {
|
|
el.title = s.label;
|
|
bar.append(el);
|
|
if (s.kind !== 'OutsideWindow') spoken.push(s.label);
|
|
}
|
|
}
|
|
if (now >= start && now <= end) {
|
|
bar.append(h('span.adesso', { style: { left: `${pos(now)}%` }, title: t('attivita.adesso') }));
|
|
}
|
|
bar.append(h('ul.vh', spoken.map((label) => h('li', label))));
|
|
|
|
const hours = h('div.ore', { 'aria-hidden': 'true' }, HOURS.map((hour) => h('span', { style: { left: `${(hour / 24) * 100}%` } }, String(hour))));
|
|
const items = [
|
|
['sessione', h('i.l-sess')],
|
|
['prossime', h('i.l-prev')],
|
|
['rallentamento', h('i.l-freno')],
|
|
['fermo', h('i.l-fermo')],
|
|
['riposo', h('i.l-notte')],
|
|
].filter(([key]) => key === 'sessione' || kinds.has(key));
|
|
const legend = h('div.legenda', items.map(([key, swatch]) => h('span', swatch, t(`attivita.legenda.${key}`))));
|
|
return { strip: bar, hours, legend };
|
|
}
|