我只是想通过使用d3.js库在javascript中绘制函数。我需要添加缩放和平移事件。我按照这个例子完成了它:
http://bl.ocks.org/mbostock/7ec977c95910dd026812
我在这架飞机上划了一些线。 我的问题是,当我缩放它时,线宽也会改变。 我喜欢的是该线在缩放时仍具有原始宽度。我想我必须重新绘制它,但我不确定这是否是最佳方式。
你能告诉我是否有更好的方法可以做到这一点,或者告诉我一个简单的例子? 谢谢!
答案 0 :(得分:0)
As you have not supplied any code it is a bit hard to tell. From your description the grid lines you are rendering are being transformed by the zoom matrix.
You can either draw the grid independently of the zoom but you will have to switch between zoomed and grid transforms and will require more code or just re-render the grid lines with the width set to the width times the inverse scale. Eg if your grid lines are two pixels then you can can keep them that width by setting their render width to 2*(1/scale)
which is the same as 2/scale
. Scale being the amount of zoom. The same applies to any objects you wish to keep at a fixed render size.
There is no easy way to avoid re-rendering the gridlines
答案 1 :(得分:0)