我正在使用此工作代码作为入门。我正在尝试根据我的数据和需要进行修改。
我唯一不明白的是为什么这种放大缩小不起作用。我试过这个解决方案,但没有运气。
我无法在代码中找到问题所在,但我可以看到评论中指出该功能已停用。我怎样才能激活它?对不起,如果这是一个愚蠢的问题,我仍然是 js 的新手。也有类似的问题,但问题是 jsfiddle 不再工作了,所以我看不到整个代码来理解逻辑。
// Zoom functionnality is desactivated (user can use browser Ctrl + mouse wheel shortcut)
function zoomAndDrag() {
//var scale = d3.event.scale,
var scale = 1,
translation = d3.event.translate,
tbound = -height * scale,
bbound = height * scale,
lbound = (-width + margin.right) * scale,
rbound = (width - margin.left) * scale;
// limit translation to thresholds
translation = [
Math.max(Math.min(translation[0], rbound), lbound),
Math.max(Math.min(translation[1], bbound), tbound)
];
d3.select('.drawarea')
.attr('transform', 'translate(' + translation + ')' +
' scale(' + scale + ')');
}
这是代码的工作演示:https : //blockbuilder.org/ninjakx/2c4e726a531b40f9f09d7df41217d1de
D3 使用鼠标滚轮事件来实现放大/缩小功能。您的示例在此行中禁用鼠标滚轮事件:
d3.select('#tree-container').select('svg').on(mouseWheelName, null);
此外,该演示使用 D3 的第 3 版,我强烈建议使用该库的最新版本(V5)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句