MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / formatRelativeTime

Function formatRelativeTime

web/scripts/ragnar_modern.js:2732–2760  ·  view source on GitHub ↗
(seconds)

Source from the content-addressed store, hash-verified

2730 const K = o.big ? 1.3 : 1; // type / padding scale
2731 const dpr = window.devicePixelRatio || 1;
2732 const W = canvas.clientWidth, H = Math.round(o.height || canvas.clientHeight || 360);
2733 if (W < 20 || H < 20) return;
2734 canvas.width = W * dpr; canvas.height = H * dpr;
2735 canvas._wifiHits = [];
2736 const ctx = canvas.getContext('2d'); ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
2737 ctx.clearRect(0, 0, W, H);
2738 const padL = Math.round(40 * K), padR = Math.round(12 * K),
2739 padT = Math.round(16 * K), padB = Math.round(34 * K);
2740 const plotW = W - padL - padR, plotH = H - padT - padB;
2741 const yTop = -30, yBot = -95;
2742 const yFor = (dbm) => padT + (yTop - Math.max(yBot, Math.min(yTop, dbm))) / (yTop - yBot) * plotH;
2743 const dbmFor = (y) => yTop - (y - padT) / plotH * (yTop - yBot);
2744 // Y gridlines
2745 ctx.strokeStyle = '#1e293b'; ctx.fillStyle = '#64748b'; ctx.font = `${10 * K}px sans-serif`; ctx.textAlign = 'right';
2746 for (let v = yTop; v >= yBot; v -= 10) {
2747 const y = yFor(v); ctx.beginPath(); ctx.moveTo(padL, y); ctx.lineTo(W - padR, y); ctx.stroke();
2748 ctx.fillText(v + '', padL - 4, y + 3);
2749 }
2750 if (o.big) {
2751 ctx.save(); ctx.translate(12, padT + plotH / 2); ctx.rotate(-Math.PI / 2);
2752 ctx.textAlign = 'center'; ctx.fillStyle = '#475569'; ctx.font = '11px sans-serif';
2753 ctx.fillText('RSSI (dBm)', 0, 0); ctx.restore();
2754 }
2755 // Which bands to show
2756 let bands = _wifiState.band === 'all' ? Object.keys(d.spectrum).sort() : [_wifiState.band];
2757 bands = bands.filter(b => d.aps.some(a => a.band === b));
2758 if (!bands.length) {
2759 ctx.fillStyle = '#64748b'; ctx.textAlign = 'center'; ctx.font = `${11 * K}px sans-serif`;
2760 ctx.fillText('No APs on selected band', W / 2, H / 2);
2761 canvas._wifiGeom = null;
2762 return;
2763 }

Callers 1

buildLastSyncDisplayFunction · 0.70

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected