When zooming, you apply a transform on the g1 group. Applying a transform on a <g>
will scale all the elements within. A possible design would be to have two groups, one that is affected by the zoom (here g1 in your code) and another that is not:
<svg>
<g class="zoomable">
<!-- the rest, zoomable -->
</g>
<g class="not-zoomable">
<!-- annotations -->
</g>
Then, in your code, put the annotations in the not-zoomable
group, and have the zoom transform the zoomable
group only:
let zoomableGroup = d3.select(".zoomable")
d3
.zoom()
.scaleExtent([1, 100])
.on('zoom', event => {
zoomableGroup.attr('transform', event.transform);
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…