From b4642ce57a8774a5ff42a221d3b6d6663a2c7712 Mon Sep 17 00:00:00 2001 From: dlawler489 <104159223@student.swin.edu.au> Date: Tue, 29 Apr 2025 19:19:45 +1000 Subject: [PATCH] fixed download function --- script/script.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/script/script.js b/script/script.js index 6084930..aa8c4bd 100644 --- a/script/script.js +++ b/script/script.js @@ -171,29 +171,26 @@ d3.csv("PHSwithContinent.csv").then(function(data) { updateChart(); }); - // Download chart as PNG d3.select("#downloadButton").on("click", function() { 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(document.getElementById("chart"), { - filename: filename, + + saveSvgAsPng(document.getElementById("chart"), filename, { // <-- filename second, options third scale: 2, backgroundColor: darkMode ? "#121212" : "#ffffff" }); }); }); - // Update legend depending on chart type function updateLegend(chartType) { const legend = d3.select("#legend");