-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks-app.js
More file actions
300 lines (257 loc) · 9.43 KB
/
Copy pathbenchmarks-app.js
File metadata and controls
300 lines (257 loc) · 9.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// ============ Benchmarks App ============
let bmData = null;
let currentFilter = 'all';
let currentSearch = '';
let currentView = 'tree';
const arrowSvg = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>`;
const modalityIcons = {
image: '🖼️', audio: '🔊', text: '📝', video: '🎬', others: '🔮',
'image+text': '🖼️📝', 'audio+text': '🔊📝', 'video+text': '🎬📝',
};
function getModalityIcon(modality) {
return modalityIcons[modality] || '📦';
}
function getModalityBadgeClass(modality) {
const base = modality.split('+')[0];
return ['image','audio','text','video','others'].includes(base) ? base : 'others';
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function highlightText(text, search) {
if (!search) return escapeHtml(text);
const escaped = escapeHtml(text);
const regex = new RegExp(`(${search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
return escaped.replace(regex, '<span class="bm-highlight">$1</span>');
}
// ============ Tree View ============
function renderTree() {
const container = document.getElementById('treeView');
if (!bmData) return;
const tree = bmData.tree;
const search = currentSearch.toLowerCase();
let html = '';
let hasResults = false;
for (const l1 of Object.keys(tree)) {
if (currentFilter !== 'all' && l1 !== currentFilter) continue;
const l1Class = l1 === 'understanding' ? 'understand' : 'generate';
const l1Icon = l1 === 'understanding' ? '🔍' : '✨';
let l2Html = '';
let l1TaskCount = 0;
for (const l2 of Object.keys(tree[l1])) {
const l2Icon = l2 === 'single modal' ? '○' : '◆';
let l3Html = '';
let l2TaskCount = 0;
for (const l3 of Object.keys(tree[l1][l2])) {
const tasks = tree[l1][l2][l3];
let taskHtml = '';
let matchedTasks = 0;
for (const task of tasks) {
if (search) {
const searchable = [l1, l2, l3, task.task, ...task.benchmarks].join(' ').toLowerCase();
if (!searchable.includes(search)) continue;
}
matchedTasks++;
const chips = task.benchmarks.map(b =>
`<span class="bm-chip">${highlightText(b, currentSearch)}</span>`
).join('');
taskHtml += `
<div class="bm-task">
<div class="bm-task-name">${highlightText(task.task, currentSearch)}</div>
<div class="bm-task-benchmarks">${chips}</div>
</div>
`;
}
if (matchedTasks === 0) continue;
l2TaskCount += matchedTasks;
l3Html += `
<div class="bm-l3 open">
<div class="bm-l3-header" onclick="this.parentElement.classList.toggle('open')">
<span class="bm-l3-badge ${getModalityBadgeClass(l3)}">${getModalityIcon(l3)} ${escapeHtml(l3)}</span>
<span class="bm-l3-count">${matchedTasks} task${matchedTasks > 1 ? 's' : ''}</span>
<span class="bm-l3-arrow">${arrowSvg}</span>
</div>
<div class="bm-l3-body">${taskHtml}</div>
</div>
`;
}
if (l2TaskCount === 0) continue;
l1TaskCount += l2TaskCount;
l2Html += `
<div class="bm-l2 open">
<div class="bm-l2-header" onclick="this.parentElement.classList.toggle('open')">
<span class="bm-l2-icon">${l2Icon}</span>
<span class="bm-l2-title">${escapeHtml(l2)}</span>
<span class="bm-l2-count">${l2TaskCount} task${l2TaskCount > 1 ? 's' : ''}</span>
<span class="bm-l2-arrow">${arrowSvg}</span>
</div>
<div class="bm-l2-body">${l3Html}</div>
</div>
`;
}
if (l1TaskCount === 0) continue;
hasResults = true;
html += `
<div class="bm-l1 ${l1Class} open">
<div class="bm-l1-header" onclick="this.parentElement.classList.toggle('open')">
<span class="bm-l1-icon">${l1Icon}</span>
<span class="bm-l1-title">${escapeHtml(l1)}</span>
<span class="bm-l1-count">${l1TaskCount} task${l1TaskCount > 1 ? 's' : ''}</span>
<span class="bm-l1-arrow">${arrowSvg}</span>
</div>
<div class="bm-l1-body">${l2Html}</div>
</div>
`;
}
if (!hasResults) {
html = `
<div class="bm-no-results">
<div class="bm-no-results-icon">🔍</div>
<div class="bm-no-results-text">No benchmarks found</div>
<div class="bm-no-results-hint">Try adjusting your search or filter</div>
</div>
`;
}
container.innerHTML = html;
}
// ============ Table View ============
function renderTable() {
const container = document.getElementById('tableView');
if (!bmData) return;
const search = currentSearch.toLowerCase();
let rows = '';
let hasResults = false;
for (const item of bmData.flat) {
if (currentFilter !== 'all' && item.level1 !== currentFilter) continue;
if (search) {
const searchable = [item.level1, item.level2, item.level3, item.level4, ...item.benchmarks].join(' ').toLowerCase();
if (!searchable.includes(search)) continue;
}
hasResults = true;
const l1Class = item.level1 === 'understanding' ? 'understand' : 'generate';
const chips = item.benchmarks.map(b =>
`<span class="bm-chip">${highlightText(b, currentSearch)}</span>`
).join('');
rows += `
<tr>
<td class="l1-cell ${l1Class}">${highlightText(item.level1, currentSearch)}</td>
<td class="l2-cell">${highlightText(item.level2, currentSearch)}</td>
<td class="l3-cell">${highlightText(item.level3, currentSearch)}</td>
<td class="l4-cell">${highlightText(item.level4, currentSearch)}</td>
<td class="bm-cell"><div class="bm-task-benchmarks">${chips}</div></td>
</tr>
`;
}
if (!hasResults) {
container.innerHTML = `
<div class="bm-no-results">
<div class="bm-no-results-icon">🔍</div>
<div class="bm-no-results-text">No benchmarks found</div>
<div class="bm-no-results-hint">Try adjusting your search or filter</div>
</div>
`;
return;
}
container.innerHTML = `
<table class="bm-table">
<thead>
<tr>
<th>Category</th>
<th>Modality Type</th>
<th>Modality</th>
<th>Task</th>
<th>Benchmarks</th>
</tr>
</thead>
<tbody>${rows}</tbody>
</table>
`;
}
// ============ Render ============
function render() {
if (currentView === 'tree') {
renderTree();
document.getElementById('treeView').style.display = '';
document.getElementById('tableView').style.display = 'none';
} else {
renderTable();
document.getElementById('treeView').style.display = 'none';
document.getElementById('tableView').style.display = '';
}
}
function updateStats() {
if (!bmData) return;
document.getElementById('stat-tasks').textContent = bmData.stats.total_tasks;
document.getElementById('stat-benchmarks').textContent = bmData.stats.total_benchmarks;
document.getElementById('stat-understand').textContent = bmData.stats.understanding_tasks;
document.getElementById('stat-generate').textContent = bmData.stats.generation_tasks;
}
// ============ Events ============
function setupEvents() {
const searchInput = document.getElementById('bmSearch');
const clearBtn = document.getElementById('bmClear');
searchInput.addEventListener('input', (e) => {
currentSearch = e.target.value;
clearBtn.classList.toggle('visible', currentSearch.length > 0);
render();
});
clearBtn.addEventListener('click', () => {
searchInput.value = '';
currentSearch = '';
clearBtn.classList.remove('visible');
render();
});
document.querySelectorAll('#bmTabs .tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('#bmTabs .tab').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
currentFilter = tab.dataset.filter;
render();
});
});
document.querySelectorAll('.stat-card[data-filter]').forEach(card => {
card.addEventListener('click', () => {
currentFilter = card.dataset.filter;
document.querySelectorAll('#bmTabs .tab').forEach(t => {
t.classList.toggle('active', t.dataset.filter === currentFilter);
});
render();
});
});
document.querySelectorAll('.view-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.view-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
currentView = btn.dataset.view;
render();
});
});
document.addEventListener('keydown', (e) => {
if (e.key === '/' && document.activeElement !== searchInput) {
e.preventDefault();
searchInput.focus();
}
});
}
// ============ Init ============
async function init() {
try {
const resp = await fetch('benchmarks.json');
bmData = await resp.json();
updateStats();
render();
setupEvents();
} catch (err) {
console.error('Failed to load benchmarks:', err);
document.getElementById('treeView').innerHTML = `
<div class="bm-no-results">
<div class="bm-no-results-icon">⚠️</div>
<div class="bm-no-results-text">Failed to load benchmark data</div>
<div class="bm-no-results-hint">Please ensure benchmarks.json is available</div>
</div>
`;
}
}
document.addEventListener('DOMContentLoaded', init);