Update script.js

fixed normalisation for data labels
This commit is contained in:
dlawler489 2025-05-20 18:45:13 +10:00
parent 430a81be94
commit f1ed754b3d

View file

@ -12,9 +12,9 @@ const y = d3.scaleLinear().rangeRound([height, 0]);
// Education levels for legend and grouped charts // Education levels for legend and grouped charts
const educationLevels = [ const educationLevels = [
"Primary education", "Primary Education",
"Secondary education", "Secondary Education",
"Tertiary education" "Tertiary Education"
]; ];
// Color scale for education levels // Color scale for education levels
@ -82,8 +82,19 @@ darkModeToggle.addEventListener('click', () => {
g.selectAll(".lowest-box").attr("fill", darkMode ? "#222" : "#fff").attr("stroke", darkMode ? "#aaa" : "#999"); g.selectAll(".lowest-box").attr("fill", darkMode ? "#222" : "#fff").attr("stroke", darkMode ? "#aaa" : "#999");
}); });
// Load data // Load data
d3.csv("PHSwithContinent.csv").then(function(data) { d3.csv("PHSwithContinent.csv").then(function(data) {
// Normalize Socio-economic status values to match educationLevels
data.forEach(d => {
if (d["Socio-economic status"] === "Pre-primary, primary and lower secondary education") {
d["Socio-economic status"] = "Primary Education";
} else if (d["Socio-economic status"] === "Upper secondary and post-secondary non-tertiary, all programmes") {
d["Socio-economic status"] = "Secondary Education";
} else if (d["Socio-economic status"] === "Tertiary education") {
d["Socio-economic status"] = "Tertiary Education";
}
});
const allData = data; const allData = data;
// Populate continent and education dropdowns // Populate continent and education dropdowns