fix(dashboard): add cache-busting and defensive chartManager guards to fix empty charts
This commit is contained in:
@@ -50,6 +50,14 @@ class AnalyticsPage {
|
||||
}
|
||||
|
||||
async loadCharts() {
|
||||
const cm = window.chartManager || await window.waitForChartManager();
|
||||
if (!cm) {
|
||||
this.showEmptyChart('analytics-chart', 'Chart system unavailable');
|
||||
this.showEmptyChart('clients-chart', 'Chart system unavailable');
|
||||
this.showEmptyChart('models-chart', 'Chart system unavailable');
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch each data source independently so one failure doesn't kill the others
|
||||
const [timeSeriesResult, breakdownResult] = await Promise.allSettled([
|
||||
window.api.get('/usage/time-series'),
|
||||
@@ -111,6 +119,8 @@ class AnalyticsPage {
|
||||
}
|
||||
|
||||
renderAnalyticsChart(series) {
|
||||
const cm = window.chartManager;
|
||||
if (!cm) return;
|
||||
const data = {
|
||||
labels: series.map(s => s.time),
|
||||
datasets: [
|
||||
@@ -130,10 +140,12 @@ class AnalyticsPage {
|
||||
]
|
||||
};
|
||||
|
||||
window.chartManager.createLineChart('analytics-chart', data);
|
||||
cm.createLineChart('analytics-chart', data);
|
||||
}
|
||||
|
||||
renderClientsChart(clients) {
|
||||
const cm = window.chartManager;
|
||||
if (!cm) return;
|
||||
const data = {
|
||||
labels: clients.map(c => c.label),
|
||||
datasets: [{
|
||||
@@ -143,17 +155,19 @@ class AnalyticsPage {
|
||||
}]
|
||||
};
|
||||
|
||||
window.chartManager.createHorizontalBarChart('clients-chart', data);
|
||||
cm.createHorizontalBarChart('clients-chart', data);
|
||||
}
|
||||
|
||||
renderModelsChart(models) {
|
||||
const cm = window.chartManager;
|
||||
if (!cm) return;
|
||||
const data = {
|
||||
labels: models.map(m => m.label),
|
||||
data: models.map(m => m.value),
|
||||
colors: window.chartManager.defaultColors
|
||||
colors: cm.defaultColors
|
||||
};
|
||||
|
||||
window.chartManager.createDoughnutChart('models-chart', data);
|
||||
cm.createDoughnutChart('models-chart', data);
|
||||
}
|
||||
|
||||
async loadUsageData() {
|
||||
|
||||
Reference in New Issue
Block a user