简体   繁体   English

SVG / Raphael,如何在javascript中实现DOT算法? (图组织)

[英]SVG / Raphael, how does one implement the DOT algorithm in javascript? (Graph organization)

My fiddle: http://jsfiddle.net/G5mTx/10/ 我的小提琴: http : //jsfiddle.net/G5mTx/10/

As you can see, the current way I'm organizing the nodes does no balancing, and there is some overlap when parent nodes have more than 1 child node. 如您所见,当前组织节点的方式没有平衡,并且当父节点有多个子节点时会有一些重叠。

For those not familiar with the DOT algorithm, a brief, vague explanation can be found here: http://www.ece.uci.edu/~jhahn/pdf/dot.pdf 对于那些不熟悉DOT算法的人,可以在这里找到简短的,模糊的解释: http : //www.ece.uci.edu/~jhahn/pdf/dot.pdf

Basically, DOT organizes the nodes such that the graph is optimal, which means that it is concise, has minimal line crossing, and is balanced. 基本上,DOT对节点进行组织,以使图形最优,这意味着它简洁明了,具有最小的线交叉并且是平衡的。

I've heard of some people running the DOT algorithm server side before sending it to the client... which would be consistantly faster... but I need each of the nodes to have hover and click states, as I plan on allowing the user to re-assign where the arrows / lines point. 我听说有人在将DOT算法服务器端发送给客户端之前运行DOT算法服务器端……这通常会更快……但是我需要每个节点都具有悬停和单击状态,因为我计划允许用户将箭头/直线指向的位置重新分配。

I mean, I COULD do the SVG generation server-side.. but then how would I hook up hover / click events to the nodes, and have the tell the server which Model the node represents upon line re-assignment? 我的意思是,我可以在服务器端执行SVG生成。但是,如何将悬停/单击事件挂接到节点上,并告诉服务器该节点在重新分配线路时代表哪个模型?

Note: My server runs Ruby on Rails 2.3.8 注意:我的服务器运行Ruby on Rails 2.3.8

I struggled with exactly this situation and ran the DOT algorithm on my server, sending only the new coordinates for the nodes back to the browser. 我在这种情况下苦苦挣扎,并在服务器上运行了DOT算法,仅将节点的新坐标发送回浏览器。 Ultimately I found the setup unsatisfactory. 最终,我发现设置不令人满意。

I switched to using D3's force layout algorithm , which is implemented in Javascript and appears to be more modern than DOT's, and now I'm much happier. 我改用了D3的强制布局算法 ,该算法是用Javascript实现的,而且似乎比DOT的更现代,现在我更开心了。

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

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