まず、ここで達成しようとしたことをおおよそ示します。 望ましい効果。 現在のシステムは機能しないため、正確ではないことに注意してください。それが私がここにいる理由です。
私はしばらくの間、この問題を解決しようとしてきました。これまでにこのコードを取得しましたが、正しく機能していません。
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;
}
代わりに、これを作成します。
少し情報が少なすぎるかもしれませんが、どれだけ必要かは正確にはわかりません。詳しくはお尋ねください。ありがとう!
新しいアカウントのため、画像を投稿できませんでした。
編集 私のシステムでは、座標は親に対して相対的であると言うのを忘れていました。
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;
}