/// <summary>
        /// Does the initial scaling of the layout, could also be avoided.
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="nodePositions"></param>
        /// <param name="nodeSizes"></param>
        /// <param name="scalingMethod"></param>
        static void DoInitialScaling(Node[] nodes, Point[] nodePositions, Size[] nodeSizes,
                                     InitialScaling scalingMethod)
        {
            var    avgEdgeLength = AvgEdgeLength(nodes);
            double goalLength;

            if (scalingMethod == InitialScaling.Inch72Pixel)
            {
                goalLength = 72;
            }
            else if (scalingMethod == InitialScaling.AvgNodeSize)
            {
                goalLength = nodeSizes.Average(box => (box.Width + box.Height) / 2);
            }
            else
            {
                return;
            }

            double scaling = goalLength / avgEdgeLength;

#if DEBUG
            Console.WriteLine("AvgEdgeLength Scaling Method: {0}, ScaleFactor={1:F2}", scalingMethod, scaling);
#endif
            for (int j = 0; j < nodePositions.Length; j++)
            {
                nodePositions[j] *= scaling;
            }
        }
示例#2
0
        static void DoInitialScaling(GeometryGraph Graph, InitialScaling initScaling)
        {
            if (Graph.Edges.Count == 0)
            {
                return;
            }
            var nodePositions = Graph.Nodes.Select(v => v.Center).ToArray();
            var nodeBoxes     = Graph.Nodes.Select(v => v.BoundingBox).ToArray();

            var avgEdgeLength = AvgEdgeLength(Graph);

            double goalLength;

            if (initScaling == InitialScaling.Inch72Pixel)
            {
                goalLength = 72;
            }
            else if (initScaling == InitialScaling.AvgNodeSize)
            {
                goalLength = nodeBoxes.Average(box => (box.Width + box.Height) / 2);
            }
            else
            {
                return;
            }

            double scaling = goalLength / avgEdgeLength;


            for (int j = 0; j < nodePositions.Length; j++)
            {
                nodePositions[j] *= scaling;
                Rectangle rect = nodeBoxes[j];
                rect.Center           = nodePositions[j];
                nodeBoxes[j]          = rect;
                Graph.Nodes[j].Center = nodePositions[j];
            }
        }
        /// <summary>
        /// Does the initial scaling of the layout, could also be avoided.
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="nodePositions"></param>
        /// <param name="nodeSizes"></param>
        /// <param name="scalingMethod"></param>
        static void DoInitialScaling(Node[] nodes, Point[] nodePositions, Size[] nodeSizes,
            InitialScaling scalingMethod) {

            var avgEdgeLength = AvgEdgeLength(nodes);
            double goalLength;
            if (scalingMethod == InitialScaling.Inch72Pixel)
                goalLength = 72;
            else if (scalingMethod == InitialScaling.AvgNodeSize)
                goalLength = nodeSizes.Average(box => (box.Width + box.Height)/2);
            else return;

            double scaling = goalLength/avgEdgeLength;
#if DEBUG
            Console.WriteLine("AvgEdgeLength Scaling Method: {0}, ScaleFactor={1:F2}", scalingMethod, scaling);
#endif
            for (int j = 0; j < nodePositions.Length; j++) {
                nodePositions[j] *= scaling;
            }
        }