How do I specify the initial zoom level in D3?

前端 未结 3 2061
臣服心动
臣服心动 2021-01-04 09:57

I have written a script to graphically display some row-oriented data, with bars, labels and connections between rows. As the dataset has grown, the resulting SVG element ha

3条回答
  •  轮回少年
    2021-01-04 10:43

    In d3 v4, you can use:

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

    Simple example:

    var zoom = d3.zoom()
            .on("zoom", zoomed);
    
    var zoomer = svg.append("rect")
            .call(zoom)
            .call(zoom.transform, d3.zoomIdentity.scale(2,2));
    
    function zoomed() {
            svg.attr("transform", d3.event.transform);
        }
    

    Hope that helps.

提交回复
热议问题