简体   繁体   English

d3.js网络图放大

[英]d3.js network diagram zoom

I have probably a relativly simple question. 我可能有一个相对简单的问题。

Here is my simple diagram enter link description here 这是我的简单图表, 在此处输入链接描述

And I would love to implement zooming in and out functionality, using the behaviour descibed here enter link description here . 我很想实现缩放功能,请使用此处描述的行为在此处输入链接描述 But I cant make it work, maybe You would spot the problem. 但是我无法使其正常工作,也许您会发现问题所在。

Thanks for Your time. 谢谢你的时间。

The whole zooming in functionality seems to be handled with this assignment and function: 整个放大功能似乎可以通过以下分配和功能来处理:

svg = d3.select("body").append("svg").attr("width", width).attr("height", height)
.call(d3.behavior.zoom().x(x).y(y).scaleExtent([1, 8]).on("zoom", zoom));

function zoom() {
svg.clearRect(0, 0, width, height);  
}

The code you have tried for zooming is used for canvas. 您尝试缩放的代码用于画布。 You can use transform attribute for zooming in svg. 您可以使用transform属性来放大svg。 You can put the whole graph in a (group) element and apply transform attribute to element. 您可以将整个图形放在(组)元素中,然后将transform属性应用于element。

svg = d3.select("body")
         .append("svg")
         .attr("width", width)
         .attr("height", height)
         .call(d3.behavior.zoom().x(x).y(y).scaleExtent([1, 8]).on("zoom", zoom))
         .append("g");

function zoom() {
    svg.attr("transform","translate("+ d3.event.translate+") scale("+d3.event.scale+")");  
}

Here is the fiddle 这是小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM