Normally, in a minimap with zoom/pan scenario, we spend calculation cycles figuring out how to scale movements between the minimap's coordinates and the main image's coordinates.
These calculations normally happen in the callback function (every time the mouse moves). Those calculations are then used to transform elements within an SVG (translate and scale).
The things to keep track of then:
Bill D. White's work is widely referenced by d3 practitioners. This example is an attempt to reimplement his method, while reducing programmatic complexity.
To make this work:
id
and a viewport. The following attributes, then, are required:id
is to uniquely identify the image for later reuse
* height
provides the viewport's height
* width
provides the viewport's widthviewBox
* preserveAspectRatio
viewBox
- identical to the target SVG's initial viewBox/dimensions.<use>
References
Built with blockbuilder.org
https://d3js.org/d3.v5.min.js