[英]Programatic zoom in D3
Using the code pattern here , I want to programmatically achieve semantic zooming (in or out). 使用此处的代码模式,我想以编程方式实现语义放大(放大或缩小)。 I'm unsure how to get the proper x, y, and scaleExtent terms that are augmented via the zoom: 我不确定如何获得适当的x,y和scaleExtent项,这些项会通过zoom扩展:
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.call(d3.behavior.zoom().x(x).y(y).scaleExtent([1, 8]).on("zoom", zoom));
See JSfiddle here . 在这里查看JSfiddle。 The zoomIn and zoomOut functions should simulate the mousewheel events centered in the SVG. zoomIn和zoomOut函数应模拟以SVG为中心的鼠标滚轮事件。
Here's a solution based on the answer below: http://jsbin.com/dociwuvacu/1 这是基于以下答案的解决方案: http : //jsbin.com/dociwuvacu/1
I believe I successfully updated your fiddle, but in case not, here is the type of code you would need: 我相信我已经成功更新了您的小提琴,但是如果没有,这是您需要的代码类型:
function zoomIn() {
zoomer.scale(zoomer.scale()+.1);
zoomer.event(svg);
}
function zoomOut() {
zoomer.scale(zoomer.scale()-.1);
zoomer.event(svg);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.