Hello everyone,
Does someone of you have translated this C#-Project Algorithm for Drawing Trees to Xojo before? Have some Problems to convert it…like these ones (the Dictionary-Things ):
[h]TreeNodeHelper.cs[/h]
[code]private static void CalculateFinalPositions(TreeNodeModel node, float modSum)
{
node.X += modSum;
modSum += node.Mod;
foreach (var child in node.Children)
CalculateFinalPositions(child, modSum);
if (node.Children.Count == 0)
{
node.Width = node.X;
node.Height = node.Y;
}
else
{
node.Width = node.Children.OrderByDescending(p => p.Width).First().Width; // ??? OrderByDescending
node.Height = node.Children.OrderByDescending(p => p.Height).First().Height; // ??? OrderByDescending
}
}
private static void CheckForConflicts(TreeNodeModel node)
{
var minDistance = treeDistance + nodeSize;
var shiftValue = 0F; // declared as Float = Double, but what does 0F mean???
var nodeContour = new Dictionary<int, float>();
GetLeftContour(node, 0, ref nodeContour);
var sibling = node.GetLeftMostSibling();
while (sibling != null && sibling != node)
{
var siblingContour = new Dictionary<int, float>();
GetRightContour(sibling, 0, ref siblingContour);
for (int level = node.Y + 1; level <= Math.Min(siblingContour.Keys.Max(), nodeContour.Keys.Max()); level++)
{
var distance = nodeContour[level] - siblingContour[level];
if (distance + shiftValue < minDistance)
{
shiftValue = minDistance - distance;
}
}
if (shiftValue > 0)
{
node.X += shiftValue;
node.Mod += shiftValue;
CenterNodesBetween(node, sibling);
shiftValue = 0;
}
sibling = sibling.GetNextSibling();
}
}
private static void CheckAllChildrenOnScreen(TreeNodeModel node)
{
var nodeContour = new Dictionary<int, float>();
GetLeftContour(node, 0, ref nodeContour);
float shiftAmount = 0;
foreach (var y in nodeContour.Keys)
{
if (nodeContour[y] + shiftAmount < 0)
shiftAmount = (nodeContour[y] * -1);
}
if (shiftAmount > 0)
{
node.X += shiftAmount;
node.Mod += shiftAmount;
}
}
private static void GetLeftContour(TreeNodeModel node, float modSum, ref Dictionary<int, float> values)
{
if (!values.ContainsKey(node.Y))
values.Add(node.Y, node.X + modSum);
else
values[node.Y] = Math.Min(values[node.Y], node.X + modSum);
modSum += node.Mod;
foreach (var child in node.Children)
{
GetLeftContour(child, modSum, ref values);
}
}
private static void GetRightContour(TreeNodeModel node, float modSum, ref Dictionary<int, float> values)
{
if (!values.ContainsKey(node.Y))
values.Add(node.Y, node.X + modSum);
else
values[node.Y] = Math.Max(values[node.Y], node.X + modSum);
modSum += node.Mod;
foreach (var child in node.Children)
{
GetRightContour(child, modSum, ref values);
}
}[/code]