diff options
| author | Christian Cleberg <[email protected]> | 2026-04-17 19:41:31 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-17 19:41:31 -0500 |
| commit | 623ae07ebacb9d596b225179727dc87641ad1cca (patch) | |
| tree | f1045282b3369bf3f4b0249cd649b47a5d010dad /assets/js/map/zoom.js | |
| parent | fd412c5197286518ff9491a1b51e6319c9a22904 (diff) | |
| download | world-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/map/zoom.js')
| -rw-r--r-- | assets/js/map/zoom.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/assets/js/map/zoom.js b/assets/js/map/zoom.js index aec278b..cba7c2c 100644 --- a/assets/js/map/zoom.js +++ b/assets/js/map/zoom.js @@ -1,3 +1,18 @@ -// Phase 3: zoom and pan behavior -export function initZoom(svg, mapGroup) {} -export function resetZoom(svg, zoomBehavior) {} +import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm"; + +let _svg, _zoom; + +export function initZoom(svg, mapGroup) { + _svg = svg; + _zoom = d3.zoom() + .scaleExtent([0.5, 8]) + .on("zoom", (event) => { + mapGroup.attr("transform", event.transform); + }); + svg.call(_zoom); + return _zoom; +} + +export function resetZoom() { + _svg.transition().duration(750).call(_zoom.transform, d3.zoomIdentity); +} |
