简体   繁体   English

以编程方式放大D3?

[英]Programmatically Zooming in D3?

使用JavaScript可视化库D3,如何以编程方式设置缩放行为,以使其跳至其他位置,然后在滚动或缩放时不仅仅恢复到原始位置?

The reason it jumps is that within the code for the zoom behaviour, D3 copies the scale and uses that to make calculations for scrolling and zooming. 它跳跃的原因是,在缩放行为代码中,D3复制了缩放比例,并使用该比例进行滚动和缩放计算。 To fix it you need to force the internal copy to go to the position that you want. 要解决此问题,您需要强制内部副本转到所需位置。

This can be done by calling .x or .y on the zoom object. 这可以通过在缩放对象上调用.x或.y来完成。 For example, if you had an xScale that you change then pass the xScale back into the .x of the zoom object to set the internal copy to that xScale. 例如,如果您更改了xScale,则将xScale传递回缩放对象的.x,以将内部副本设置为该xScale。

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

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