translateExtent() is a D3 zoom behavior method for limiting how far a visualization can be translated during panning. It accepts minimum and maximum coordinates, helping keep a map from moving entirely out of view. section 13.3
Listing 13.12 Implementing zooming and panning (map-world.js)
...
import { zoom } from "d3-zoom";
export const drawWorldMap = (laureates, world) => {
...
const zoomHandler = zoom() #1
.on("zoom", (e) => { #2
console.log(e);
});
select(".map-container") #3
.call(zoomHandler);
};
Use the complete zoom configuration to see translateExtent() alongside scaleExtent(), the zoom event, and SVG transform updates. section 13.3
Constrain a world map
const zoomHandler = zoom() .scaleExtent([1, 5]) .translateExtent([ [-width / 2, -height / 2], [3 * width / 2, 3 * height / 2] ]) .on("zoom", (e) => { svg.attr("transform", e.transform); }); section 13.3
