如何禁用d3.behavior.zoom的双击缩放? [英] How to disable double click zoom for d3.behavior.zoom?

查看:1023
本文介绍了如何禁用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆