首先,我将展示大约我在此尝试完成的内容。 The desired effect. 请注意,它不是确切的,因为目前的系统无法正常工作。这就是我来这里的原因。排序视觉节点阵列
我一直在试图解决这个问题一段时间。到目前为止,我得到了这个代码,但它不能正常工作。
public double UpdateChildPosition(bool fromParent)
{
if (children.Count == 0)
return 0;
if (!fromParent && parentnode != null)
{
parentnode.UpdateChildPosition(false);
return 0;
}
double cwidth = 0;
if ((fromParent && children.Count > 0) || parentnode == null)
children.ForEach((n) => cwidth += n.UpdateChildPosition(true));
double width = children.Sum((n) => n.rectangle1.Width + 10) + cwidth/2;
double x = 0 - width/2;
foreach (MindmapNode node in children)
{
node.x = x;
x += node.rectangle1.Width + 10 + cwidth/children.Count;
node.y = 50;
}
return width;
}
相反,它创建这样的:
Picture of the current effect http://img29.imageshack.us/img29/9660/effectg.png
我给也许有点太少的信息,但我不完全知道有多少是必要的。询问更多信息。 谢谢!
没有让我发布图片,因为有新帐户。
编辑 我忘了说,在我的系统中,坐标是相对于父项。
EDIT2 我已经取得了一些进展。目前的问题是:当节点的大小改变时(是的,它们是动态的)它们重叠。
List<MindmapNode> children;
public double UpdateChildPosition(bool fromParent)
{
if (children.Count == 0)
return rectangle1.Width + 10;
if (!fromParent && parentnode != null)
{
parentnode.UpdateChildPosition(false);
return 0;
}
double[] childrenwidth = new double[children.Count];
//if ((fromParent && children.Count > 0) || parentnode == null)
List<MindmapNode> rchildren = (from n in children
where n.moved == false
select n).ToList();
(from n in children
where rchildren.Contains(n) == false
select n).ToList().ForEach((n) => n.UpdateChildPosition(true));
int i = 0;
rchildren.ForEach((n) => childrenwidth[i++] =
Math.Max(n.UpdateChildPosition(true), (n.children.Count > 0) ? n.rectangle1.Width * 2 : 0));
double width = childrenwidth.Sum();
double x = -width/2;
i = 0;
foreach (MindmapNode node in rchildren)
{
x += childrenwidth[i]/2;
node.x = x;
x += childrenwidth[i]/2;
node.y = 50;
i++;
node.SetOrigin();
}
return width;
}
你碰到什么问题?我看不到当前和期望之间的任何区别。 – 2013-03-16 18:19:35
@PieterGeerkens他希望每个子节点组位于其父节点下方,看起来像。我不知道他是否希望绿色节点或紫色节点均匀分布;这两者之间的选择意味着解决问题的不同方法。 – Random832 2013-03-16 18:21:05
@ Random832:现在明白了; TY。 – 2013-03-16 18:21:45