Tiles get sparklines and delta chips (CR.tile/sparkline/delta): Reports unique + bots by day, Links 7-day clicks, Ads 7-day hourly views; bar charts capped in width, peak highlight only with 3+ days
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -116,5 +116,23 @@ window.CR = (function () {
|
||||
});
|
||||
}
|
||||
async function requireSession(onReady) { const m = await me(); whoPaint(m); if (m && m.signedIn) { strip(); await loginAd(); return onReady(m); } signInFlow(async r => { whoPaint(r); strip(); await loginAd(); onReady(r); }); }
|
||||
return { esc, fmt, api, get, copy, dialog, toast, mount, sub, me, requireSession, signInFlow };
|
||||
// tiles with a sparkline and a delta chip (Instrument scheme, 2026-09-29): series = numbers oldest first
|
||||
function sparkline(series) {
|
||||
const s = (series || []).map(Number); if (s.length < 2 || !s.some(Boolean)) return '';
|
||||
const W = 74, H = 26, max = Math.max(...s), min = Math.min(...s);
|
||||
const pts = s.map((v, i) => [(i / (s.length - 1)) * W, H - 2 - ((v - min) / ((max - min) || 1)) * (H - 4)]);
|
||||
const line = pts.map(p => p[0].toFixed(1) + ',' + p[1].toFixed(1)).join(' ');
|
||||
return '<svg class="sparkline" viewBox="0 0 74 26" aria-hidden="true"><polygon class="fill" points="0,26 ' + line + ' 74,26"/><polyline points="' + line + '"/></svg>';
|
||||
}
|
||||
function delta(now, before, label) {
|
||||
now = Number(now) || 0; before = Number(before) || 0; if (!before && !now) return null;
|
||||
if (!before) return { text: 'new' + (label ? ' ' + label : ''), cls: 'flat' };
|
||||
const pct = Math.round((now - before) / before * 100);
|
||||
return { text: (pct > 0 ? '+' : '') + pct + '%' + (label ? ' ' + label : ''), cls: pct > 0 ? '' : pct < 0 ? 'down' : 'flat' };
|
||||
}
|
||||
function tile(o) {
|
||||
return '<div class="tile' + (o.hi ? ' hi' : '') + '"><span class="k">' + esc(o.k) + '</span><div class="row"><span class="v">' + o.v + (o.unit ? '<small>' + esc(o.unit) + '</small>' : '') + '</span>' + sparkline(o.series) + '</div>'
|
||||
+ (o.delta ? '<span class="delta' + (o.delta.cls ? ' ' + o.delta.cls : '') + '">' + esc(o.delta.text) + '</span>' : '') + (o.note ? '<span class="muted mono" style="font-size:11px">' + esc(o.note) + '</span>' : '') + '</div>';
|
||||
}
|
||||
return { esc, fmt, api, get, copy, dialog, toast, mount, sub, me, requireSession, signInFlow, tile, sparkline, delta };
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user