Skip to content

Commit c75b489

Browse files
committed
feat: update script.js to support ?version= query param
1 parent aa6c0d9 commit c75b489

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

script.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,15 @@ function createDetailRow(stats, modelName, data, vendor, model, basePath, strate
708708
</td>
709709
`;
710710

711-
// Add charts after DOM is updated
712-
setTimeout(() => {
713-
createRoundHistogram(stats, histogramCanvasId);
714-
createProviderPieChart(data, pieChartCanvasId);
715-
}, 0);
711+
// Prepare chart initialization to be called after the row is inserted into the DOM
712+
detailRow._initCharts = () => {
713+
try {
714+
createRoundHistogram(stats, histogramCanvasId);
715+
createProviderPieChart(data, pieChartCanvasId);
716+
} catch (e) {
717+
console.error('Failed to initialize detail charts', e);
718+
}
719+
};
716720

717721
// Make each per-run row clickable to open Run Viewer (if runs mapping exists)
718722
const perRunTable = detailRow.querySelector('table.table-auto');
@@ -776,9 +780,9 @@ async function loadLeaderboard(leaderboardPath, detailBasePath, displayMode = 'm
776780
// Clear previous rows if reloading
777781
tableBody.innerHTML = '';
778782

779-
// Create the performance bar chart (only on main leaderboard page)
783+
// Create the performance bar chart (only on main leaderboard page) immediately
780784
if (showChart) {
781-
createPerformanceBarChart(data.entries);
785+
try { createPerformanceBarChart(data.entries); } catch (_) {}
782786
}
783787

784788
data.entries.forEach((entry, index) => {
@@ -830,6 +834,9 @@ async function loadLeaderboard(leaderboardPath, detailBasePath, displayMode = 'm
830834
strategy
831835
);
832836
row.insertAdjacentElement('afterend', detailRow);
837+
if (typeof detailRow._initCharts === 'function') {
838+
detailRow._initCharts();
839+
}
833840
}
834841
}
835842
});
@@ -1161,6 +1168,16 @@ async function initBenchmarkVersionSelector() {
11611168
sel.appendChild(option);
11621169
});
11631170

1171+
// Respect ?version= query param if present
1172+
try {
1173+
const url = new URL(window.location.href);
1174+
const urlVersion = url.searchParams.get('version');
1175+
if (urlVersion && versions.some(v => v.version === urlVersion)) {
1176+
sel.value = urlVersion;
1177+
}
1178+
} catch (_) {}
1179+
1180+
11641181
const applyVersion = (version) => {
11651182
const paths = getDataPaths(version);
11661183
const tbody = document.getElementById('leaderboard-body');
@@ -1174,5 +1191,12 @@ async function initBenchmarkVersionSelector() {
11741191
applyVersion(sel.value || DEFAULT_BENCHMARK_VERSION);
11751192

11761193
// Reload on change
1177-
sel.addEventListener('change', () => applyVersion(sel.value));
1194+
sel.addEventListener('change', () => {
1195+
try {
1196+
const url = new URL(window.location.href);
1197+
url.searchParams.set('version', sel.value);
1198+
window.history.replaceState({}, '', url.toString());
1199+
} catch (_) {}
1200+
applyVersion(sel.value);
1201+
});
11781202
}

0 commit comments

Comments
 (0)