export charts

This commit is contained in:
2026-04-15 15:45:34 +07:00
parent f0a5079b15
commit 840b93a651
5 changed files with 426 additions and 44 deletions

View File

@@ -2,7 +2,20 @@ const standardPrograms = ['SARI', 'ILI', 'LBM', 'AFI'];
const programCode = (window.PROGRAM_CODE || '').trim().toUpperCase();
let map;
let provinceLayer;
document.addEventListener("DOMContentLoaded", () => {
if (!standardPrograms.includes(programCode)) return;
new DashboardFilter((startYear, startWeek, endYear, endWeek) => {
fetch(`/api/dashboard/program?surveillance_id=${window.SURVEILLANCE_ID}&start_year=${startYear}&start_week=${startWeek}&end_year=${endYear}&end_week=${endWeek}`)
.then(res => res.json())
.then(programCode === 'AFI' ? renderAFIDashboard : renderDashboard)
.catch(err => console.error("Dashboard API error:", err));
});
});
function normalizeProvince(name, validSet) {
if (!name || !validSet) return null;
@@ -33,22 +46,6 @@ function normalizeProvince(name, validSet) {
return match || null;
}
document.addEventListener("DOMContentLoaded", () => {
if (!standardPrograms.includes(programCode)) return;
new DashboardFilter((startYear, startWeek, endYear, endWeek) => {
fetch(`/api/dashboard/program?surveillance_id=${window.SURVEILLANCE_ID}&start_year=${startYear}&start_week=${startWeek}&end_year=${endYear}&end_week=${endWeek}`)
.then(res => res.json())
.then(programCode === 'AFI' ? renderAFIDashboard : renderDashboard)
.catch(err => console.error("Dashboard API error:", err));
});
});
function renderAFIDashboard(data) {
const pathogenRows = (data.pathogen_distribution || [])
.sort((a, b) => b.total - a.total);
@@ -100,11 +97,9 @@ function renderProvinceHeatmap(rows) {
rows.forEach(r => {
// ✅ FIX: use patient_province + validSet
const province = normalizeProvince(r.patient_province, validProvinces);
if (!province) return;
// ✅ FIX: accumulate instead of overwrite
if (!totals[province]) {
totals[province] = { total: 0, positive: 0 };
}
@@ -140,7 +135,6 @@ function renderProvinceHeatmap(rows) {
const total = totals[province]?.total || 0;
const positive = totals[province]?.positive || 0;
// ✅ positivity kept
const percent = total
? ((positive / total) * 100).toFixed(1)
: 0;
@@ -323,8 +317,6 @@ function renderDashboard(data) {
'#8b5cf6', '#14b8a6', '#f97316', '#84cc16', '#e11dba', '#f6f63b'
];
buildChart(
'pathogenChart',
'doughnut',
@@ -439,7 +431,6 @@ function getColorForPathogen(name) {
if (colors[name]) return colors[name];
// fallback random color (for future pathogens)
return `hsl(${Math.floor(Math.random() * 360)}, 70%, 60%)`;
}
function renderPathogenChart(rows) {
@@ -482,4 +473,4 @@ function renderSubtypeChart(rows) {
);
}
//Seq