public static int CompareByValueDecreasing(WeightUIElement x, WeightUIElement y)
 {
     if (x == null)
     {
         if (y == null)
         {
             return(-1);
         }
         else
         {
             return(0);
         }
     }
     else
     {
         if (y == null)
         {
             return(1);
         }
         else
         {
             return(x.Weight.CompareTo(y.Weight) * -1);
         }
     }
 }
        private void PrepareItems()
        {
            _weightSum = 0;
            this.ManagedItems.Clear();


            foreach (UIElement child in this.Children)
            {
                WeightUIElement element = new WeightUIElement(child, TreeMapsPanel.GetWeight(child));
                if (this.IsValidItem(element))
                {
                    _weightSum += element.Weight;
                    this.ManagedItems.Add(element);
                }
                else
                {
                    element.ComputedSize     = Size.Empty;
                    element.ComputedLocation = new Point(0, 0);
                    element.UIElement.Measure(element.ComputedSize);
                    element.UIElement.Visibility = Visibility.Collapsed;
                }
            }

            this.ManagedItems.Sort(WeightUIElement.CompareByValueDecreasing);
        }
        private void Squarify(List <WeightUIElement> items, List <WeightUIElement> row, double sideLength)
        {
            if (items.Count == 0)
            {
                this.AddRowToLayout(row);
                return;
            }

            WeightUIElement        item = items[0];
            List <WeightUIElement> row2 = new List <WeightUIElement>(row);

            row2.Add(item);
            List <WeightUIElement> items2 = new List <WeightUIElement>(items);

            items2.RemoveAt(0);

            double worst1 = this.Worst(row, sideLength);
            double worst2 = this.Worst(row2, sideLength);

            if (row.Count == 0 || worst1 > worst2)
            {
                this.Squarify(items2, row2, sideLength);
            }
            else
            {
                this.AddRowToLayout(row);
                this.Squarify(items, new List <WeightUIElement>(), this.GetShortestSide());
            }
        }
 protected virtual Rect GetRectangle(RowOrientation orientation, WeightUIElement item, double x, double y, double width, double height)
 {
     if (orientation == RowOrientation.Horizontal)
     {
         return(new Rect(x, y, item.RealArea / height, height));
     }
     else
     {
         return(new Rect(x, y, width, item.RealArea / width));
     }
 }
 public static int CompareByValueDecreasing(WeightUIElement x, WeightUIElement y)
 {
   if (x == null)
   {
     if (y == null)
       return -1;
     else
       return 0;
   }
   else
   {
     if (y == null)
       return 1;
     else
       return x.Weight.CompareTo(y.Weight) * -1;
   }
 }
    private void PrepareItems()
    {

      _weightSum = 0;
      this.ManagedItems.Clear();


      foreach (UIElement child in this.Children)
      {
        WeightUIElement element = new WeightUIElement(child, TreeMapsPanel.GetWeight(child));
        if (this.IsValidItem(element))
          {
            _weightSum += element.Weight;
            this.ManagedItems.Add(element);
          }
          else
          {
            element.ComputedSize = Size.Empty;
            element.ComputedLocation = new Point(0, 0);
            element.UIElement.Measure(element.ComputedSize);
            element.UIElement.Visibility = Visibility.Collapsed;
          }
      }

      this.ManagedItems.Sort(WeightUIElement.CompareByValueDecreasing);
    }
 private bool IsValidItem(WeightUIElement item)
 {
   return (item != null && item.Weight != double.NaN && Math.Round(item.Weight, 0) != 0);
 }
 protected virtual Rect GetRectangle(RowOrientation orientation, WeightUIElement item, double x, double y, double width, double height)
 {
   if (orientation == RowOrientation.Horizontal)
     return new Rect(x, y, item.RealArea / height, height);
   else
     return new Rect(x, y, width, item.RealArea / width);
 }
 private bool IsValidItem(WeightUIElement item)
 {
     return(item != null && item.Weight != double.NaN && Math.Round(item.Weight, 0) != 0);
 }