From 17f63a4fc8ec8d0543c97e7ac137fe6c83bdb57c Mon Sep 17 00:00:00 2001
From: dlawler489 <104159223@student.swin.edu.au>
Date: Sun, 27 Apr 2025 08:25:45 +1000
Subject: [PATCH 1/7] added dot plot and heat map
---
index.html | 11 +-
script/script.js | 408 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 324 insertions(+), 95 deletions(-)
diff --git a/index.html b/index.html
index d94c17b..949d24f 100644
--- a/index.html
+++ b/index.html
@@ -28,13 +28,22 @@
+
+
+
+
+
Loading chart, please wait...
-
diff --git a/script/script.js b/script/script.js
index f1c6e38..38c724b 100644
--- a/script/script.js
+++ b/script/script.js
@@ -63,11 +63,21 @@ darkModeToggle.addEventListener('click', () => {
darkMode = !darkMode;
document.body.style.backgroundColor = darkMode ? '#121212' : '#fff';
document.body.style.color = darkMode ? '#eee' : '#000';
+ chartTitle1.style("fill", darkMode ? "#eee" : "#000");
+ chartTitle2.style("fill", darkMode ? "#ccc" : "#666");
darkModeToggle.style.backgroundColor = darkMode ? '#eee' : '#333';
darkModeToggle.style.color = darkMode ? '#000' : '#fff';
tooltip.style("background-color", darkMode ? "#222" : "#fff")
.style("color", darkMode ? "#eee" : "#000");
g.selectAll("text").style("fill", darkMode ? "#eee" : "#000");
+
+ // 🆕 THESE MUST BE INSIDE the event listener block
+ g.selectAll(".lowest-annotation")
+ .style("fill", darkMode ? "#eee" : "red");
+
+ g.selectAll(".lowest-box")
+ .attr("fill", darkMode ? "#222" : "#fff")
+ .attr("stroke", darkMode ? "#aaa" : "#999");
});
d3.csv("PHSwithContinent.csv").then(function(data) {
@@ -272,7 +282,7 @@ function drawGrouped(data) {
g.append("g")
.call(d3.axisLeft(y).ticks(10));
- // 📌 Smart Annotate lowest bar
+ // 📌 Annotate lowest bar with dynamic box
if (groupedData.length > 0) {
const flat = groupedData.flatMap(g => g.values);
const lowest = flat.reduce((min, d) => d.value < min.value ? d : min, flat[0]);
@@ -283,17 +293,17 @@ function drawGrouped(data) {
const labelText = `Lowest: ${lowest["Reference area"]}`;
const tempText = g.append("text")
- .attr("x", -9999) // Place it offscreen first
+ .attr("x", -9999)
.attr("y", -9999)
.style("font-size", "12px")
.style("font-weight", "bold")
.text(labelText);
const textWidth = tempText.node().getBBox().width;
- tempText.remove(); // Cleanup
+ tempText.remove();
- // Background rectangle scaled to text size
g.append("rect")
+ .attr("class", "lowest-box")
.attr("x", barX - textWidth / 2 - 6)
.attr("y", barY - 28)
.attr("width", textWidth + 12)
@@ -304,8 +314,8 @@ function drawGrouped(data) {
.attr("stroke-width", 0.5)
.attr("opacity", 0.9);
- // Final visible text
g.append("text")
+ .attr("class", "lowest-annotation")
.attr("x", barX)
.attr("y", barY - 14)
.attr("text-anchor", "middle")
@@ -375,7 +385,6 @@ function drawDotPlot(data) {
g.append("g")
.call(d3.axisLeft(y));
- // Add X-axis label
g.append("text")
.attr("x", width / 2)
.attr("y", height + 50)
@@ -384,7 +393,7 @@ function drawDotPlot(data) {
.style("fill", darkMode ? "#fff" : "#000")
.text("Percentage Reporting Good Health (%)");
- // 📌 Smart annotate lowest dot
+ // 📌 Annotate lowest dot with dynamic box
if (groupedData.length > 0) {
const flat = groupedData.flatMap(g => g.values);
const lowest = flat.reduce((min, d) => d.value < min.value ? d : min, flat[0]);
@@ -405,6 +414,7 @@ function drawDotPlot(data) {
tempText.remove();
g.append("rect")
+ .attr("class", "lowest-box")
.attr("x", dotX - textWidth / 2 - 6)
.attr("y", dotY - 28)
.attr("width", textWidth + 12)
@@ -416,6 +426,7 @@ function drawDotPlot(data) {
.attr("opacity", 0.9);
g.append("text")
+ .attr("class", "lowest-annotation")
.attr("x", dotX)
.attr("y", dotY - 14)
.attr("text-anchor", "middle")
From 93ecc88adea650ef41cd3989c6224b71674e6121 Mon Sep 17 00:00:00 2001
From: dlawler489 <104159223@student.swin.edu.au>
Date: Sun, 27 Apr 2025 18:21:39 +1000
Subject: [PATCH 3/7] fixed export png function
---
index.html | 2 +-
script/script.js | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/index.html b/index.html
index 84acc3b..d31d7c6 100644
--- a/index.html
+++ b/index.html
@@ -43,7 +43,7 @@
Loading chart, please wait...
-
+
diff --git a/script/script.js b/script/script.js
index 38c724b..8edb336 100644
--- a/script/script.js
+++ b/script/script.js
@@ -170,16 +170,17 @@ d3.csv("PHSwithContinent.csv").then(function(data) {
const c = d3.select("#continentSelect").property("value");
const s = d3.select("#sexSelect").property("value");
const e = d3.select("#incomeSelect").property("value");
-
+
const parts = [
"education_health",
c !== "All" ? c : null,
s !== "All" ? s : null,
e !== "All" ? e.replace(/[^a-zA-Z0-9]+/g, "_").toLowerCase() : null
].filter(Boolean);
-
+
const filename = parts.join("_") + ".png";
- saveSvgAsPng.saveSvgAsPng(document.querySelector("svg"), filename);
+
+ saveSvgAsPng(document.getElementById("chart"), filename);
});
});
From b578c5359418ebbba8c0d55f3bfc6ee7de641380 Mon Sep 17 00:00:00 2001
From: dlawler489 <104159223@student.swin.edu.au>
Date: Mon, 28 Apr 2025 15:33:26 +1000
Subject: [PATCH 4/7] fixed code commenting
---
CSS/style.css | 171 ++++++++++++++++++++++++++---------------------
index.html | 18 ++++-
script/script.js | 92 ++++++++++++++++---------
3 files changed, 173 insertions(+), 108 deletions(-)
diff --git a/CSS/style.css b/CSS/style.css
index b19cbfe..855e082 100644
--- a/CSS/style.css
+++ b/CSS/style.css
@@ -1,76 +1,97 @@
+/* Base body styles */
body {
- font-family: sans-serif;
- }
- .bar {
- opacity: 0.8;
- transition: opacity 0.3s;
- }
- .bar:hover {
- opacity: 1;
- }
- .axis-label {
- font-size: 14px;
- font-weight: bold;
- }
- .tooltip {
- position: absolute;
- padding: 6px;
- background: #fff;
- border: 1px solid #ccc;
- border-radius: 5px;
- box-shadow: 0px 2px 8px rgba(0,0,0,0.2);
- font-size: 12px;
- pointer-events: none;
- opacity: 0;
- transition: all 0.3s ease;
- }
- .controls {
- margin-bottom: 20px;
- }
- select {
- margin-right: 10px;
- padding: 5px;
- }
- button {
- margin: 5px;
- padding: 8px 12px;
- font-size: 14px;
- cursor: pointer;
- background-color: #4E79A7;
- color: white;
- border: none;
- border-radius: 4px;
- }
- button:hover {
- background-color: #3a5f8c;
- }
- .legend {
- margin-top: 20px;
- }
- .legend-item {
- display: inline-block;
- margin-right: 20px;
- font-size: 14px;
- }
- .legend-color {
- width: 12px;
- height: 12px;
- display: inline-block;
- margin-right: 5px;
- vertical-align: middle;
- }
- #loading {
- font-size: 18px;
- text-align: center;
- margin: 20px;
- }
- .hidden {
- display: none;
- }
- .page-title {
- text-align: center;
- margin-top: 20px;
- margin-bottom: 10px;
- font-size: 28px;
- font-weight: bold;
- }
\ No newline at end of file
+ font-family: sans-serif;
+}
+
+/* Chart bars */
+.bar {
+ opacity: 0.8;
+ transition: opacity 0.3s;
+}
+.bar:hover {
+ opacity: 1;
+}
+
+/* Axis labels */
+.axis-label {
+ font-size: 14px;
+ font-weight: bold;
+}
+
+/* Tooltip styles */
+.tooltip {
+ position: absolute;
+ padding: 6px;
+ background: #fff;
+ border: 1px solid #ccc;
+ border-radius: 5px;
+ box-shadow: 0px 2px 8px rgba(0,0,0,0.2);
+ font-size: 12px;
+ pointer-events: none;
+ opacity: 0;
+ transition: all 0.3s ease;
+}
+
+/* Controls section (dropdowns and buttons) */
+.controls {
+ margin-bottom: 20px;
+}
+
+/* Dropdown (select) styling */
+select {
+ margin-right: 10px;
+ padding: 5px;
+}
+
+/* Buttons styling */
+button {
+ margin: 5px;
+ padding: 8px 12px;
+ font-size: 14px;
+ cursor: pointer;
+ background-color: #4E79A7;
+ color: white;
+ border: none;
+ border-radius: 4px;
+}
+button:hover {
+ background-color: #3a5f8c;
+}
+
+/* Legend area */
+.legend {
+ margin-top: 20px;
+}
+.legend-item {
+ display: inline-block;
+ margin-right: 20px;
+ font-size: 14px;
+}
+.legend-color {
+ width: 12px;
+ height: 12px;
+ display: inline-block;
+ margin-right: 5px;
+ vertical-align: middle;
+}
+
+/* Loading message */
+#loading {
+ font-size: 18px;
+ text-align: center;
+ margin: 20px;
+}
+
+/* Hidden class (for hiding elements like loading spinner) */
+.hidden {
+ display: none;
+}
+
+/* Main page title */
+.page-title {
+ text-align: center;
+ margin-top: 20px;
+ margin-bottom: 10px;
+ font-size: 28px;
+ font-weight: bold;
+}
\ No newline at end of file
diff --git a/index.html b/index.html
index d31d7c6..6ad0bfb 100644
--- a/index.html
+++ b/index.html
@@ -3,13 +3,22 @@
Health Perception by Education Level
+
+
+
+
+
+
+
+
How Education Level Shapes Perceived Health
+
+
-
-
+
Loading chart, please wait...
+
+
+
-
+