Hi, i am using release 1.2.3.4.
i have a TreeLayout containing too many small tree to either arrange only vertical or horizontal.
i want to be able arrange them vertically but to wrap them into multiple columns.
any help would appreciated.
BTW its been a while since my last visit here, i am glad to see its still very much alive and kicking
Thanks, Aviv and the BMC team.
Thanks!
here is my new layout in case someone needs it :
public class VerticalWrapTreeLayout : TreeLayout
{ #region NumberOfColumns (DependencyProperty)
public int NumberOfColumns
{
get { return (int)GetValue(NumberOfColumnsProperty); }
set { SetValue(NumberOfColumnsProperty, value); }
}
public static readonly DependencyProperty NumberOfColumnsProperty =
DependencyProperty.Register(
"NumberOfColumns",
typeof(int),
typeof(VerticalWrapTreeLayout),
new PropertyMetadata(5)
);
#endregion
protected override void ArrangeTrees()
{
var p = ArrangementOrigin;
int nodesPerColumn = Roots.Count < NumberOfColumns ? Roots.Count : Roots.Count / NumberOfColumns;//we want 5 columns
var counter = 0;
var maxTreeWidth = 0.0;
foreach (var r in Roots)
{
counter++;
var root = Network.FindVertex(r);
if (root == null) continue;
var q = p;
q.X += root.SubtreeOffset.X;
q.Y += root.SubtreeOffset.Y;
AssignAbsolutePositions(root, q);
if (root.SubtreeSize.Width > maxTreeWidth) maxTreeWidth = root.SubtreeSize.Width;//maintain max tree width within column
if (counter % nodesPerColumn == 0)//move start point to next column
{
p.X += maxTreeWidth + ArrangementSpacing.Width;//move x to the left as much as the widest tree in the column
p.Y = ArrangementOrigin.Y;//move y up the the start point
maxTreeWidth = 0.0;//new column max will start fresh
}
else
{
p.Y += root.SubtreeSize.Height + ArrangementSpacing.Height;//next node moves down
}
}
}
internal void AssignAbsolutePositions(TreeVertex v, Point p)
{
if (v == null) return;
v.Position = p;
foreach (var c in v.Children)
{
AssignAbsolutePositions(c, new Point(p.X + c.RelativePosition.X, p.Y + c.RelativePosition.Y));
}
}
}