summaryrefslogtreecommitdiff
path: root/assets/js/ui/modal.js
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-17 19:41:31 -0500
committerChristian Cleberg <[email protected]>2026-04-17 19:41:31 -0500
commit623ae07ebacb9d596b225179727dc87641ad1cca (patch)
treef1045282b3369bf3f4b0249cd649b47a5d010dad /assets/js/ui/modal.js
parentfd412c5197286518ff9491a1b51e6319c9a22904 (diff)
downloadworld-incarceration-623ae07ebacb9d596b225179727dc87641ad1cca.tar.gz
world-incarceration-623ae07ebacb9d596b225179727dc87641ad1cca.tar.bz2
world-incarceration-623ae07ebacb9d596b225179727dc87641ad1cca.zip
phase 2-6: complete D3/TopoJSON migration
Replace ZingChart + jQuery with D3 v7 + TopoJSON. Implements all planned phases: choropleth map (NaturalEarth1 projection, YlOrRd gradient), hover tooltip, zoom/pan/reset, country detail modal, side-by-side compare, metric selector, label toggle, donut pie chart with per-country drilldown bar chart. Upgrades Bootstrap JS bundle from v4.5.3 (jQuery-dependent) to v5.0.0, fixes modal API calls to use getInstance/constructor pattern compatible with BS 5.0.0+. Removes jquery, zingchart ×3 library files.
Diffstat (limited to 'assets/js/ui/modal.js')
-rw-r--r--assets/js/ui/modal.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/assets/js/ui/modal.js b/assets/js/ui/modal.js
index e110764..2fd8491 100644
--- a/assets/js/ui/modal.js
+++ b/assets/js/ui/modal.js
@@ -1,2 +1,29 @@
-// Phase 5: country detail modal
-export function showCountryModal(countryData) {}
+export function showCountryModal(countryData) {
+ document.getElementById("country-modal-title").textContent = countryData.country;
+ document.getElementById("country-modal-body").innerHTML = `
+ <p><b>Prison Population:</b> ${_fmt(countryData.pop, "pop")}</p>
+ <p><b>Rate per 100,000 Citizens:</b> ${_fmt(countryData.rate, "rate")}</p>
+ <p><b>Females:</b> ${_fmt(countryData.females, "pct")}</p>
+ <p><b>Juveniles:</b> ${_fmt(countryData.juveniles, "pct")}</p>
+ <p><b>Occupancy:</b> ${_fmt(countryData.occupancy, "pct")}</p>
+ <p><b>Government:</b> ${_fmtGov(countryData.government)}</p>
+ `;
+ const el = document.getElementById("countryModal");
+ (bootstrap.Modal.getInstance(el) || new bootstrap.Modal(el)).show();
+}
+
+function _fmt(val, type) {
+ if (val === "--" || val === null || val === undefined || (typeof val === "number" && isNaN(val))) {
+ return "<span class='text-danger'>Information not available.</span>";
+ }
+ if (type === "pop") return Number(val).toLocaleString("en");
+ if (type === "rate") return String(val);
+ if (type === "pct") return (val * 100).toFixed(2) + " %";
+ return String(val);
+}
+
+function _fmtGov(val) {
+ return (!val || val === "--")
+ ? "<span class='text-danger'>Information not available.</span>"
+ : val;
+}