Download nodes_3d_sample.html from PeytonT/paper_universe_interactive: direct link, hf CLI and curl.
- Browser
- Download file 15.3 kB
-
https://huggingface.co/datasets/PeytonT/paper_universe_interactive/resolve/main/nodes_3d_sample.html
- Command line
-
hf download hf://datasets/PeytonT/paper_universe_interactive/nodes_3d_sample.html
-
curl -L -o nodes_3d_sample.html https://huggingface.co/datasets/PeytonT/paper_universe_interactive/resolve/main/nodes_3d_sample.html
15.3 kB
| <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" selected>Paper Nodes</option> | |
| <option value="papers+categories">Paper Nodes + Category Anchors</option> | |
| <option value="all">Paper Nodes + Category + Year Anchors</option> | |
| <option value="categories">Category Anchors Only</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">Double-click a paper node to load it in the library. Click a category anchor to filter visible paper nodes.</span> | |
| <span id="status">loading…</span> | |
| </div> | |
| <div id="app"></div> | |
| <script> | |
| const {Deck, ScatterplotLayer, TextLayer, OrbitView} = 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; | |
| let selectionBridgeBound = false; | |
| function clampNumber(value, minValue, maxValue) { | |
| return Math.min(maxValue, Math.max(minValue, value)); | |
| } | |
| function buildDisplayTransform(rows) { | |
| if (!Array.isArray(rows) || !rows.length) { | |
| return {cx: 0, cy: 0, cz: 0, scale: 1}; | |
| } | |
| let minX = Infinity, minY = Infinity, minZ = Infinity; | |
| let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity; | |
| for (const row of rows) { | |
| const x = Number(row.x || 0); | |
| const y = Number(row.y || 0); | |
| const z = Number(row.z || 0); | |
| minX = Math.min(minX, x); maxX = Math.max(maxX, x); | |
| minY = Math.min(minY, y); maxY = Math.max(maxY, y); | |
| minZ = Math.min(minZ, z); maxZ = Math.max(maxZ, z); | |
| } | |
| const span = Math.max(maxX - minX, maxY - minY, maxZ - minZ, 1e-3); | |
| return { | |
| cx: (minX + maxX) / 2, | |
| cy: (minY + maxY) / 2, | |
| cz: (minZ + maxZ) / 2, | |
| scale: 14 / span | |
| }; | |
| } | |
| function withDisplayPositions(rows, transform) { | |
| return (rows || []).map(row => { | |
| row.__display_position = [ | |
| (Number(row.x || 0) - transform.cx) * transform.scale, | |
| (Number(row.y || 0) - transform.cy) * transform.scale, | |
| (Number(row.z || 0) - transform.cz) * transform.scale, | |
| ]; | |
| return row; | |
| }); | |
| } | |
| function computeInitialViewState(rows) { | |
| if (!Array.isArray(rows) || !rows.length) { | |
| return {target: [0, 0, 0], rotationX: 25, rotationOrbit: 35, zoom: 4.0}; | |
| } | |
| let minX = Infinity, minY = Infinity, minZ = Infinity; | |
| let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity; | |
| for (const row of rows) { | |
| const pos = Array.isArray(row.__display_position) | |
| ? row.__display_position | |
| : [Number(row.x || 0), Number(row.y || 0), Number(row.z || 0)]; | |
| minX = Math.min(minX, pos[0]); maxX = Math.max(maxX, pos[0]); | |
| minY = Math.min(minY, pos[1]); maxY = Math.max(maxY, pos[1]); | |
| minZ = Math.min(minZ, pos[2]); maxZ = Math.max(maxZ, pos[2]); | |
| } | |
| const app = document.getElementById('app'); | |
| const rect = app ? app.getBoundingClientRect() : null; | |
| const viewport = Math.max(320, Math.min( | |
| (rect && rect.width) || window.innerWidth || 900, | |
| (rect && rect.height) || window.innerHeight || 640 | |
| )); | |
| const span = Math.max(maxX - minX, maxY - minY, maxZ - minZ, 1e-3); | |
| const zoom = clampNumber(Math.log2(viewport / (span * 1.2)), 0.5, 8.0); | |
| return { | |
| target: [(minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2], | |
| rotationX: 25, | |
| rotationOrbit: 35, | |
| zoom | |
| }; | |
| } | |
| 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'); | |
| } | |
| function acknowledgePaperSelection(row) { | |
| if (!row || !statusEl) return; | |
| const title = row.title || row.canonical_paper_id || row.paper_id || 'paper'; | |
| const category = row.primary_category ? ` · ${row.primary_category}` : ''; | |
| statusEl.textContent = `paper selected: ${title}${category} · loading in library…`; | |
| statusEl.style.color = '#0f766e'; | |
| window.setTimeout(() => { | |
| if (statusEl.textContent.startsWith('paper selected:')) { | |
| statusEl.style.color = '#334155'; | |
| } | |
| }, 1800); | |
| } | |
| function emitPaperSelection(row) { | |
| if (!row || !window.parent || window.parent === window) return; | |
| acknowledgePaperSelection(row); | |
| try { | |
| window.parent.postMessage( | |
| { | |
| type: 'paper_universe_select_paper', | |
| paper: { | |
| paper_id: row.paper_id || '', | |
| canonical_paper_id: row.canonical_paper_id || '', | |
| title: row.title || '', | |
| primary_category: row.primary_category || '', | |
| year: row.year || 0 | |
| } | |
| }, | |
| window.location.origin | |
| ); | |
| } catch (err) { | |
| console.warn('failed to emit paper selection', err); | |
| } | |
| } | |
| 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: {doubleClickZoom: false}})], | |
| initialViewState: currentViewState || {target: [0, 0, 0], rotationX: 25, rotationOrbit: 35, zoom: 4.0}, | |
| 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; | |
| } | |
| }); | |
| if (!selectionBridgeBound) { | |
| const canvas = deckgl.canvas || document.querySelector('#app canvas'); | |
| if (canvas) { | |
| canvas.addEventListener( | |
| 'dblclick', | |
| event => { | |
| event.preventDefault(); | |
| event.stopPropagation(); | |
| const rect = canvas.getBoundingClientRect(); | |
| const info = deckgl.pickObject({ | |
| x: event.clientX - rect.left, | |
| y: event.clientY - rect.top, | |
| radius: 8, | |
| layerIds: ['papers'] | |
| }); | |
| if (info && info.object) { | |
| acknowledgePaperSelection(info.object); | |
| emitPaperSelection(info.object); | |
| } | |
| }, | |
| true | |
| ); | |
| selectionBridgeBound = true; | |
| } | |
| } | |
| return deckgl; | |
| } | |
| function maybeResetView(rows) { | |
| if (currentViewState || !rows.length) return; | |
| currentViewState = computeInitialViewState(rows); | |
| ensureDeck().setProps({viewState: 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; | |
| const showPapers = activeView === 'papers' || activeView === 'papers+categories' || activeView === 'all'; | |
| const showCategories = activeView === 'categories' || activeView === 'papers+categories' || activeView === 'all'; | |
| const showYears = activeView === 'all'; | |
| const fitRows = [ | |
| ...(showPapers ? papers : []), | |
| ...(showCategories ? categories : []), | |
| ...(showYears ? years : []), | |
| ]; | |
| const displayTransform = buildDisplayTransform(fitRows.length ? fitRows : (papers.length ? papers : categories)); | |
| const displayPapers = withDisplayPositions(papers, displayTransform); | |
| const displayCategories = withDisplayPositions(categories, displayTransform); | |
| const displayYears = withDisplayPositions(years, displayTransform); | |
| maybeResetView(fitRows.length ? withDisplayPositions(fitRows, displayTransform) : displayPapers); | |
| const layers = []; | |
| if (showPapers) { | |
| layers.push(new ScatterplotLayer({ | |
| id: 'papers', | |
| data: displayPapers, | |
| pickable: true, | |
| opacity: 0.36, | |
| radiusUnits: 'pixels', | |
| getPosition: d => d.__display_position, | |
| getRadius: _ => 1.3, | |
| getFillColor: d => [...paperColor(d), 205], | |
| radiusMinPixels: 1, | |
| radiusMaxPixels: 4, | |
| onClick: info => { | |
| if (info.object) { | |
| acknowledgePaperSelection(info.object); | |
| emitPaperSelection(info.object); | |
| } | |
| } | |
| })); | |
| } | |
| if (showCategories) { | |
| layers.push(new ScatterplotLayer({ | |
| id: 'categories', | |
| data: displayCategories, | |
| pickable: true, | |
| opacity: 0.9, | |
| radiusUnits: 'pixels', | |
| getPosition: d => d.__display_position, | |
| getRadius: d => Math.max(5, Math.min(14, 5 + Math.log10((d.paper_count || 1) + 1) * 2.5)), | |
| 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: displayCategories.slice(0, 48), | |
| pickable: false, | |
| getPosition: d => d.__display_position, | |
| 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: displayYears, | |
| pickable: true, | |
| opacity: 0.95, | |
| radiusUnits: 'pixels', | |
| getPosition: d => d.__display_position, | |
| getRadius: _ => 8, | |
| getFillColor: d => [...yearColor(d.year), 240] | |
| })); | |
| layers.push(new TextLayer({ | |
| id: 'year-labels', | |
| data: displayYears, | |
| pickable: false, | |
| getPosition: d => d.__display_position, | |
| getText: d => String(d.year), | |
| getColor: _ => [6, 78, 59, 255], | |
| getSize: _ => 14, | |
| sizeUnits: 'pixels', | |
| getTextAnchor: _ => 'middle', | |
| getAlignmentBaseline: _ => 'center' | |
| })); | |
| } | |
| ensureDeck().setProps({ | |
| layers, | |
| viewState: currentViewState || undefined, | |
| onViewStateChange: ({viewState}) => { | |
| currentViewState = viewState; | |
| deckgl.setProps({viewState}); | |
| } | |
| }); | |
| statusEl.textContent = `paper nodes: ${papers.length.toLocaleString()} | category anchors: ${categories.length.toLocaleString()} | year anchors: ${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> | |