void LayeredLayout(SugiyamaLayoutSettings layeredSettings, GeometryGraph component) { var layeredLayout = new LayeredLayout(component, layeredSettings); layeredLayout.SetCancelToken(this.CancelToken); double aspectRatio = layeredLayout.EstimateAspectRatio(); double edgeDensity = (double)component.Edges.Count / component.Nodes.Count; // if the estimated aspect ratio is not in the range below then we fall back to force directed layout // with constraints which is both faster and usually returns a better aspect ratio for largish graphs var fallbackLayoutSettings = layeredSettings.FallbackLayoutSettings; if (fallbackLayoutSettings != null && (component.Nodes.Count > 50 && edgeDensity > 2 || // too dense component.Nodes.Count > 40 && edgeDensity > 3.0 || // too dense component.Nodes.Count > 30 && edgeDensity > 4.0 || // too dense component.Nodes.Count > 30 && aspectRatio > layeredSettings.MaxAspectRatioEccentricity || // too wide component.Nodes.Count > 30 && aspectRatio < 1d / layeredSettings.MaxAspectRatioEccentricity // too high )) { // for large graphs there's really no point trying to produce nice edge routes // the sugiyama edge routing can be quite circuitous on large graphs anyway var prevEdgeRouting = fallbackLayoutSettings.EdgeRoutingSettings.EdgeRoutingMode; if (component.Nodes.Count > 100 && edgeDensity > 2.0) { fallbackLayoutSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.StraightLine; } LayoutComponent(fallbackLayoutSettings, component); fallbackLayoutSettings.EdgeRoutingSettings.EdgeRoutingMode = prevEdgeRouting; } else { var prevEdgeRouting = layeredSettings.EdgeRoutingSettings.EdgeRoutingMode; // for large graphs there's really no point trying to produce nice edge routes // the sugiyama edge routing can be quite circuitous on large graphs anyway if (component.Nodes.Count > 100 && edgeDensity > 2.0) { layeredSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.StraightLine; } layeredLayout.Run(this.CancelToken); layeredSettings.EdgeRoutingSettings.EdgeRoutingMode = prevEdgeRouting; InitialLayoutHelpers.FixBoundingBox(component, layeredSettings); } //LayoutAlgorithmSettings.ShowGraph(component); }