中心力导向布局后使用根节点(返回中心)

编程入门 行业动态 更新时间:2024-10-17 07:24:45
本文介绍了中心力导向布局后使用根节点(返回中心)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用D3.js尝试强制导向布局。我需要的是中心布局的根(或其他选定的节点),并返回此节点到svg(例如画布)中心后,tick函数完成(图的alpha是低)。可能吗?我在

I am experimenting with force directed layout using D3.js. What I need is center the layout by root (or other selected node) and return this node to the svg (e.g. canvas) center after the tick function is done (the graph alpha is low). Is it possible? I found an example at

http://bl.ocks / 1080941

但我无法使根(在使用aplha或其他自定义tick函数计算时)返回中心布局由这个特定的节点)。

but I am unable to make the root (when using aplha or other custom tick function calculation) return back to the center (center the layout by this particular node).

任何帮助将不胜感激。

推荐答案

其实我这样解决这个问题(类似以前但更复杂):

Actually I solved this like this(similar to previous but more sophisticated):

force.on("tick", function(e) { node.attr("transform", function(d) { //TODO move these constants to the header section //center the center (root) node when graph is cooling down if(d.index==0){ damper = 0.1; d.x = d.x + (w/2 - d.x) * (damper + 0.71) * e.alpha; d.y = d.y + (h/2 - d.y) * (damper + 0.71) * e.alpha; } //start is initiated when importing nodes from XML if(d.start === true){ d.x = w/2; d.y = h/2; d.start = false; } r = d.name.length; //these setting are used for bounding box, see [blockses.appspot/1129492][1] d.x = Math.max(r, Math.min(w - r, d.x)); d.y = Math.max(r, Math.min(h - r, d.y)); return "translate("+d.x+","+d.y+")"; } ); });

更多推荐

中心力导向布局后使用根节点(返回中心)

本文发布于:2023-11-25 00:37:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:心力   节点   导向   布局   中心

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!