Spaces:
Running
Running
Live games-over-time charts (static, client-side fetch)
Browse files- README.md +7 -4
- index.html +417 -17
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Faïence Game Traffic
|
| 3 |
+
emoji: 🎲
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
Live activity charts for the [RemiFabre/faience-games](https://huggingface.co/datasets/RemiFabre/faience-games)
|
| 11 |
+
dataset. Static page: on every load it lists the dataset's game files via the
|
| 12 |
+
Hub API (one JSONL file per shared game, timestamp in the filename) and bins
|
| 13 |
+
them client-side. Nothing to restart, no server, no schedule.
|
index.html
CHANGED
|
@@ -1,19 +1,419 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>Faïence Game Traffic</title>
|
| 7 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600&family=IBM+Plex+Sans:wght@400;500;600&display=swap">
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
--surface: #fcfcfb;
|
| 11 |
+
--surface-2: #f3f2ef;
|
| 12 |
+
--ink: #0b0b0b;
|
| 13 |
+
--ink-2: #52514e;
|
| 14 |
+
--ink-3: #8a887f;
|
| 15 |
+
--series: #2a78d6;
|
| 16 |
+
--series-soft: rgba(42, 120, 214, 0.10);
|
| 17 |
+
--grid: rgba(11, 11, 11, 0.08);
|
| 18 |
+
--tooltip-bg: #23221f;
|
| 19 |
+
--tooltip-ink: #fcfcfb;
|
| 20 |
+
--border: rgba(11, 11, 11, 0.12);
|
| 21 |
+
}
|
| 22 |
+
@media (prefers-color-scheme: dark) {
|
| 23 |
+
:root {
|
| 24 |
+
--surface: #1a1a19;
|
| 25 |
+
--surface-2: #232322;
|
| 26 |
+
--ink: #ffffff;
|
| 27 |
+
--ink-2: #c3c2b7;
|
| 28 |
+
--ink-3: #8a887f;
|
| 29 |
+
--series: #3987e5;
|
| 30 |
+
--series-soft: rgba(57, 135, 229, 0.14);
|
| 31 |
+
--grid: rgba(255, 255, 255, 0.10);
|
| 32 |
+
--tooltip-bg: #f3f2ef;
|
| 33 |
+
--tooltip-ink: #1a1a19;
|
| 34 |
+
--border: rgba(255, 255, 255, 0.15);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
* { box-sizing: border-box; }
|
| 39 |
+
body {
|
| 40 |
+
background: var(--surface);
|
| 41 |
+
color: var(--ink);
|
| 42 |
+
font-family: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
|
| 43 |
+
line-height: 1.5;
|
| 44 |
+
margin: 0;
|
| 45 |
+
padding: 2.5rem 1.25rem 4rem;
|
| 46 |
+
}
|
| 47 |
+
.wrap { max-width: 60rem; margin: 0 auto; }
|
| 48 |
+
|
| 49 |
+
header { margin-bottom: 2rem; }
|
| 50 |
+
.eyebrow {
|
| 51 |
+
font-size: 0.75rem;
|
| 52 |
+
font-weight: 600;
|
| 53 |
+
letter-spacing: 0.08em;
|
| 54 |
+
text-transform: uppercase;
|
| 55 |
+
color: var(--series);
|
| 56 |
+
margin: 0 0 0.5rem;
|
| 57 |
+
}
|
| 58 |
+
h1 {
|
| 59 |
+
font-family: "Fraunces", Georgia, serif;
|
| 60 |
+
font-weight: 600;
|
| 61 |
+
font-size: clamp(1.8rem, 4vw, 2.6rem);
|
| 62 |
+
line-height: 1.15;
|
| 63 |
+
text-wrap: balance;
|
| 64 |
+
margin: 0 0 0.4rem;
|
| 65 |
+
}
|
| 66 |
+
.sub { color: var(--ink-2); margin: 0; max-width: 42rem; }
|
| 67 |
+
a { color: var(--series); }
|
| 68 |
+
|
| 69 |
+
#status {
|
| 70 |
+
color: var(--ink-2);
|
| 71 |
+
background: var(--surface-2);
|
| 72 |
+
border-radius: 8px;
|
| 73 |
+
padding: 0.9rem 1.2rem;
|
| 74 |
+
margin: 1.75rem 0;
|
| 75 |
+
}
|
| 76 |
+
#status.error { color: #c0392b; }
|
| 77 |
+
.hidden { display: none; }
|
| 78 |
+
|
| 79 |
+
.stats {
|
| 80 |
+
display: flex;
|
| 81 |
+
flex-wrap: wrap;
|
| 82 |
+
gap: 1rem;
|
| 83 |
+
margin: 1.75rem 0 2rem;
|
| 84 |
+
}
|
| 85 |
+
.stat {
|
| 86 |
+
background: var(--surface-2);
|
| 87 |
+
border-radius: 8px;
|
| 88 |
+
padding: 0.9rem 1.2rem;
|
| 89 |
+
min-width: 9rem;
|
| 90 |
+
flex: 0 1 auto;
|
| 91 |
+
}
|
| 92 |
+
.stat .n {
|
| 93 |
+
font-family: "Fraunces", Georgia, serif;
|
| 94 |
+
font-weight: 600;
|
| 95 |
+
font-size: 1.9rem;
|
| 96 |
+
font-variant-numeric: tabular-nums;
|
| 97 |
+
line-height: 1.1;
|
| 98 |
+
}
|
| 99 |
+
.stat .l { font-size: 0.8rem; color: var(--ink-2); margin-top: 0.15rem; }
|
| 100 |
+
|
| 101 |
+
.chart-card { position: relative; }
|
| 102 |
+
.chart-card + .chart-card { margin-top: 2.25rem; }
|
| 103 |
+
.chart-title { font-weight: 600; margin: 0 0 0.25rem; }
|
| 104 |
+
.chart-note { font-size: 0.8rem; color: var(--ink-3); margin: 0 0 0.75rem; }
|
| 105 |
+
.chart-scroll { overflow-x: auto; }
|
| 106 |
+
svg { display: block; }
|
| 107 |
+
|
| 108 |
+
.tooltip {
|
| 109 |
+
position: absolute;
|
| 110 |
+
pointer-events: none;
|
| 111 |
+
background: var(--tooltip-bg);
|
| 112 |
+
color: var(--tooltip-ink);
|
| 113 |
+
font-size: 0.78rem;
|
| 114 |
+
line-height: 1.35;
|
| 115 |
+
padding: 0.4rem 0.6rem;
|
| 116 |
+
border-radius: 6px;
|
| 117 |
+
white-space: nowrap;
|
| 118 |
+
opacity: 0;
|
| 119 |
+
transition: opacity 80ms linear;
|
| 120 |
+
z-index: 2;
|
| 121 |
+
}
|
| 122 |
+
@media (prefers-reduced-motion: reduce) {
|
| 123 |
+
.tooltip { transition: none; }
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
details { margin-top: 2.25rem; }
|
| 127 |
+
summary { cursor: pointer; font-weight: 500; color: var(--ink-2); }
|
| 128 |
+
summary:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; border-radius: 3px; }
|
| 129 |
+
.table-scroll { overflow-x: auto; margin-top: 0.75rem; }
|
| 130 |
+
table { border-collapse: collapse; font-size: 0.85rem; }
|
| 131 |
+
th, td {
|
| 132 |
+
text-align: left;
|
| 133 |
+
padding: 0.3rem 1.1rem 0.3rem 0;
|
| 134 |
+
border-bottom: 1px solid var(--border);
|
| 135 |
+
font-variant-numeric: tabular-nums;
|
| 136 |
+
}
|
| 137 |
+
th { color: var(--ink-2); font-weight: 500; }
|
| 138 |
+
|
| 139 |
+
footer { margin-top: 2.5rem; font-size: 0.8rem; color: var(--ink-3); }
|
| 140 |
+
</style>
|
| 141 |
+
</head>
|
| 142 |
+
<body>
|
| 143 |
+
<div class="wrap">
|
| 144 |
+
<header>
|
| 145 |
+
<p class="eyebrow">Dataset · RemiFabre/faience-games</p>
|
| 146 |
+
<h1>Games played over time</h1>
|
| 147 |
+
<p class="sub">Every shared human-vs-net Azul game on Faïence, counted live from the
|
| 148 |
+
file listing of the
|
| 149 |
+
<a href="https://huggingface.co/datasets/RemiFabre/faience-games">dataset</a>.
|
| 150 |
+
Reload the page to refresh. All times UTC.</p>
|
| 151 |
+
</header>
|
| 152 |
+
|
| 153 |
+
<div id="status">Loading game list from the Hub…</div>
|
| 154 |
+
|
| 155 |
+
<div id="content" class="hidden">
|
| 156 |
+
<div class="stats" id="stats"></div>
|
| 157 |
+
|
| 158 |
+
<div class="chart-card">
|
| 159 |
+
<p class="chart-title" id="bars-title">Games per hour</p>
|
| 160 |
+
<p class="chart-note">Hover a bar for the exact count · times in UTC</p>
|
| 161 |
+
<div class="chart-scroll"><svg id="chart1" role="img" aria-label="Bar chart of games played per time bin"></svg></div>
|
| 162 |
+
<div class="tooltip" id="tip1"></div>
|
| 163 |
+
</div>
|
| 164 |
+
|
| 165 |
+
<div class="chart-card">
|
| 166 |
+
<p class="chart-title">Cumulative games</p>
|
| 167 |
+
<p class="chart-note">Running total of shared games · times in UTC</p>
|
| 168 |
+
<div class="chart-scroll"><svg id="chart2" role="img" aria-label="Line chart of cumulative games played"></svg></div>
|
| 169 |
+
<div class="tooltip" id="tip2"></div>
|
| 170 |
+
</div>
|
| 171 |
+
|
| 172 |
+
<details>
|
| 173 |
+
<summary>Data table</summary>
|
| 174 |
+
<div class="table-scroll">
|
| 175 |
+
<table id="data-table">
|
| 176 |
+
<thead><tr><th id="bin-th">Bin (UTC)</th><th>Games</th><th>Cumulative</th></tr></thead>
|
| 177 |
+
<tbody></tbody>
|
| 178 |
+
</table>
|
| 179 |
+
</div>
|
| 180 |
+
</details>
|
| 181 |
+
</div>
|
| 182 |
+
|
| 183 |
+
<footer id="foot"></footer>
|
| 184 |
+
</div>
|
| 185 |
+
|
| 186 |
+
<script>
|
| 187 |
+
(async function () {
|
| 188 |
+
const DATASET = "RemiFabre/faience-games";
|
| 189 |
+
const MONTHS = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
|
| 190 |
+
const status = document.getElementById("status");
|
| 191 |
+
|
| 192 |
+
// 1. List every game file via the paginated tree API.
|
| 193 |
+
async function listGameFiles() {
|
| 194 |
+
let url = `https://huggingface.co/api/datasets/${DATASET}/tree/main?recursive=true&limit=1000`;
|
| 195 |
+
const paths = [];
|
| 196 |
+
while (url) {
|
| 197 |
+
const r = await fetch(url);
|
| 198 |
+
if (!r.ok) throw new Error(`Hub API returned ${r.status}`);
|
| 199 |
+
for (const it of await r.json()) {
|
| 200 |
+
if (it.type === "file" && it.path.startsWith("games/") && it.path.endsWith(".jsonl")) {
|
| 201 |
+
paths.push(it.path);
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
const m = (r.headers.get("Link") || "").match(/<([^>]+)>;\s*rel="next"/);
|
| 205 |
+
url = m ? m[1] : null;
|
| 206 |
+
if (url) status.textContent = `Loading game list from the Hub… ${paths.length} files so far`;
|
| 207 |
+
}
|
| 208 |
+
return paths;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
// 2. Timestamps come from the filenames: games/YYYY-MM-DD/YYYY-MM-DDTHH-MM-SS-mmmZ-N.jsonl
|
| 212 |
+
function parseTs(path) {
|
| 213 |
+
const m = path.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2})/);
|
| 214 |
+
if (!m) return null;
|
| 215 |
+
return Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
let times;
|
| 219 |
+
try {
|
| 220 |
+
times = (await listGameFiles()).map(parseTs).filter(t => t !== null).sort((a, b) => a - b);
|
| 221 |
+
if (!times.length) throw new Error("no game files found in the dataset");
|
| 222 |
+
} catch (e) {
|
| 223 |
+
status.textContent = `Could not load the dataset listing (${e.message}). Reload the page to retry.`;
|
| 224 |
+
status.classList.add("error");
|
| 225 |
+
return;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// 3. Bin: per hour while the span is short, per day once it exceeds 8 days.
|
| 229 |
+
const HOUR = 3600e3, DAY = 24 * HOUR;
|
| 230 |
+
const span = times[times.length - 1] - times[0];
|
| 231 |
+
const perDay = span > 8 * DAY;
|
| 232 |
+
const binMs = perDay ? DAY : HOUR;
|
| 233 |
+
const floor = t => Math.floor(t / binMs) * binMs;
|
| 234 |
+
const t0 = floor(times[0]), t1 = floor(times[times.length - 1]);
|
| 235 |
+
const bins = [];
|
| 236 |
+
for (let t = t0; t <= t1; t += binMs) bins.push({ t, n: 0 });
|
| 237 |
+
for (const t of times) bins[(floor(t) - t0) / binMs].n++;
|
| 238 |
+
const CUM = [];
|
| 239 |
+
bins.reduce((acc, b) => { CUM.push(acc + b.n); return acc + b.n; }, 0);
|
| 240 |
+
|
| 241 |
+
function fmt(t, withHour) {
|
| 242 |
+
const d = new Date(t);
|
| 243 |
+
let s = `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;
|
| 244 |
+
if (d.getUTCFullYear() !== new Date(times[0]).getUTCFullYear() || withHour === "year") s += ` ${d.getUTCFullYear()}`;
|
| 245 |
+
if (withHour === true) s += `, ${String(d.getUTCHours()).padStart(2, "0")}:00`;
|
| 246 |
+
return s;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// 4. Stats row.
|
| 250 |
+
const total = times.length;
|
| 251 |
+
const days = Math.max(span / DAY, 1 / 24);
|
| 252 |
+
const peak = bins.reduce((a, b) => b.n > a.n ? b : a, bins[0]);
|
| 253 |
+
const statDefs = [
|
| 254 |
+
[String(total), "games total"],
|
| 255 |
+
[perDay ? `${Math.round(days)} d` : `${Math.round(span / HOUR)} h`,
|
| 256 |
+
`${fmt(times[0], !perDay)} → ${fmt(times[times.length - 1], !perDay)} UTC`],
|
| 257 |
+
[(total / days).toFixed(1), "games / day, average"],
|
| 258 |
+
[String(peak.n), `peak ${perDay ? "day" : "hour"} (${fmt(peak.t, !perDay)})`],
|
| 259 |
+
];
|
| 260 |
+
document.getElementById("stats").innerHTML = statDefs.map(([n, l]) =>
|
| 261 |
+
`<div class="stat"><div class="n">${n}</div><div class="l">${l}</div></div>`).join("");
|
| 262 |
+
document.getElementById("bars-title").textContent = perDay ? "Games per day" : "Games per hour";
|
| 263 |
+
document.getElementById("bin-th").textContent = perDay ? "Day (UTC)" : "Hour (UTC)";
|
| 264 |
+
|
| 265 |
+
// 5. Shared chart scaffolding.
|
| 266 |
+
const NS = "http://www.w3.org/2000/svg";
|
| 267 |
+
const W = 920, H = 320, n = bins.length;
|
| 268 |
+
function el(name, attrs, parent) {
|
| 269 |
+
const e = document.createElementNS(NS, name);
|
| 270 |
+
for (const k in attrs) e.setAttribute(k, attrs[k]);
|
| 271 |
+
parent.appendChild(e);
|
| 272 |
+
return e;
|
| 273 |
+
}
|
| 274 |
+
function niceMax(v) {
|
| 275 |
+
const p = Math.pow(10, Math.floor(Math.log10(Math.max(v, 1))));
|
| 276 |
+
for (const m of [1, 2, 2.5, 5, 10]) if (m * p >= v) return m * p;
|
| 277 |
+
return 10 * p;
|
| 278 |
+
}
|
| 279 |
+
// Tick every 6h in hourly mode; in daily mode a stride that keeps ≤ 14 labels.
|
| 280 |
+
const stride = perDay ? Math.max(1, Math.ceil(n / 14)) : 1;
|
| 281 |
+
function isTick(i) {
|
| 282 |
+
const d = new Date(bins[i].t);
|
| 283 |
+
if (!perDay) return i === 0 || d.getUTCHours() % 6 === 0;
|
| 284 |
+
return i % stride === 0;
|
| 285 |
+
}
|
| 286 |
+
function tickLabels(i) {
|
| 287 |
+
const d = new Date(bins[i].t);
|
| 288 |
+
if (!perDay) {
|
| 289 |
+
const top = `${String(d.getUTCHours()).padStart(2, "0")}:00`;
|
| 290 |
+
const bottom = (i === 0 || d.getUTCHours() === 0) ? fmt(bins[i].t) : null;
|
| 291 |
+
return [top, bottom];
|
| 292 |
+
}
|
| 293 |
+
const first = i < stride;
|
| 294 |
+
const bottom = (first || d.getUTCDate() <= stride) ? String(d.getUTCFullYear()) : null;
|
| 295 |
+
return [fmt(bins[i].t), bottom];
|
| 296 |
+
}
|
| 297 |
+
function axes(svg, M, yMax, yStep) {
|
| 298 |
+
const plotW = W - M.left - M.right, plotH = H - M.top - M.bottom;
|
| 299 |
+
const y = v => M.top + plotH * (1 - v / yMax);
|
| 300 |
+
for (let v = 0; v <= yMax; v += yStep) {
|
| 301 |
+
el("line", { x1: M.left, x2: W - M.right, y1: y(v), y2: y(v),
|
| 302 |
+
stroke: v === 0 ? "var(--ink-3)" : "var(--grid)", "stroke-width": 1 }, svg);
|
| 303 |
+
el("text", { x: M.left - 8, y: y(v) + 4, "text-anchor": "end", fill: "var(--ink-2)",
|
| 304 |
+
"font-size": "12", style: "font-variant-numeric: tabular-nums" }, svg)
|
| 305 |
+
.textContent = v;
|
| 306 |
+
}
|
| 307 |
+
return { plotW, plotH, y };
|
| 308 |
+
}
|
| 309 |
+
function xTicks(svg, M, xOf, y0) {
|
| 310 |
+
for (let i = 0; i < n; i++) {
|
| 311 |
+
if (!isTick(i)) continue;
|
| 312 |
+
const [top, bottom] = tickLabels(i);
|
| 313 |
+
el("text", { x: xOf(i), y: y0 + 18, "text-anchor": "middle",
|
| 314 |
+
fill: "var(--ink-2)", "font-size": "12" }, svg).textContent = top;
|
| 315 |
+
if (bottom) el("text", { x: xOf(i), y: y0 + 34, "text-anchor": "middle",
|
| 316 |
+
fill: "var(--ink-3)", "font-size": "12" }, svg).textContent = bottom;
|
| 317 |
+
}
|
| 318 |
+
}
|
| 319 |
+
function attachTooltip(svg, tip, html, onEnter, onLeave) {
|
| 320 |
+
const card = svg.closest(".chart-card");
|
| 321 |
+
svg.addEventListener("pointermove", ev => {
|
| 322 |
+
const t = ev.target.closest("[data-i]");
|
| 323 |
+
if (!t) return leave();
|
| 324 |
+
const i = +t.dataset.i;
|
| 325 |
+
tip.innerHTML = html(i);
|
| 326 |
+
tip.style.opacity = 1;
|
| 327 |
+
const box = card.getBoundingClientRect();
|
| 328 |
+
let tx = ev.clientX - box.left + 12;
|
| 329 |
+
if (tx + tip.offsetWidth > box.width - 4) tx = ev.clientX - box.left - tip.offsetWidth - 12;
|
| 330 |
+
tip.style.left = tx + "px";
|
| 331 |
+
tip.style.top = (ev.clientY - box.top - 10) + "px";
|
| 332 |
+
onEnter(i);
|
| 333 |
+
});
|
| 334 |
+
svg.addEventListener("pointerleave", leave);
|
| 335 |
+
function leave() { tip.style.opacity = 0; onLeave(); }
|
| 336 |
+
}
|
| 337 |
+
function setupSvg(svg) {
|
| 338 |
+
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
|
| 339 |
+
svg.setAttribute("width", "100%");
|
| 340 |
+
svg.style.minWidth = "640px";
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
// 6. Bars.
|
| 344 |
+
{
|
| 345 |
+
const svg = document.getElementById("chart1");
|
| 346 |
+
setupSvg(svg);
|
| 347 |
+
const M = { top: 12, right: 8, bottom: 44, left: 40 };
|
| 348 |
+
const yMax = niceMax(peak.n), yStep = niceMax(peak.n) / 4;
|
| 349 |
+
const { plotW, plotH, y } = axes(svg, M, yMax, yStep);
|
| 350 |
+
const step = plotW / n, barW = Math.max(1.5, step - 2);
|
| 351 |
+
bins.forEach((b, i) => {
|
| 352 |
+
const x = M.left + i * step + (step - barW) / 2;
|
| 353 |
+
if (b.n > 0) {
|
| 354 |
+
const top = y(b.n), r = Math.min(4, plotH * b.n / yMax, barW / 2);
|
| 355 |
+
el("path", { d: `M ${x} ${y(0)} V ${top + r} Q ${x} ${top} ${x + r} ${top} H ${x + barW - r} Q ${x + barW} ${top} ${x + barW} ${top + r} V ${y(0)} Z`,
|
| 356 |
+
fill: "var(--series)", "data-i": i }, svg);
|
| 357 |
+
}
|
| 358 |
+
el("rect", { x: M.left + i * step, y: M.top, width: step, height: plotH + M.bottom - 12,
|
| 359 |
+
fill: "transparent", "data-i": i }, svg);
|
| 360 |
+
});
|
| 361 |
+
xTicks(svg, M, i => M.left + (i + 0.5) * step, y(0));
|
| 362 |
+
let hl = null;
|
| 363 |
+
const bar = i => svg.querySelector(`path[data-i="${i}"]`);
|
| 364 |
+
attachTooltip(svg, document.getElementById("tip1"),
|
| 365 |
+
i => `<strong>${bins[i].n} game${bins[i].n === 1 ? "" : "s"}</strong><br>${fmt(bins[i].t, !perDay)} UTC`,
|
| 366 |
+
i => { if (hl !== null && hl !== i && bar(hl)) bar(hl).removeAttribute("fill-opacity");
|
| 367 |
+
hl = i; if (bar(i)) bar(i).setAttribute("fill-opacity", "0.75"); },
|
| 368 |
+
() => { if (hl !== null && bar(hl)) bar(hl).removeAttribute("fill-opacity"); hl = null; });
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
// 7. Cumulative line.
|
| 372 |
+
{
|
| 373 |
+
const svg = document.getElementById("chart2");
|
| 374 |
+
setupSvg(svg);
|
| 375 |
+
const M = { top: 16, right: 56, bottom: 44, left: 48 };
|
| 376 |
+
const yMax = niceMax(total), yStep = yMax / 4;
|
| 377 |
+
const { plotW, plotH, y } = axes(svg, M, yMax, yStep);
|
| 378 |
+
const x = i => M.left + (i + 0.5) * plotW / n;
|
| 379 |
+
xTicks(svg, M, x, y(0));
|
| 380 |
+
const pts = CUM.map((v, i) => `${x(i)},${y(v)}`).join(" ");
|
| 381 |
+
el("polygon", { points: `${x(0)},${y(0)} ${pts} ${x(n - 1)},${y(0)}`, fill: "var(--series-soft)" }, svg);
|
| 382 |
+
el("polyline", { points: pts, fill: "none", stroke: "var(--series)",
|
| 383 |
+
"stroke-width": 2, "stroke-linejoin": "round" }, svg);
|
| 384 |
+
el("circle", { cx: x(n - 1), cy: y(total), r: 4, fill: "var(--series)",
|
| 385 |
+
stroke: "var(--surface)", "stroke-width": 2 }, svg);
|
| 386 |
+
el("text", { x: x(n - 1) + 10, y: y(total) + 4, fill: "var(--ink)", "font-size": "13",
|
| 387 |
+
"font-weight": "600", style: "font-variant-numeric: tabular-nums" }, svg)
|
| 388 |
+
.textContent = total;
|
| 389 |
+
const cross = el("line", { y1: M.top, y2: y(0), stroke: "var(--ink-3)", "stroke-width": 1,
|
| 390 |
+
"stroke-dasharray": "3 3", opacity: 0 }, svg);
|
| 391 |
+
const dot = el("circle", { r: 4.5, fill: "var(--series)", stroke: "var(--surface)",
|
| 392 |
+
"stroke-width": 2, opacity: 0 }, svg);
|
| 393 |
+
bins.forEach((_, i) => {
|
| 394 |
+
el("rect", { x: M.left + i * plotW / n, y: M.top, width: plotW / n,
|
| 395 |
+
height: plotH + M.bottom - 12, fill: "transparent", "data-i": i }, svg);
|
| 396 |
+
});
|
| 397 |
+
attachTooltip(svg, document.getElementById("tip2"),
|
| 398 |
+
i => `<strong>${CUM[i]} games total</strong><br>by end of ${fmt(bins[i].t, !perDay)} UTC`,
|
| 399 |
+
i => { cross.setAttribute("x1", x(i)); cross.setAttribute("x2", x(i)); cross.setAttribute("opacity", 1);
|
| 400 |
+
dot.setAttribute("cx", x(i)); dot.setAttribute("cy", y(CUM[i])); dot.setAttribute("opacity", 1); },
|
| 401 |
+
() => { cross.setAttribute("opacity", 0); dot.setAttribute("opacity", 0); });
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// 8. Table + footer.
|
| 405 |
+
const tbody = document.querySelector("#data-table tbody");
|
| 406 |
+
tbody.innerHTML = bins.map((b, i) =>
|
| 407 |
+
`<tr><td>${fmt(b.t, !perDay)}</td><td>${b.n}</td><td>${CUM[i]}</td></tr>`).join("");
|
| 408 |
+
const now = new Date();
|
| 409 |
+
document.getElementById("foot").innerHTML =
|
| 410 |
+
`Latest shared game: ${fmt(times[times.length - 1], "year")}, ` +
|
| 411 |
+
`${String(new Date(times[times.length - 1]).getUTCHours()).padStart(2, "0")}:${String(new Date(times[times.length - 1]).getUTCMinutes()).padStart(2, "0")} UTC · ` +
|
| 412 |
+
`listing fetched ${now.toUTCString().replace(":" + String(now.getUTCSeconds()).padStart(2, "0") + " GMT", " UTC")} · reload to refresh.`;
|
| 413 |
+
|
| 414 |
+
status.classList.add("hidden");
|
| 415 |
+
document.getElementById("content").classList.remove("hidden");
|
| 416 |
+
})();
|
| 417 |
+
</script>
|
| 418 |
+
</body>
|
| 419 |
</html>
|