简体   繁体   English

在d3中设定特定的缩放等级?

[英]Setting specific zoom levels in d3?

I have a line graph in d3, and we need to implement specific zoom levels, similar to Google maps. 我在d3中有一个折线图,我们需要实现特定的缩放级别,类似于Google地图。 I want a mouse wheel zoom in action to snap/transition to the next possible inward zoom level, and a mouse wheel zoom out action to snap/transition to the next possible outward zoom level. 我希望鼠标滚轮放大动作可以捕捉/转换到下一个可能的向内缩放级别,而鼠标滚轮缩小动作可以捕捉/转换到下一个可能的向外缩放级别。

My setup for the zoom method is similar to everyone else's: 我对zoom方法的设置类似于其他所有人的设置:

        self.plot.call(d3.behavior.zoom().x(self.x).y(self.y).on("zoom", self.redraw()));

But I don't know enough about d3 (nor do I have tons of time left...) to know how to set this. 但是我对d3知之甚少(我也没有剩下很多时间...)来知道如何设置它。 Any tips/help? 任何提示/帮助吗?

You can change your zoom event listener to interject the event and adjust the scale as you like (eg round to the next integer). 您可以更改缩放事件侦听器以插入事件并根据需要调整缩放比例(例如,舍入到下一个整数)。 There's a blog post that explains a bit more here . 有一篇博客文章, 这里有更多解释。

This is a bit more work than simply attaching the zoom behaviour to an axis, but d3 doesn't offer anything to restrict the zoom levels out of the box. 与仅将缩放行为附加到轴上相比,这需要做更多的工作,但是d3并没有提供任何限制缩放级别的功能。

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

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