fix bugs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { COLORS, SUBTYPE_COLORS } from "./globals.js";
|
||||
import * as Charts from "./dashboard/globals.js";
|
||||
const standardPrograms = ['SARI', 'ILI', 'LBM', 'AFI', 'NDS'];
|
||||
const programCode = (window.PROGRAM_CODE || '').trim().toUpperCase();
|
||||
|
||||
@@ -31,34 +31,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
});
|
||||
|
||||
});
|
||||
function buildDistributionChart(
|
||||
id,
|
||||
type,
|
||||
rows,
|
||||
labelKey,
|
||||
valueKey = 'total',
|
||||
colorResolver = null
|
||||
) {
|
||||
|
||||
const labels = rows.map(r => r[labelKey]);
|
||||
buildChart(
|
||||
id,
|
||||
type,
|
||||
labels,
|
||||
rows.map(r => r[valueKey])
|
||||
);
|
||||
|
||||
if (!charts[id]) return;
|
||||
|
||||
charts[id].data.datasets[0].backgroundColor = labels.map(
|
||||
(label, index) =>
|
||||
colorResolver
|
||||
? colorResolver(label, index)
|
||||
: COLORS[index % COLORS.length]
|
||||
);
|
||||
|
||||
charts[id].update();
|
||||
}
|
||||
function renderTrend(valueId, changeId, current, previous, suffix = '') {
|
||||
|
||||
const valueEl = document.getElementById(valueId);
|
||||
@@ -90,16 +63,7 @@ function renderTrend(valueId, changeId, current, previous, suffix = '') {
|
||||
changeEl.className = "text-muted";
|
||||
}
|
||||
}
|
||||
function getSubtypeColor(label, index = 0) {
|
||||
|
||||
const specialColors = {
|
||||
'A/H5N1': '#dc2626',
|
||||
'Influenza': '#b90c00'
|
||||
};
|
||||
|
||||
return specialColors[label]
|
||||
|| COLORS[index % COLORS.length];
|
||||
}
|
||||
function renderSummary(summary = {}) {
|
||||
|
||||
const mappings = [
|
||||
@@ -127,41 +91,41 @@ function renderDashboard(data = {}) {
|
||||
renderSummary(data.summary);
|
||||
renderProvinceHeatmap(data.province_distribution || []);
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'pathogenChart',
|
||||
'doughnut',
|
||||
(data.pathogen_distribution || [])
|
||||
.sort((a, b) => b.total - a.total),
|
||||
'pathogen',
|
||||
'total',
|
||||
getSubtypeColor
|
||||
Charts.getSubtypeColor
|
||||
|
||||
);
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'ageChart',
|
||||
'doughnut',
|
||||
data.age_distribution || [],
|
||||
'age_group'
|
||||
);
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'sexChart',
|
||||
'bar',
|
||||
data.sex_distribution || [],
|
||||
'patient_sex'
|
||||
);
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'subtypeChart',
|
||||
'bar',
|
||||
data.subtype_distribution || [],
|
||||
'subtype',
|
||||
'total',
|
||||
getSubtypeColor
|
||||
Charts.getSubtypeColor
|
||||
);
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'sentinelChart',
|
||||
'pie',
|
||||
data.sentinel_sites || [],
|
||||
@@ -178,21 +142,21 @@ function renderAFIDashboard(data = {}) {
|
||||
renderAFITrend(
|
||||
data.afi_case_trend.section_1,
|
||||
'afiSection1Trend',
|
||||
COLORS,
|
||||
Chart.COLORS,
|
||||
'trend'
|
||||
);
|
||||
|
||||
renderAFITrend(
|
||||
data.afi_case_trend.section_2,
|
||||
'afiSection2Trend',
|
||||
COLORS,
|
||||
Chart.COLORS,
|
||||
'trend'
|
||||
);
|
||||
|
||||
renderAFITrend(
|
||||
data.afi_case_trend.section_3,
|
||||
'afiSection3Trend',
|
||||
COLORS,
|
||||
Chart.COLORS,
|
||||
'trend'
|
||||
);
|
||||
|
||||
@@ -200,21 +164,21 @@ function renderAFIDashboard(data = {}) {
|
||||
renderAFITrend(
|
||||
data.afi_case_trend.section_1,
|
||||
'afiPcrChart',
|
||||
COLORS,
|
||||
Chart.COLORS,
|
||||
'donut'
|
||||
);
|
||||
|
||||
renderAFITrend(
|
||||
data.afi_case_trend.section_2,
|
||||
'afiMultiplexChart',
|
||||
COLORS,
|
||||
Chart.COLORS,
|
||||
'donut'
|
||||
);
|
||||
|
||||
renderAFITrend(
|
||||
data.afi_case_trend.section_3,
|
||||
'afiElisaChart',
|
||||
COLORS,
|
||||
Chart.COLORS,
|
||||
'donut'
|
||||
);
|
||||
|
||||
@@ -466,7 +430,7 @@ function renderProgramTrend(rows = []) {
|
||||
|
||||
if (!rows.length) {
|
||||
|
||||
buildMixedTrendChart(
|
||||
Charts.buildMixedTrendChart(
|
||||
'trendChart',
|
||||
[],
|
||||
[],
|
||||
@@ -720,7 +684,7 @@ function renderProgramTrend(rows = []) {
|
||||
|
||||
}
|
||||
|
||||
buildMixedTrendChart(
|
||||
Charts.buildMixedTrendChart(
|
||||
'trendChart',
|
||||
labels,
|
||||
samples,
|
||||
@@ -758,7 +722,7 @@ function renderAFITrend(
|
||||
|
||||
if (type === 'donut') {
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
canvasId,
|
||||
'doughnut',
|
||||
[],
|
||||
@@ -768,7 +732,7 @@ function renderAFITrend(
|
||||
|
||||
} else {
|
||||
|
||||
buildMixedTrendChart(
|
||||
Charts.buildMixedTrendChart(
|
||||
canvasId,
|
||||
[],
|
||||
[],
|
||||
@@ -862,7 +826,7 @@ function renderAFITrend(
|
||||
total
|
||||
}));
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
canvasId,
|
||||
'doughnut',
|
||||
donutRows,
|
||||
@@ -886,12 +850,12 @@ function renderAFITrend(
|
||||
0
|
||||
);
|
||||
|
||||
if (charts[canvasId]) {
|
||||
if (Charts.charts[canvasId]) {
|
||||
|
||||
charts[canvasId].$afiTotalCases =
|
||||
Charts.charts[canvasId].$afiTotalCases =
|
||||
donutTotal;
|
||||
|
||||
charts[canvasId].update();
|
||||
Charts.charts[canvasId].update();
|
||||
|
||||
}
|
||||
|
||||
@@ -941,8 +905,8 @@ function renderAFITrend(
|
||||
}),
|
||||
|
||||
color:
|
||||
COLORS[
|
||||
i % COLORS.length
|
||||
Charts.COLORS[
|
||||
i % Charts.COLORS.length
|
||||
]
|
||||
|
||||
})
|
||||
@@ -954,7 +918,7 @@ function renderAFITrend(
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
buildMixedTrendChart(
|
||||
Charts.buildMixedTrendChart(
|
||||
canvasId,
|
||||
labels,
|
||||
totalCases,
|
||||
@@ -965,7 +929,7 @@ function renderAFITrend(
|
||||
|
||||
|
||||
function renderPathogenChart(rows = []) {
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'pathogenChart',
|
||||
'doughnut',
|
||||
rows,
|
||||
@@ -973,7 +937,7 @@ function renderPathogenChart(rows = []) {
|
||||
);
|
||||
}
|
||||
function renderSentinel(rows = []) {
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'sentinelChart',
|
||||
'pie',
|
||||
rows,
|
||||
@@ -982,27 +946,26 @@ function renderSentinel(rows = []) {
|
||||
}
|
||||
function renderSubtypeChart(rows = []) {
|
||||
|
||||
console.log('renderSubtypeChart');
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'subtypeChart',
|
||||
'bar',
|
||||
rows,
|
||||
'subtype',
|
||||
'total',
|
||||
getSubtypeColor
|
||||
Charts.getSubtypeColor
|
||||
);
|
||||
}
|
||||
function renderDemographics(data = {}) {
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'ageChart',
|
||||
'doughnut',
|
||||
data.age_distribution || [],
|
||||
'age_group'
|
||||
);
|
||||
|
||||
buildDistributionChart(
|
||||
Charts.buildDistributionChart(
|
||||
'sexChart',
|
||||
'bar',
|
||||
data.sex_distribution || [],
|
||||
|
||||
Reference in New Issue
Block a user