Exemplo n.º 1
0
        private void CalcLayout(MapItem[] items, int start, int end, MapRect bounds)
        {
            if (start > end)
            {
                return;
            }
            if (start == end)
            {
                items[start].Bounds = bounds;
            }

            fMid = start;
            while (fMid < end)
            {
                if (GetHighestAspect(items, start, fMid, bounds) > GetHighestAspect(items, start, fMid + 1, bounds))
                {
                    fMid++;
                }
                else
                {
                    MapRect newBounds = LayoutRow(items, start, fMid, bounds);
                    CalcLayout(items, fMid + 1, end, newBounds);
                }
            }
        }
Exemplo n.º 2
0
        public void CalcLayout(List <MapItem> itemsList, MapRect bounds)
        {
            if (itemsList == null || itemsList.Count <= 0)
            {
                return;
            }

            // calculate sum for current level
            double sum = 0;

            foreach (MapItem item in itemsList)
            {
                sum += item.GetCalcSize();
            }

            // calculate relative sizes for current level
            double totalArea = bounds.W * bounds.H;

            foreach (MapItem item in itemsList)
            {
                item.Ratio = (totalArea / sum * item.GetCalcSize());
            }

            MapItem[] itemsArr = new MapItem[itemsList.Count];
            itemsArr = itemsList.ToArray();
            QuickSortDesc(itemsArr, 0, itemsArr.Length - 1);

            CalcLayout(itemsArr, 0, itemsArr.Length - 1, bounds);
        }
Exemplo n.º 3
0
 public MapItem(string name, double size)
 {
     fItems    = new List <MapItem>();
     fName     = name;
     fSize     = size;
     fBounds   = new MapRect();
     fCalcSize = 0;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Arrange the items in the given MapModel to fill the given rectangle.
        /// </summary>
        /// <param name="bounds">The bounding rectangle for the layout.</param>
        public void CalcLayout(MapRect bounds)
        {
            // calculate all true sizes for treemap
            foreach (MapItem item in fItems)
            {
                item.CalculateSize();
            }

            // calculate bounds of item for all levels
            CalcRecursiveLayout(fItems, bounds);
        }
Exemplo n.º 5
0
        private double GetHighestAspect(MapItem[] items, int start, int end, MapRect bounds)
        {
            LayoutRow(items, start, end, bounds);
            double max = double.MinValue;

            for (int i = start; i <= end; i++)
            {
                if (items[i].Bounds.GetAspectRatio() > max)
                {
                    max = items[i].Bounds.GetAspectRatio();
                }
            }
            return(max);
        }
Exemplo n.º 6
0
        public void CalcRecursiveLayout(List <MapItem> itemsList, MapRect bounds)
        {
            CalcLayout(itemsList, bounds);

            foreach (MapItem item in itemsList)
            {
                if (item.IsLeaf())
                {
                    continue;
                }

                CalcRecursiveLayout(item.Items, item.Bounds);
            }
        }
Exemplo n.º 7
0
        private MapRect LayoutRow(MapItem[] items, int start, int end, MapRect bounds)
        {
            bool   isHorizontal = bounds.W > bounds.H;
            double total        = bounds.W * bounds.H; //totalSize(items, 0, items.length-1);
            double rowSize      = GetTotalSize(items, start, end);
            double rowRatio     = rowSize / total;
            double offset       = 0;

            for (int i = start; i <= end; i++)
            {
                MapRect r     = new MapRect();
                double  ratio = items[i].Ratio / rowSize;

                if (isHorizontal)
                {
                    r.X = bounds.X;
                    r.W = bounds.W * rowRatio;
                    r.Y = bounds.Y + bounds.H * offset;
                    r.H = bounds.H * ratio;
                }
                else
                {
                    r.X = bounds.X + bounds.W * offset;
                    r.W = bounds.W * ratio;
                    r.Y = bounds.Y;
                    r.H = bounds.H * rowRatio;
                }
                items[i].Bounds = r;
                offset         += ratio;
            }
            if (isHorizontal)
            {
                return(new MapRect(bounds.X + bounds.W * rowRatio, bounds.Y, bounds.W - bounds.W * rowRatio, bounds.H));
            }
            else
            {
                return(new MapRect(bounds.X, bounds.Y + bounds.H * rowRatio, bounds.W, bounds.H - bounds.H * rowRatio));
            }
        }
Exemplo n.º 8
0
 public MapItem(double size, int order)
 {
     fSize   = size;
     fOrder  = order;
     fBounds = new MapRect();
 }