PeytonT commited on
Commit
c8c79cd
·
verified ·
1 Parent(s): 826afd3

Upload universe_3d_hover.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. universe_3d_hover.html +281 -0
universe_3d_hover.html ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Paper Universe 3D Viewer</title>
6
+ <style>
7
+ html, body { margin:0; padding:0; width:100%; height:100%; overflow:hidden; background:#07111f; color:#e2e8f0; }
8
+ #app { position:fixed; inset:0; }
9
+ #controls {
10
+ position: fixed;
11
+ top: 10px;
12
+ left: 10px;
13
+ z-index: 10;
14
+ background: rgba(255,255,255,0.92);
15
+ color:#0f172a;
16
+ padding: 10px 12px;
17
+ border-radius: 10px;
18
+ font-family: sans-serif;
19
+ display:flex;
20
+ flex-wrap:wrap;
21
+ gap:8px;
22
+ align-items:center;
23
+ max-width: calc(100vw - 24px);
24
+ box-shadow: 0 18px 45px rgba(2, 8, 23, 0.20);
25
+ }
26
+ #status {
27
+ min-width: 280px;
28
+ color:#334155;
29
+ }
30
+ select, input {
31
+ border: 1px solid #cbd5e1;
32
+ border-radius: 6px;
33
+ padding: 4px 6px;
34
+ background: white;
35
+ }
36
+ .hint {
37
+ color:#475569;
38
+ font-size: 12px;
39
+ }
40
+ </style>
41
+ <script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
42
+ </head>
43
+ <body>
44
+ <div id="controls">
45
+ <label for="viewMode">View:</label>
46
+ <select id="viewMode">
47
+ <option value="papers">Papers</option>
48
+ <option value="categories">Categories</option>
49
+ <option value="papers+categories" selected>Papers + Categories</option>
50
+ <option value="all">All</option>
51
+ </select>
52
+ <label for="paperLevel">Paper LOD:</label>
53
+ <select id="paperLevel"></select>
54
+ <label for="colorMode">Color:</label>
55
+ <select id="colorMode">
56
+ <option value="category" selected>Primary Category</option>
57
+ <option value="year">Year</option>
58
+ <option value="uniform">Uniform</option>
59
+ </select>
60
+ <label for="categoryFilter">Filter Category:</label>
61
+ <select id="categoryFilter">
62
+ <option value="">All Categories</option>
63
+ </select>
64
+ <span class="hint">Click a category anchor to filter papers.</span>
65
+ <span id="status">loading…</span>
66
+ </div>
67
+ <div id="app"></div>
68
+ <script>
69
+ const {Deck, ScatterplotLayer, TextLayer, OrbitView, OrbitController} = deck;
70
+ const assetRoot = './interactive/';
71
+ const viewModeEl = document.getElementById('viewMode');
72
+ const paperLevelEl = document.getElementById('paperLevel');
73
+ const colorModeEl = document.getElementById('colorMode');
74
+ const categoryFilterEl = document.getElementById('categoryFilter');
75
+ const statusEl = document.getElementById('status');
76
+ let deckgl = null;
77
+ let manifest = null;
78
+ let cached = {};
79
+ let currentViewState = null;
80
+
81
+ function hashColor(str) {
82
+ let h = 0;
83
+ for (let i = 0; i < str.length; i++) h = (h * 31 + str.charCodeAt(i)) | 0;
84
+ const r = (Math.abs(h) % 160) + 60;
85
+ const g = (Math.abs(h >> 8) % 160) + 60;
86
+ const b = (Math.abs(h >> 16) % 160) + 60;
87
+ return [r, g, b];
88
+ }
89
+
90
+ function yearColor(year) {
91
+ const y = Number(year || 0);
92
+ const base = ((y % 17) * 13) % 255;
93
+ return [40 + (base % 180), 120 + ((base * 2) % 100), 255 - (base % 120)];
94
+ }
95
+
96
+ function paperColor(row) {
97
+ if (colorModeEl.value === 'uniform') return [29, 78, 216];
98
+ if (colorModeEl.value === 'year') return yearColor(row.year);
99
+ return hashColor(row.primary_category || 'unknown');
100
+ }
101
+
102
+ function categoryColor(row) {
103
+ return hashColor(row.category_id || 'category');
104
+ }
105
+
106
+ async function loadJson(path) {
107
+ if (!cached[path]) {
108
+ cached[path] = fetch(path).then(r => r.json());
109
+ }
110
+ return cached[path];
111
+ }
112
+
113
+ async function ensureManifest() {
114
+ if (!manifest) {
115
+ manifest = await loadJson(assetRoot + 'manifest.json');
116
+ for (const level of manifest.paper_levels) {
117
+ const opt = document.createElement('option');
118
+ opt.value = level.path;
119
+ opt.textContent = level.label;
120
+ paperLevelEl.appendChild(opt);
121
+ }
122
+ const cats = await loadJson(assetRoot + manifest.categories.path);
123
+ for (const row of cats) {
124
+ const opt = document.createElement('option');
125
+ opt.value = row.category_id;
126
+ opt.textContent = `${row.category_id} (${row.paper_count.toLocaleString()})`;
127
+ categoryFilterEl.appendChild(opt);
128
+ }
129
+ }
130
+ return manifest;
131
+ }
132
+
133
+ function ensureDeck() {
134
+ if (deckgl) return deckgl;
135
+ deckgl = new Deck({
136
+ parent: document.getElementById('app'),
137
+ views: [new OrbitView({orbitAxis: 'Z'})],
138
+ controller: new OrbitController(),
139
+ initialViewState: {target: [0, 0, 0], rotationX: 25, rotationOrbit: 35, zoom: 0.2},
140
+ getTooltip: ({object, layer}) => {
141
+ if (!object) return null;
142
+ if (layer && layer.id === 'papers') {
143
+ return {
144
+ html: `<b>${object.title || object.canonical_paper_id}</b><br/>${object.primary_category || 'unknown'}<br/>year: ${object.year || 'n/a'}`,
145
+ style: {backgroundColor: 'rgba(15, 23, 42, 0.92)', color: '#f8fafc'}
146
+ };
147
+ }
148
+ if (layer && layer.id === 'categories') {
149
+ return {
150
+ html: `<b>${object.category_id}</b><br/>papers: ${(object.paper_count || 0).toLocaleString()}`,
151
+ style: {backgroundColor: 'rgba(15, 23, 42, 0.92)', color: '#f8fafc'}
152
+ };
153
+ }
154
+ if (layer && layer.id === 'years') {
155
+ return {
156
+ html: `<b>${object.year}</b><br/>papers: ${(object.paper_count || 0).toLocaleString()}`,
157
+ style: {backgroundColor: 'rgba(15, 23, 42, 0.92)', color: '#f8fafc'}
158
+ };
159
+ }
160
+ return null;
161
+ }
162
+ });
163
+ return deckgl;
164
+ }
165
+
166
+ function maybeResetView(rows) {
167
+ if (currentViewState || !rows.length) return;
168
+ const xs = rows.map(r => r.x);
169
+ const ys = rows.map(r => r.y);
170
+ const zs = rows.map(r => r.z);
171
+ const center = [
172
+ (Math.min(...xs) + Math.max(...xs)) / 2,
173
+ (Math.min(...ys) + Math.max(...ys)) / 2,
174
+ (Math.min(...zs) + Math.max(...zs)) / 2
175
+ ];
176
+ currentViewState = {target: center, rotationX: 25, rotationOrbit: 35, zoom: 0.2};
177
+ ensureDeck().setProps({initialViewState: currentViewState});
178
+ }
179
+
180
+ async function render() {
181
+ const man = await ensureManifest();
182
+ const paperPath = assetRoot + paperLevelEl.value;
183
+ const papersRaw = await loadJson(paperPath);
184
+ const categories = await loadJson(assetRoot + man.categories.path);
185
+ const years = await loadJson(assetRoot + man.years.path);
186
+ const activeView = viewModeEl.value;
187
+ const categoryFilter = categoryFilterEl.value;
188
+ const papers = categoryFilter ? papersRaw.filter(r => r.primary_category === categoryFilter) : papersRaw;
189
+ maybeResetView(papers.length ? papers : categories);
190
+
191
+ const showPapers = activeView === 'papers' || activeView === 'papers+categories' || activeView === 'all';
192
+ const showCategories = activeView === 'categories' || activeView === 'papers+categories' || activeView === 'all';
193
+ const showYears = activeView === 'all';
194
+
195
+ const layers = [];
196
+ if (showPapers) {
197
+ layers.push(new ScatterplotLayer({
198
+ id: 'papers',
199
+ data: papers,
200
+ pickable: true,
201
+ opacity: 0.28,
202
+ radiusUnits: 'pixels',
203
+ getPosition: d => [d.x, d.y, d.z],
204
+ getRadius: _ => 1.1,
205
+ getFillColor: d => [...paperColor(d), 190],
206
+ radiusMinPixels: 1,
207
+ radiusMaxPixels: 3
208
+ }));
209
+ }
210
+ if (showCategories) {
211
+ layers.push(new ScatterplotLayer({
212
+ id: 'categories',
213
+ data: categories,
214
+ pickable: true,
215
+ opacity: 0.95,
216
+ radiusUnits: 'pixels',
217
+ getPosition: d => [d.x, d.y, d.z],
218
+ getRadius: d => Math.max(6, Math.min(18, 6 + Math.log10((d.paper_count || 1) + 1) * 3)),
219
+ getFillColor: d => [...categoryColor(d), 235],
220
+ onClick: info => {
221
+ if (info.object) {
222
+ categoryFilterEl.value = info.object.category_id || '';
223
+ render();
224
+ }
225
+ }
226
+ }));
227
+ layers.push(new TextLayer({
228
+ id: 'category-labels',
229
+ data: categories.slice(0, 48),
230
+ pickable: false,
231
+ getPosition: d => [d.x, d.y, d.z],
232
+ getText: d => d.category_id,
233
+ getColor: _ => [15, 23, 42, 255],
234
+ getSize: _ => 14,
235
+ sizeUnits: 'pixels',
236
+ getTextAnchor: _ => 'start',
237
+ getAlignmentBaseline: _ => 'center'
238
+ }));
239
+ }
240
+ if (showYears) {
241
+ layers.push(new ScatterplotLayer({
242
+ id: 'years',
243
+ data: years,
244
+ pickable: true,
245
+ opacity: 0.95,
246
+ radiusUnits: 'pixels',
247
+ getPosition: d => [d.x, d.y, d.z],
248
+ getRadius: _ => 8,
249
+ getFillColor: d => [...yearColor(d.year), 240]
250
+ }));
251
+ layers.push(new TextLayer({
252
+ id: 'year-labels',
253
+ data: years,
254
+ pickable: false,
255
+ getPosition: d => [d.x, d.y, d.z],
256
+ getText: d => String(d.year),
257
+ getColor: _ => [6, 78, 59, 255],
258
+ getSize: _ => 14,
259
+ sizeUnits: 'pixels',
260
+ getTextAnchor: _ => 'middle',
261
+ getAlignmentBaseline: _ => 'center'
262
+ }));
263
+ }
264
+
265
+ ensureDeck().setProps({
266
+ layers,
267
+ onViewStateChange: ({viewState}) => {
268
+ currentViewState = viewState;
269
+ }
270
+ });
271
+ statusEl.textContent = `papers shown: ${papers.length.toLocaleString()} | categories: ${categories.length.toLocaleString()} | years: ${years.length.toLocaleString()}`;
272
+ }
273
+
274
+ viewModeEl.addEventListener('change', render);
275
+ paperLevelEl.addEventListener('change', render);
276
+ colorModeEl.addEventListener('change', render);
277
+ categoryFilterEl.addEventListener('change', render);
278
+ ensureManifest().then(() => render());
279
+ </script>
280
+ </body>
281
+ </html>