| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8" /> |
| <title>Paper Universe 3D Viewer</title> |
| <style> |
| html, body { margin:0; padding:0; width:100%; height:100%; overflow:hidden; background:#07111f; color:#e2e8f0; } |
| #app { position:fixed; inset:0; } |
| #controls { |
| position: fixed; |
| top: 10px; |
| left: 10px; |
| z-index: 10; |
| background: rgba(255,255,255,0.92); |
| color:#0f172a; |
| padding: 10px 12px; |
| border-radius: 10px; |
| font-family: sans-serif; |
| display:flex; |
| flex-wrap:wrap; |
| gap:8px; |
| align-items:center; |
| max-width: calc(100vw - 24px); |
| box-shadow: 0 18px 45px rgba(2, 8, 23, 0.20); |
| } |
| #status { |
| min-width: 280px; |
| color:#334155; |
| } |
| select, input { |
| border: 1px solid #cbd5e1; |
| border-radius: 6px; |
| padding: 4px 6px; |
| background: white; |
| } |
| .hint { |
| color:#475569; |
| font-size: 12px; |
| } |
| </style> |
| <script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script> |
| </head> |
| <body> |
| <div id="controls"> |
| <label for="viewMode">View:</label> |
| <select id="viewMode"> |
| <option value="papers">Papers</option> |
| <option value="categories">Categories</option> |
| <option value="papers+categories" selected>Papers + Categories</option> |
| <option value="all">All</option> |
| </select> |
| <label for="paperLevel">Paper LOD:</label> |
| <select id="paperLevel"></select> |
| <label for="colorMode">Color:</label> |
| <select id="colorMode"> |
| <option value="category" selected>Primary Category</option> |
| <option value="year">Year</option> |
| <option value="uniform">Uniform</option> |
| </select> |
| <label for="categoryFilter">Filter Category:</label> |
| <select id="categoryFilter"> |
| <option value="">All Categories</option> |
| </select> |
| <span class="hint">Click a category anchor to filter papers.</span> |
| <span id="status">loading…</span> |
| </div> |
| <div id="app"></div> |
| <script> |
| const {Deck, ScatterplotLayer, TextLayer, OrbitView, OrbitController} = deck; |
| const assetRoot = './interactive/'; |
| const viewModeEl = document.getElementById('viewMode'); |
| const paperLevelEl = document.getElementById('paperLevel'); |
| const colorModeEl = document.getElementById('colorMode'); |
| const categoryFilterEl = document.getElementById('categoryFilter'); |
| const statusEl = document.getElementById('status'); |
| let deckgl = null; |
| let manifest = null; |
| let cached = {}; |
| let currentViewState = null; |
| |
| function hashColor(str) { |
| let h = 0; |
| for (let i = 0; i < str.length; i++) h = (h * 31 + str.charCodeAt(i)) | 0; |
| const r = (Math.abs(h) % 160) + 60; |
| const g = (Math.abs(h >> 8) % 160) + 60; |
| const b = (Math.abs(h >> 16) % 160) + 60; |
| return [r, g, b]; |
| } |
| |
| function yearColor(year) { |
| const y = Number(year || 0); |
| const base = ((y % 17) * 13) % 255; |
| return [40 + (base % 180), 120 + ((base * 2) % 100), 255 - (base % 120)]; |
| } |
| |
| function paperColor(row) { |
| if (colorModeEl.value === 'uniform') return [29, 78, 216]; |
| if (colorModeEl.value === 'year') return yearColor(row.year); |
| return hashColor(row.primary_category || 'unknown'); |
| } |
| |
| function categoryColor(row) { |
| return hashColor(row.category_id || 'category'); |
| } |
| |
| async function loadJson(path) { |
| if (!cached[path]) { |
| cached[path] = fetch(path).then(r => r.json()); |
| } |
| return cached[path]; |
| } |
| |
| async function ensureManifest() { |
| if (!manifest) { |
| manifest = await loadJson(assetRoot + 'manifest.json'); |
| for (const level of manifest.paper_levels) { |
| const opt = document.createElement('option'); |
| opt.value = level.path; |
| opt.textContent = level.label; |
| paperLevelEl.appendChild(opt); |
| } |
| const cats = await loadJson(assetRoot + manifest.categories.path); |
| for (const row of cats) { |
| const opt = document.createElement('option'); |
| opt.value = row.category_id; |
| opt.textContent = `${row.category_id} (${row.paper_count.toLocaleString()})`; |
| categoryFilterEl.appendChild(opt); |
| } |
| } |
| return manifest; |
| } |
| |
| function ensureDeck() { |
| if (deckgl) return deckgl; |
| deckgl = new Deck({ |
| parent: document.getElementById('app'), |
| views: [new OrbitView({orbitAxis: 'Z'})], |
| controller: new OrbitController(), |
| initialViewState: {target: [0, 0, 0], rotationX: 25, rotationOrbit: 35, zoom: 0.2}, |
| getTooltip: ({object, layer}) => { |
| if (!object) return null; |
| if (layer && layer.id === 'papers') { |
| return { |
| html: `<b>${object.title || object.canonical_paper_id}</b><br/>${object.primary_category || 'unknown'}<br/>year: ${object.year || 'n/a'}`, |
| style: {backgroundColor: 'rgba(15, 23, 42, 0.92)', color: '#f8fafc'} |
| }; |
| } |
| if (layer && layer.id === 'categories') { |
| return { |
| html: `<b>${object.category_id}</b><br/>papers: ${(object.paper_count || 0).toLocaleString()}`, |
| style: {backgroundColor: 'rgba(15, 23, 42, 0.92)', color: '#f8fafc'} |
| }; |
| } |
| if (layer && layer.id === 'years') { |
| return { |
| html: `<b>${object.year}</b><br/>papers: ${(object.paper_count || 0).toLocaleString()}`, |
| style: {backgroundColor: 'rgba(15, 23, 42, 0.92)', color: '#f8fafc'} |
| }; |
| } |
| return null; |
| } |
| }); |
| return deckgl; |
| } |
| |
| function maybeResetView(rows) { |
| if (currentViewState || !rows.length) return; |
| const xs = rows.map(r => r.x); |
| const ys = rows.map(r => r.y); |
| const zs = rows.map(r => r.z); |
| const center = [ |
| (Math.min(...xs) + Math.max(...xs)) / 2, |
| (Math.min(...ys) + Math.max(...ys)) / 2, |
| (Math.min(...zs) + Math.max(...zs)) / 2 |
| ]; |
| currentViewState = {target: center, rotationX: 25, rotationOrbit: 35, zoom: 0.2}; |
| ensureDeck().setProps({initialViewState: currentViewState}); |
| } |
| |
| async function render() { |
| const man = await ensureManifest(); |
| const paperPath = assetRoot + paperLevelEl.value; |
| const papersRaw = await loadJson(paperPath); |
| const categories = await loadJson(assetRoot + man.categories.path); |
| const years = await loadJson(assetRoot + man.years.path); |
| const activeView = viewModeEl.value; |
| const categoryFilter = categoryFilterEl.value; |
| const papers = categoryFilter ? papersRaw.filter(r => r.primary_category === categoryFilter) : papersRaw; |
| maybeResetView(papers.length ? papers : categories); |
| |
| const showPapers = activeView === 'papers' || activeView === 'papers+categories' || activeView === 'all'; |
| const showCategories = activeView === 'categories' || activeView === 'papers+categories' || activeView === 'all'; |
| const showYears = activeView === 'all'; |
| |
| const layers = []; |
| if (showPapers) { |
| layers.push(new ScatterplotLayer({ |
| id: 'papers', |
| data: papers, |
| pickable: true, |
| opacity: 0.28, |
| radiusUnits: 'pixels', |
| getPosition: d => [d.x, d.y, d.z], |
| getRadius: _ => 1.1, |
| getFillColor: d => [...paperColor(d), 190], |
| radiusMinPixels: 1, |
| radiusMaxPixels: 3 |
| })); |
| } |
| if (showCategories) { |
| layers.push(new ScatterplotLayer({ |
| id: 'categories', |
| data: categories, |
| pickable: true, |
| opacity: 0.95, |
| radiusUnits: 'pixels', |
| getPosition: d => [d.x, d.y, d.z], |
| getRadius: d => Math.max(6, Math.min(18, 6 + Math.log10((d.paper_count || 1) + 1) * 3)), |
| getFillColor: d => [...categoryColor(d), 235], |
| onClick: info => { |
| if (info.object) { |
| categoryFilterEl.value = info.object.category_id || ''; |
| render(); |
| } |
| } |
| })); |
| layers.push(new TextLayer({ |
| id: 'category-labels', |
| data: categories.slice(0, 48), |
| pickable: false, |
| getPosition: d => [d.x, d.y, d.z], |
| getText: d => d.category_id, |
| getColor: _ => [15, 23, 42, 255], |
| getSize: _ => 14, |
| sizeUnits: 'pixels', |
| getTextAnchor: _ => 'start', |
| getAlignmentBaseline: _ => 'center' |
| })); |
| } |
| if (showYears) { |
| layers.push(new ScatterplotLayer({ |
| id: 'years', |
| data: years, |
| pickable: true, |
| opacity: 0.95, |
| radiusUnits: 'pixels', |
| getPosition: d => [d.x, d.y, d.z], |
| getRadius: _ => 8, |
| getFillColor: d => [...yearColor(d.year), 240] |
| })); |
| layers.push(new TextLayer({ |
| id: 'year-labels', |
| data: years, |
| pickable: false, |
| getPosition: d => [d.x, d.y, d.z], |
| getText: d => String(d.year), |
| getColor: _ => [6, 78, 59, 255], |
| getSize: _ => 14, |
| sizeUnits: 'pixels', |
| getTextAnchor: _ => 'middle', |
| getAlignmentBaseline: _ => 'center' |
| })); |
| } |
| |
| ensureDeck().setProps({ |
| layers, |
| onViewStateChange: ({viewState}) => { |
| currentViewState = viewState; |
| } |
| }); |
| statusEl.textContent = `papers shown: ${papers.length.toLocaleString()} | categories: ${categories.length.toLocaleString()} | years: ${years.length.toLocaleString()}`; |
| } |
| |
| viewModeEl.addEventListener('change', render); |
| paperLevelEl.addEventListener('change', render); |
| colorModeEl.addEventListener('change', render); |
| categoryFilterEl.addEventListener('change', render); |
| ensureManifest().then(() => render()); |
| </script> |
| </body> |
| </html> |
|
|