fix: preload player rating history to fix first-click chart render (#10)
This commit is contained in:
+21
-13
@@ -26,23 +26,31 @@ function applyDeltaPill(pillEl, value) {
|
||||
pillEl.appendChild(numSpan);
|
||||
}
|
||||
|
||||
function initChartsIn(rootEl) {
|
||||
rootEl.querySelectorAll('.player-chart').forEach(function(container) {
|
||||
if (container.dataset.charted === 'true') return;
|
||||
if (!container.dataset.history) return;
|
||||
try {
|
||||
const history = JSON.parse(container.dataset.history);
|
||||
createRatingChart(container, history);
|
||||
container.dataset.charted = 'true';
|
||||
} catch (e) {
|
||||
console.error('Error rendering chart:', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setupTooltipsAfterSwap() {
|
||||
document.body.addEventListener('htmx:afterSwap', function(event) {
|
||||
if (event.detail.target.id === 'ratings-table') {
|
||||
initRatingsTooltips();
|
||||
}
|
||||
// After player history partial loads, render the chart
|
||||
const target = event.detail.target;
|
||||
if (target.id === 'ratings-table') {
|
||||
initRatingsTooltips();
|
||||
initChartsIn(target); // initial table render — chart any pre-loaded .player-chart
|
||||
return;
|
||||
}
|
||||
// refreshRatingHistory still re-fetches into #history-content-<id>
|
||||
if (target.id && target.id.startsWith('history-content-')) {
|
||||
const container = target.querySelector('.player-chart, .chart-container');
|
||||
if (container && container.dataset.history) {
|
||||
try {
|
||||
const history = JSON.parse(container.dataset.history);
|
||||
createRatingChart(container, history);
|
||||
} catch (e) {
|
||||
console.error('Error rendering chart:', e);
|
||||
}
|
||||
}
|
||||
initChartsIn(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user