D3 v4: Reset zoom state

前端 未结 5 1812
谎友^
谎友^ 2021-02-19 07:26

I have a SVG which can be zoomed and also a \"reset\" button. I\'m resetting the zoom with

zoom.transform(selection, d3.zoomIdentity)

This wor

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-19 08:11

    This works as expected and resets the zoom on the SVG. But if I zoom again, it zooms back to the last state.

    I have the same problem, after a quick research I discovered. You cant apply zoom and reset zoom to , you need to append and apply zoom there.

    svg.call(zoom.transform, d3.zoomIdentity.scale(1));
    

    Changed to zoom.transform(d3.select(chartContainer).select('svg.view'), d3.zoomIdentity.scale(1)); it works for me.

提交回复
热议问题