Manages the various free space boxes that are available
All methods are static.
Пример #1
0
        RecalculateFreeSpace
        (
            LinkedListNode <FreeSpaceBox> freeSpaceBoxNode,
            RectangleF boxPlaced
        )
        {
            FreeSpaceBox freeSpaceBox = freeSpaceBoxNode.Value;

            float top, bottom, right, left;

            if (freeSpaceBox.orientation == FreeSpaceBox.Orientation.Horiz)
            {
                top    = freeSpaceBox.boxRectangle.Top;
                left   = boxPlaced.Right;
                right  = freeSpaceBox.boxRectangle.Right;
                bottom = freeSpaceBox.boxRectangle.Bottom;
            }
            else
            {
                top    = boxPlaced.Bottom;
                left   = freeSpaceBox.boxRectangle.Left;
                right  = freeSpaceBox.boxRectangle.Right;
                bottom = freeSpaceBox.boxRectangle.Bottom;
            }

            FreeSpaceBox newFreeSpaceBox     = new FreeSpaceBox(left, top, right, bottom, freeSpaceBox.orientation);
            double       newFreeSpaceBoxArea = newFreeSpaceBox.GetArea();

            freeSpaceBoxList.AddLast(newFreeSpaceBox);
            freeSpaceBoxList.Remove(freeSpaceBoxNode);
        }
Пример #2
0
        PlaceGroupInFreeBox
        (
            GroupInfo groupToBePlaced,
            double groupArea,
            FreeSpaceBox freeBox
        )
        {
            double gLeft, gRight, gTop, gBottom, gHeight, gWidth;

            if (freeBox.orientation == FreeSpaceBox.Orientation.Vert)
            {
                gLeft   = freeBox.boxRectangle.Left;
                gRight  = freeBox.boxRectangle.Right;
                gTop    = freeBox.boxRectangle.Top;
                gHeight = groupArea / ((double)(gRight - gLeft));
                gBottom = gTop + gHeight;
            }
            else
            {
                gLeft   = freeBox.boxRectangle.Left;
                gTop    = freeBox.boxRectangle.Top;
                gBottom = freeBox.boxRectangle.Bottom;
                gWidth  = groupArea / ((double)Math.Abs(gTop - gBottom));
                gRight  = gLeft + gWidth;
            }
            return(RectangleF.FromLTRB((float)gLeft, (float)gTop, (float)gRight, (float)gBottom));
        }
Пример #3
0
        LayoutAllGroupsInDonut
        (
            Rectangle graphRectangle,
            IList <GroupInfo> sortedGroups,
            double alpha,
            double gamma,
            double ARs,
            Int32 iSortedGroupCount,
            Double dTotalNumberOfVertices
        )
        {
            aoGroupRectangles = new RectangleF[iSortedGroupCount];
            Boolean done = false;

            while (!done)
            {
redoDonut:
                // Place the biggest group at the center
                double ratioCenterGroup = gamma * ((double)sortedGroups[0].Vertices.Count / dTotalNumberOfVertices);
                Debug.Assert(ratioCenterGroup > 0);
                double AreaCenterGroup   = ratioCenterGroup * graphRectangle.Width * graphRectangle.Height;
                double centerGroupWidth  = Math.Sqrt(ratioCenterGroup * graphRectangle.Width * graphRectangle.Height / ARs);
                double centerGroupHeight = Math.Sqrt(ratioCenterGroup * graphRectangle.Width * graphRectangle.Height * ARs);
                double centerX           = (graphRectangle.Left + graphRectangle.Right) / 2;
                double centerY           = (graphRectangle.Top + graphRectangle.Bottom) / 2;
                Debug.Assert(centerGroupHeight > 0);
                Debug.Assert(centerGroupWidth > 0);

                double dGroupTop    = centerY - (centerGroupHeight / 2);
                double dGroupBottom = centerY + (centerGroupHeight / 2);
                double dGroupLeft   = centerX - (centerGroupWidth / 2);
                double dGroupRight  = centerX + (centerGroupWidth / 2);

                // Assign the boundaries to center group's rectangle
                aoGroupRectangles[0] = RectangleF.FromLTRB((float)dGroupLeft,
                                                           (float)dGroupTop, (float)dGroupRight, (float)dGroupBottom);

                // Calculate the free spaces. Constructor follows the Left, Top, Right, Bottom order
                FreeSpaceBox B1 = new FreeSpaceBox(graphRectangle.Left, graphRectangle.Top, graphRectangle.Right, (float)dGroupTop, FreeSpaceBox.Orientation.Horiz);
                FreeSpaceBox B2 = new FreeSpaceBox(graphRectangle.Left, (float)dGroupTop, (float)dGroupLeft, graphRectangle.Bottom, FreeSpaceBox.Orientation.Vert);
                FreeSpaceBox B3 = new FreeSpaceBox((float)dGroupLeft, (float)dGroupBottom, graphRectangle.Right, graphRectangle.Bottom, FreeSpaceBox.Orientation.Horiz);
                FreeSpaceBox B4 = new FreeSpaceBox((float)dGroupRight, (float)dGroupTop, graphRectangle.Right, (float)dGroupBottom, FreeSpaceBox.Orientation.Vert);

                // Place the boxes in the linked list
                freeSpaceBoxList = new LinkedList <FreeSpaceBox>();
                freeSpaceBoxList.AddFirst(B1);
                freeSpaceBoxList.AddLast(B3);
                freeSpaceBoxList.AddLast(B4);
                freeSpaceBoxList.AddLast(B2);

                done = ArrangeRemainingGroupsInFreeSpaces(graphRectangle, sortedGroups, gamma, iSortedGroupCount, dTotalNumberOfVertices);
                if (!done)
                {
                    gamma = gamma * alpha; // ETM: alpha has been set in Layouts->Layouts->LayoutBase.cs
                    Debug.Assert(gamma > 0);
                    for (int j = 0; j < iSortedGroupCount; j++)
                    {
                        aoGroupRectangles[j] = RectangleF.Empty;
                        freeSpaceBoxList     = new LinkedList <FreeSpaceBox>();
                    }
                    goto redoDonut;
                }
            }
            for (Int32 i = 0; i < iSortedGroupCount; i++)
            {
                sortedGroups[i].Rectangle = GraphicsUtil.RectangleFToRectangle(aoGroupRectangles[i], 1);
            }
        }
Пример #4
0
        LayoutAllGroupsInU
        (
            Rectangle graphRectangle,
            IList <GroupInfo> sortedGroups,
            double alpha,
            double gamma,
            double ARs,
            Int32 iSortedGroupCount,
            Double dTotalNumberOfVertices
        )
        {
            aoGroupRectangles = new RectangleF[iSortedGroupCount];
            Boolean done = false;

            while (!done)
            {
redoU:
                // Place the biggest group at the top center
                double ratioFirstGroup = gamma * ((double)sortedGroups[0].Vertices.Count / dTotalNumberOfVertices);

                Debug.Assert(ratioFirstGroup > 0);

                double AreaFirstGroup   = ratioFirstGroup * graphRectangle.Width * graphRectangle.Height;
                double firstGroupWidth  = Math.Sqrt(ratioFirstGroup * graphRectangle.Width * graphRectangle.Height / ARs);
                double firstGroupHeight = Math.Sqrt(ratioFirstGroup * graphRectangle.Width * graphRectangle.Height * ARs);
                double dGroupTop        = (double)graphRectangle.Top;
                double dGroupBottom     = dGroupTop + firstGroupHeight;
                double dGroupLeft       = (double)graphRectangle.Left + ((double)(graphRectangle.Width - firstGroupWidth) / 2.0);
                double dGroupRight      = dGroupLeft + firstGroupWidth;

                // Assign the boundaries to center(first) group's rectangle
                aoGroupRectangles[0] = RectangleF.FromLTRB((float)dGroupLeft,
                                                           (float)dGroupTop, (float)dGroupRight, (float)dGroupBottom);

                // Calculate the free spaces. Constructor follows the Left, Top, Right, Bottom order
                FreeSpaceBox B2 = new FreeSpaceBox(graphRectangle.Left, (float)dGroupTop, (float)dGroupLeft, graphRectangle.Bottom, FreeSpaceBox.Orientation.Vert);
                FreeSpaceBox B3 = new FreeSpaceBox((float)dGroupLeft, (float)dGroupBottom, graphRectangle.Right, graphRectangle.Bottom, FreeSpaceBox.Orientation.Horiz);
                FreeSpaceBox B4 = new FreeSpaceBox((float)dGroupRight, (float)dGroupTop, graphRectangle.Right, (float)dGroupBottom, FreeSpaceBox.Orientation.Vert);

                // Place the boxes in the linked list
                freeSpaceBoxList = new LinkedList <FreeSpaceBox>();
                freeSpaceBoxList.AddFirst(B3);
                freeSpaceBoxList.AddLast(B2);
                freeSpaceBoxList.AddLast(B4);

                done = ArrangeRemainingGroupsInFreeSpaces(graphRectangle, sortedGroups, gamma, iSortedGroupCount, dTotalNumberOfVertices);
                if (!done)
                {
                    gamma = gamma * alpha; // alpha has been set in Layouts->Layouts->LayoutBase.cs
                    Debug.Assert(gamma > 0);
                    for (int j = 0; j < iSortedGroupCount; j++)
                    {
                        aoGroupRectangles[j] = RectangleF.Empty;
                        freeSpaceBoxList     = new LinkedList <FreeSpaceBox>();
                    }
                    goto redoU;
                }
            }
            for (Int32 i = 0; i < iSortedGroupCount; i++)
            {
                sortedGroups[i].Rectangle = GraphicsUtil.RectangleFToRectangle(aoGroupRectangles[i], 1);
            }

            // Calculate the screen space wasted
            double totalFreeAreaLeft           = 0;
            LinkedListNode <FreeSpaceBox> next = freeSpaceBoxList.First;

            while (next != null)
            {
                totalFreeAreaLeft = totalFreeAreaLeft + next.Value.GetArea();
                next = next.Next;
            }
        }
    RecalculateFreeSpace
    (
        LinkedListNode<FreeSpaceBox> freeSpaceBoxNode,
        RectangleF boxPlaced
    )
    {
        FreeSpaceBox freeSpaceBox = freeSpaceBoxNode.Value;

        float top, bottom, right, left;
        if (freeSpaceBox.orientation == FreeSpaceBox.Orientation.Horiz)
        {
            top = freeSpaceBox.boxRectangle.Top;
            left = boxPlaced.Right;
            right = freeSpaceBox.boxRectangle.Right;
            bottom = freeSpaceBox.boxRectangle.Bottom;
        }
        else
        {
            top = boxPlaced.Bottom;
            left = freeSpaceBox.boxRectangle.Left;
            right = freeSpaceBox.boxRectangle.Right;
            bottom = freeSpaceBox.boxRectangle.Bottom;
        }

        FreeSpaceBox newFreeSpaceBox = new FreeSpaceBox(left, top, right, bottom, freeSpaceBox.orientation);
        double newFreeSpaceBoxArea = newFreeSpaceBox.GetArea();

        freeSpaceBoxList.AddLast(newFreeSpaceBox);
        freeSpaceBoxList.Remove(freeSpaceBoxNode);
    }
 PlaceGroupInFreeBox
 (
     GroupInfo groupToBePlaced,
     double groupArea,
     FreeSpaceBox freeBox
 )
 {   double gLeft, gRight, gTop, gBottom, gHeight, gWidth;
     
     if (freeBox.orientation == FreeSpaceBox.Orientation.Vert)
     {
         gLeft = freeBox.boxRectangle.Left;
         gRight = freeBox.boxRectangle.Right;
         gTop = freeBox.boxRectangle.Top;
         gHeight = groupArea / ((double)(gRight - gLeft));
         gBottom = gTop + gHeight;
     }
     else
     {
         gLeft = freeBox.boxRectangle.Left;
         gTop = freeBox.boxRectangle.Top;
         gBottom = freeBox.boxRectangle.Bottom;
         gWidth = groupArea / ((double)Math.Abs(gTop - gBottom));
         gRight = gLeft + gWidth;
     }
     return RectangleF.FromLTRB((float)gLeft, (float)gTop, (float)gRight, (float)gBottom);
 }
    LayoutAllGroupsInDonut
    (
        Rectangle graphRectangle,
        IList<GroupInfo> sortedGroups,
        double alpha,
        double gamma,
        double ARs,
        Int32 iSortedGroupCount,
        Double dTotalNumberOfVertices
    )
    {
        aoGroupRectangles = new RectangleF[iSortedGroupCount]; 
        Boolean done = false;
        while (!done)
        {
        redoDonut:
            // Place the biggest group at the center
            double ratioCenterGroup = gamma * ((double)sortedGroups[0].Vertices.Count / dTotalNumberOfVertices);
            Debug.Assert(ratioCenterGroup > 0);
            double AreaCenterGroup = ratioCenterGroup * graphRectangle.Width * graphRectangle.Height;
            double centerGroupWidth = Math.Sqrt(ratioCenterGroup * graphRectangle.Width * graphRectangle.Height / ARs);
            double centerGroupHeight = Math.Sqrt(ratioCenterGroup * graphRectangle.Width * graphRectangle.Height * ARs);
            double centerX = (graphRectangle.Left + graphRectangle.Right) / 2;
            double centerY = (graphRectangle.Top + graphRectangle.Bottom) / 2;
            Debug.Assert(centerGroupHeight > 0);
            Debug.Assert(centerGroupWidth > 0);

            double dGroupTop = centerY - (centerGroupHeight / 2);
            double dGroupBottom = centerY + (centerGroupHeight / 2);
            double dGroupLeft = centerX - (centerGroupWidth / 2);
            double dGroupRight = centerX + (centerGroupWidth / 2);

            // Assign the boundaries to center group's rectangle
            aoGroupRectangles[0] = RectangleF.FromLTRB((float)dGroupLeft,
            (float)dGroupTop, (float)dGroupRight, (float)dGroupBottom);

            // Calculate the free spaces. Constructor follows the Left, Top, Right, Bottom order
            FreeSpaceBox B1 = new FreeSpaceBox(graphRectangle.Left, graphRectangle.Top, graphRectangle.Right, (float)dGroupTop, FreeSpaceBox.Orientation.Horiz);
            FreeSpaceBox B2 = new FreeSpaceBox(graphRectangle.Left, (float)dGroupTop, (float)dGroupLeft, graphRectangle.Bottom, FreeSpaceBox.Orientation.Vert);
            FreeSpaceBox B3 = new FreeSpaceBox((float)dGroupLeft, (float)dGroupBottom, graphRectangle.Right, graphRectangle.Bottom, FreeSpaceBox.Orientation.Horiz);
            FreeSpaceBox B4 = new FreeSpaceBox((float)dGroupRight, (float)dGroupTop, graphRectangle.Right, (float)dGroupBottom, FreeSpaceBox.Orientation.Vert);

            // Place the boxes in the linked list
            freeSpaceBoxList = new LinkedList<FreeSpaceBox>();
            freeSpaceBoxList.AddFirst(B1);
            freeSpaceBoxList.AddLast(B3);
            freeSpaceBoxList.AddLast(B4);
            freeSpaceBoxList.AddLast(B2);
            
            done = ArrangeRemainingGroupsInFreeSpaces(graphRectangle, sortedGroups, gamma, iSortedGroupCount, dTotalNumberOfVertices);
            if (!done)
            {
                gamma = gamma * alpha; // ETM: alpha has been set in Layouts->Layouts->LayoutBase.cs
                Debug.Assert(gamma > 0);
                for (int j = 0; j < iSortedGroupCount; j++)
                {
                    aoGroupRectangles[j] = RectangleF.Empty;
                    freeSpaceBoxList = new LinkedList<FreeSpaceBox>();
                }
                goto redoDonut;
            }
        }
        for (Int32 i = 0; i < iSortedGroupCount; i++)
        {
            sortedGroups[i].Rectangle = GraphicsUtil.RectangleFToRectangle(aoGroupRectangles[i], 1);
        }
    }
    LayoutAllGroupsInU
    (
        Rectangle graphRectangle,
        IList<GroupInfo> sortedGroups,
        double alpha,
        double gamma,
        double ARs,
        Int32 iSortedGroupCount,
        Double dTotalNumberOfVertices
    )
    {
        aoGroupRectangles = new RectangleF[iSortedGroupCount]; 
        Boolean done = false;
        while (!done)
        {
        redoU:
            // Place the biggest group at the top center
            double ratioFirstGroup = gamma * ((double)sortedGroups[0].Vertices.Count / dTotalNumberOfVertices);

            Debug.Assert(ratioFirstGroup > 0);

            double AreaFirstGroup = ratioFirstGroup * graphRectangle.Width * graphRectangle.Height;
            double firstGroupWidth = Math.Sqrt(ratioFirstGroup * graphRectangle.Width * graphRectangle.Height / ARs);
            double firstGroupHeight = Math.Sqrt(ratioFirstGroup * graphRectangle.Width * graphRectangle.Height * ARs);
            double dGroupTop = (double)graphRectangle.Top;
            double dGroupBottom = dGroupTop + firstGroupHeight;
            double dGroupLeft = (double)graphRectangle.Left + ((double)(graphRectangle.Width - firstGroupWidth) / 2.0);
            double dGroupRight = dGroupLeft + firstGroupWidth;

            // Assign the boundaries to center(first) group's rectangle
            aoGroupRectangles[0] = RectangleF.FromLTRB((float)dGroupLeft,
            (float)dGroupTop, (float)dGroupRight, (float)dGroupBottom);

            // Calculate the free spaces. Constructor follows the Left, Top, Right, Bottom order
            FreeSpaceBox B2 = new FreeSpaceBox(graphRectangle.Left, (float)dGroupTop, (float)dGroupLeft, graphRectangle.Bottom, FreeSpaceBox.Orientation.Vert);
            FreeSpaceBox B3 = new FreeSpaceBox((float)dGroupLeft, (float)dGroupBottom, graphRectangle.Right, graphRectangle.Bottom, FreeSpaceBox.Orientation.Horiz);
            FreeSpaceBox B4 = new FreeSpaceBox((float)dGroupRight, (float)dGroupTop, graphRectangle.Right, (float)dGroupBottom, FreeSpaceBox.Orientation.Vert);

            // Place the boxes in the linked list
            freeSpaceBoxList = new LinkedList<FreeSpaceBox>();
            freeSpaceBoxList.AddFirst(B3);
            freeSpaceBoxList.AddLast(B2);
            freeSpaceBoxList.AddLast(B4);

            done = ArrangeRemainingGroupsInFreeSpaces(graphRectangle, sortedGroups, gamma, iSortedGroupCount, dTotalNumberOfVertices);
            if (!done)
            {
                gamma = gamma * alpha; // alpha has been set in Layouts->Layouts->LayoutBase.cs
                Debug.Assert(gamma > 0);
                for (int j = 0; j < iSortedGroupCount; j++)
                {
                    aoGroupRectangles[j] = RectangleF.Empty;
                    freeSpaceBoxList = new LinkedList<FreeSpaceBox>();
                }
                goto redoU;
            }
        }
        for (Int32 i = 0; i < iSortedGroupCount; i++)
        {
            sortedGroups[i].Rectangle = GraphicsUtil.RectangleFToRectangle(aoGroupRectangles[i], 1);
        }

        // Calculate the screen space wasted
        double totalFreeAreaLeft = 0;
        LinkedListNode<FreeSpaceBox> next = freeSpaceBoxList.First;
        while (next != null)
        {
            totalFreeAreaLeft = totalFreeAreaLeft + next.Value.GetArea();
            next = next.Next;
        }
    }