如何禁用 d3.behavior.zoom 的双击缩放? [英] How to disable double click zoom for d3.behavior.zoom?
问题描述
我不希望 d3.behavior.zoom添加在我的图表上双击缩放的功能.如何禁用此行为?
I do not want d3.behavior.zoom to add the ability to double click zoom on my graph. How can I disable this behavior?
这是一个带有不需要的行为的 JSFiddle.
Here is a JSFiddle with the unwanted behavior.
我尝试了以下但没有任何运气.
I have tried the following without any luck.
d3.behavior.zoom.dblclick = function() {};
推荐答案
您可以通过移除缩放行为的 dblclick 事件侦听器来禁用双击行为.查看您的代码,您已将缩放行为分配给 SVG 元素.所以你可以说:
You can disable the double-click behavior by removing the zoom behavior’s dblclick event listener. Looking at your code, you’ve assigned the zoom behavior to the SVG element. So you could say:
d3.select("svg").on("dblclick.zoom", null);
或者,连同您注册缩放行为的位置:
Or, together with where you register the zoom behavior:
.call(d3.behavior.zoom().on("zoom", update)).on("dblclick.zoom", null)
您可能还想将缩放行为向下移动到 G 元素,而不是将它位于根 SVG 元素上;我不确定它是否会在根 SVG 上正常工作,因为 SVG 元素不支持 转换属性.
You might also want to move the zoom behavior down to a G element rather than putting it on the root SVG element; I’m not sure it will work correctly on the root SVG, since the SVG element doesn’t support the transform attribute.
这篇关于如何禁用 d3.behavior.zoom 的双击缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!