2013-03-16 87 views
1

首先,我将展示大约我在此尝试完成的内容。 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; 
    } 
+0

你碰到什么问题?我看不到当前和期望之间的任何区别。 – 2013-03-16 18:19:35

+0

@PieterGeerkens他希望每个子节点组位于其父节点下方,看起来像。我不知道他是否希望绿色节点或紫色节点均匀分布;这两者之间的选择意味着解决问题的不同方法。 – Random832 2013-03-16 18:21:05

+0

@ Random832:现在明白了; TY。 – 2013-03-16 18:21:45

回答

0

这应该为每个家庭工作:

X = ((children.Last.Right - children.First.Left)/2) - Width/2; 

在我看来,这是需要什么,翻译直入代码的定义。

+0

我似乎无法理解这个应该如何实施。 – Rare 2013-03-16 18:27:06

+0

您是否希望将父母亲放入孩子(最好是我认为的)还是相对于父母的孩子? – 2013-03-16 18:58:17

+0

“子节点均匀分布,递归遍布各层节点。”可能应该添加相对于父项。请注意它是递归的,因为在节点下的节点下可以有节点 - 大小是动态的。 – Rare 2013-03-16 19:03:50