Skip to content

Commit a646433

Browse files
committed
fix(site): show negative history deltas
Related to #19
1 parent 2e715a8 commit a646433

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

site/src/pages/index.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const endpoints = [
4848
<span class="mark">T</span>TechAPI<span class="cursor" aria-hidden="true"></span>
4949
</a>
5050
<div class="nav-links">
51-
<a href="#playground">Playground</a>
5251
<a href="#history">History</a>
52+
<a href="#playground">Playground</a>
5353
<a href="#featured">devices</a>
5454
<a href="#endpoints">endpoints</a>
5555
<a href={`${base}docs`}>docs</a>
@@ -76,7 +76,8 @@ const endpoints = [
7676
</h1>
7777
<p class="tagline">Structured specs &amp; computed scores for smartphones, SoCs, GPUs and CPUs — served as plain static JSON. Free and open.</p>
7878
<div class="hero-cta">
79-
<a class="btn primary" href="#playground">Open Playground <span class="arr">→</span></a>
79+
<a class="btn primary" href="#history">View dataset history <span class="arr">→</span></a>
80+
<a class="btn" href="#playground">Open Playground</a>
8081
<a class="btn" href={`${base}docs`}>Read the docs</a>
8182
</div>
8283
</div>

site/src/scripts/techapi.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,16 @@ function countUp(node, target) {
222222
const prev = sumByKey(prevRows);
223223
return nextRows
224224
.map((row) => ({ key: row.key, delta: row.count - (prev[row.key] || 0) }))
225-
.filter((row) => row.delta > 0)
226-
.sort((a, b) => b.delta - a.delta)
227-
.slice(0, 2);
225+
.filter((row) => row.delta !== 0)
226+
.sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta))
227+
.slice(0, 3);
228+
}
229+
230+
function formatDelta(delta, baseline = false) {
231+
if (baseline) return "baseline";
232+
if (delta > 0) return "+" + delta.toLocaleString();
233+
if (delta < 0) return delta.toLocaleString();
234+
return "no change";
228235
}
229236

230237
function renderHistory(points) {
@@ -234,18 +241,19 @@ function countUp(node, target) {
234241
const range = Math.max(1, maxTotal - minTotal);
235242
chartEl.innerHTML = points.map((point) => {
236243
const pct = 18 + ((point.total - minTotal) / range) * 82;
237-
const deltaText = point.delta > 0 ? "+" + point.delta.toLocaleString() : "baseline";
244+
const deltaText = formatDelta(point.delta, point.baseline);
245+
const deltaClass = point.delta < 0 ? " is-negative" : "";
238246
return `<a class="history-bar" href="${esc(point.url)}" target="_blank" rel="noopener" style="--h:${pct.toFixed(1)}%" title="${esc(point.title)}">
239247
<span class="history-bar-fill"></span>
240248
<span class="history-bar-total">${point.total.toLocaleString()}</span>
241-
<span class="history-bar-delta">${esc(deltaText)}</span>
249+
<span class="history-bar-delta${deltaClass}">${esc(deltaText)}</span>
242250
</a>`;
243251
}).join("");
244252

245253
listEl.innerHTML = points.slice().reverse().map((point) => {
246254
const changes = point.changes.length
247-
? point.changes.map((row) => `${shortLabel[row.key]} +${row.delta.toLocaleString()}`).join(", ")
248-
: (point.delta > 0 ? `total +${point.delta.toLocaleString()}` : "baseline snapshot");
255+
? point.changes.map((row) => `${shortLabel[row.key]} ${formatDelta(row.delta)}`).join(", ")
256+
: (point.baseline ? "baseline snapshot" : `total ${formatDelta(point.delta)}`);
249257
return `<li><span class="history-dot"></span><span>
250258
<a href="${esc(point.url)}" target="_blank" rel="noopener">${esc(point.title)}</a>
251259
<small>${esc(point.when)} - ${esc(point.sha)} - ${esc(changes)}</small>
@@ -296,6 +304,7 @@ function countUp(node, target) {
296304

297305
for (let i = 0; i < points.length; i++) {
298306
const prev = points[i - 1];
307+
points[i].baseline = !prev;
299308
points[i].delta = prev ? points[i].total - prev.total : 0;
300309
points[i].changes = largestChanges(prev?.rows, points[i].rows);
301310
}

site/src/styles/techapi.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ code, .mono { font-family: var(--mono); }
366366
font-size: 10px;
367367
color: var(--accent-text);
368368
}
369+
.history-bar-delta.is-negative {
370+
color: var(--err);
371+
}
369372
.history-list li {
370373
display: grid;
371374
grid-template-columns: 12px 1fr;

0 commit comments

Comments
 (0)