예제 #1
0
        void CalculateLabelsX()
        {
            int          i;
            ISolverShell solver = ConstrainedOrdering.CreateSolver();

            for (i = 0; i < pairArray.Length; i++)
            {
                solver.AddVariableWithIdealPosition(i, labelCenters[i], GetLabelWeight(pairArray[i]));
            }

            //add non overlapping constraints between to neighbor labels
            double prevLabelWidth = GetMaxLabelWidth(pairArray[0]);

            for (i = 0; i < pairArray.Length - 1; i++)
            {
                solver.AddLeftRightSeparationConstraint(i, i + 1,
                                                        (prevLabelWidth +
                                                         (prevLabelWidth = GetMaxLabelWidth(pairArray[i + 1]))) / 2 +
                                                        settings.NodeSeparation);
            }

            for (i = 0; i < labelCenters.Length; i++)
            {
                double x = labelCenters[i] = solver.GetVariableResolvedPosition(i);
                foreach (Label label in PairLabels(pairArray[i]))
                {
                    label.Center = new Point(x, label.Center.Y);
                }
            }
        }
        bool CanSwap(int i, int j)
        {
            if (IsVirtualNode(i) || IsVirtualNode(j))
            {
                return(true);
            }
            LayerInfo layerInfo = layerInfos[layering[i]];

            if (layerInfo == null)
            {
                return(true);
            }
            if (ConstrainedOrdering.BelongsToNeighbBlock(i, layerInfo)
                ||
                ConstrainedOrdering.BelongsToNeighbBlock(j, layerInfo)
                ||
                layerInfo.constrainedFromAbove.ContainsKey(i)
                ||
                layerInfo.constrainedFromBelow.ContainsKey(j)
                )
            {
                return(false);
            }

            if (layerInfo.leftRight.Contains(new Tuple <int, int>(i, j)))
            {
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// it is a special recovery constructor to recreate the engine from the recovery engine
 /// </summary>
 internal LayeredLayoutEngine(LayerArrays engineLayerArrays, GeometryGraph originalGraph, ProperLayeredGraph properLayeredGraph, SugiyamaLayoutSettings sugiyamaSettings, Database database, BasicGraph<Node, IntEdge> intGraph, Dictionary<Node, int> nodeIdToIndex, BasicGraph<Node, IntEdge> gluedDagSkeletonForLayering, bool layersAreDoubled, ConstrainedOrdering constrainedOrdering, bool brandes, XLayoutGraph xLayoutGraph) {
     this.engineLayerArrays = engineLayerArrays;
     this.originalGraph = originalGraph;
     this.properLayeredGraph = properLayeredGraph;
     this.sugiyamaSettings = sugiyamaSettings;
     this.database = database;
     IntGraph = intGraph;
     this.nodeIdToIndex = nodeIdToIndex;
     GluedDagSkeletonForLayering = gluedDagSkeletonForLayering;
     LayersAreDoubled = layersAreDoubled;
     this.constrainedOrdering = constrainedOrdering;
     Brandes = brandes;
     anchors = database.anchors;
     this.xLayoutGraph = xLayoutGraph;
 }
        LayerArrays YLayeringAndOrdering(LayerCalculator layering) {
            #region reporting

#if REPORTING
            Timer t = null;
            if (sugiyamaSettings.Reporting) {
                t = new Timer();
                Report("ylayering ... ");
                t.Start();
            }
#endif

            #endregion

            int[] yLayers = layering.GetLayers();
            Balancing.Balance(GluedDagSkeletonForLayering, yLayers, GetNodeCountsOfGluedDag(), null);
            yLayers = ExtendLayeringToUngluedSameLayerVertices(yLayers);

            #region reporting

#if REPORTING
            if (sugiyamaSettings.Reporting) {
                t.Stop();
                Report(String.Format(CultureInfo.CurrentCulture, "{0}\n", t.Duration));
                Report("ordering ... ");
                t.Start();
            }
#endif

            #endregion

            var layerArrays = new LayerArrays(yLayers);
            //if (!SugiyamaSettings.UseEdgeBundling && (HorizontalConstraints == null || HorizontalConstraints.IsEmpty)) {
            if (HorizontalConstraints == null || HorizontalConstraints.IsEmpty) {
                layerArrays = YLayeringAndOrderingWithoutHorizontalConstraints(layerArrays);

                #region reporting

#if REPORTING
                if (sugiyamaSettings.Reporting) {
                    t.Stop();
                    Report(String.Format(CultureInfo.CurrentCulture, "{0}\n", t.Duration));
                }
#endif

                #endregion

                return layerArrays;
            }
            constrainedOrdering = new ConstrainedOrdering(originalGraph, IntGraph, layerArrays.Y, nodeIdToIndex,
                                                          database, sugiyamaSettings);
            constrainedOrdering.Calculate();
            properLayeredGraph = constrainedOrdering.ProperLayeredGraph;

            #region reporting

#if REPORTING
            if (sugiyamaSettings.Reporting) {
                t.Stop();
                Report(String.Format(CultureInfo.CurrentCulture, "{0}\n", t.Duration));
            }
#endif

            #endregion

            // SugiyamaLayoutSettings.ShowDatabase(this.database);
            return constrainedOrdering.LayerArrays;
        }
        LayerArrays YLayeringAndOrdering(LayerCalculator layering) {

            int[] yLayers = layering.GetLayers();
            yLayers = ExtendLayeringToUngluedSameLayerVertices(yLayers);
            var layerArrays = new LayerArrays(yLayers);
            //if (!SugiyamaSettings.UseEdgeBundling && (HorizontalConstraints == null || HorizontalConstraints.IsEmpty)) {
            if (HorizontalConstraints == null || HorizontalConstraints.IsEmpty) {
                layerArrays = YLayeringAndOrderingWithoutHorizontalConstraints(layerArrays);
                return layerArrays;
            }
            constrainedOrdering = new ConstrainedOrdering(originalGraph, IntGraph, layerArrays.Y, nodeIdToIndex,
                                                          database, sugiyamaSettings);
            constrainedOrdering.Calculate();
            properLayeredGraph = constrainedOrdering.ProperLayeredGraph;


            // SugiyamaLayoutSettings.ShowDatabase(this.database);
            return constrainedOrdering.LayerArrays;
        }