private MapRow getRow() { double left, top; if (mapRows.Count == 0) { left = 0; top = 0; } else { var lastRow = mapRows.Last(); if (lastRow.Orientation == Orientation.Horizontal) { left = lastRow.Left; top = lastRow.Height + lastRow.Top; } else { left = lastRow.Width + lastRow.Left; top = lastRow.Top; } } Orientation orientation; if (mapWidth > mapHeight) { orientation = Orientation.Vertical; } else { orientation = Orientation.Horizontal; } var mapRow = new MapRow(left, top, orientation, mapHeight, mapWidth, currentArea); return(mapRow); }
private void squarify(List <RowElement> children, MapRow row, double width) { if (children.Count == 0) { row.CompleteRow(); mapRows.Add(row); return; } var first = children[0]; var values = row.getElementsValues(); var temp = values.Select(x => x).ToList(); temp.Add(first.Value); if (getMaxRatio(row.getElementsValues(), width) >= getMaxRatio(temp, width)) { row.AddElement(first); children.RemoveAt(0); squarify(children, row, width); } else { row.CompleteRow(); currentArea = currentArea - row.getArea(); if (row.Orientation == Orientation.Horizontal) { mapHeight -= row.Height; } else { mapWidth -= row.Width; } mapRows.Add(row); var newRow = getRow(); squarify(children, newRow, Math.Min(mapHeight, mapWidth)); } }