Dragging and highlighting

筅森魡賤 提交于 2019-12-11 06:28:04

问题


In this jsfiddle user is supposed to be able to drag a node, and while he/she is dragging, only that node and his neighbors, and links between them, should be highlighted.

I thought I have a good solution, but a problem was reported if the user drags node to the boundary, and in such case there is undesired behavior - all nodes suddenly are highlighted:

(ERROR IS WHEN DRAGGED NODE HITS THE WALL)

This is due to the fact that mouse pointer went away from the node, but user is still keeping the mouse buttons, and still expects only selected node to be highlighted, and others to remain grayed.

Can this be fixed? Can I redesign events so that this situation is cured?


回答1:


What you want is to fade the non-neighboring nodes while one of them is being dragged, not only on mouseover:

force.drag().on('drag', fade(.1));

Working example: http://jsfiddle.net/h358K/

Note that for symmetry, you might want to fade in the nodes on dragstop.



来源:https://stackoverflow.com/questions/21393768/dragging-and-highlighting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!