public void CalculateIterationsForGraphSize() { const int LowerThreshold = 10; const int UpperThreshold = 50; const int MinIterations = 10; const int MaxIterations = 30; Assert.AreEqual( LayoutAlgorithmHelpers.NegativeLinearInterpolation(UpperThreshold + 1, LowerThreshold, UpperThreshold, MinIterations, MaxIterations), MinIterations, "When nodeCount > upperThreshold number of iterations should be minIterations"); Assert.AreEqual( LayoutAlgorithmHelpers.NegativeLinearInterpolation(UpperThreshold, LowerThreshold, UpperThreshold, MinIterations, MaxIterations), MinIterations, "When nodeCount == upperThreshold number of iterations should be minIterations"); Assert.AreEqual( LayoutAlgorithmHelpers.NegativeLinearInterpolation(LowerThreshold - 1, LowerThreshold, UpperThreshold, MinIterations, MaxIterations), MaxIterations, "When nodeCount < lowerThreshold number of iterations should be maxIterations"); Assert.AreEqual( LayoutAlgorithmHelpers.NegativeLinearInterpolation(LowerThreshold, LowerThreshold, UpperThreshold, MinIterations, MaxIterations), MaxIterations, "When nodeCount == lowerThreshold number of iterations should be maxIterations"); Assert.AreEqual( LayoutAlgorithmHelpers.NegativeLinearInterpolation((UpperThreshold + LowerThreshold) / 2, LowerThreshold, UpperThreshold, MinIterations, MaxIterations), (MinIterations + MaxIterations) / 2, "When nodeCount is mid-way between lowerThreshold and upperThreshold number of iterations should be mid-way between minIterations and maxIterations"); }
internal void LayoutComponent(GeometryGraph component, FastIncrementalLayoutSettings settings) { // for small graphs (below 100 nodes) do extra iterations settings.MaxIterations = LayoutAlgorithmHelpers.NegativeLinearInterpolation( component.Nodes.Count, /*lowerThreshold:*/ 50, /*upperThreshold:*/ 500, /*minIterations:*/ 3, /*maxIterations:*/ 5); settings.MinorIterations = LayoutAlgorithmHelpers.NegativeLinearInterpolation(component.Nodes.Count, /*lowerThreshold:*/ 50, /*upperThreshold:*/ 500, /*minIterations:*/ 2, /*maxIterations:*/ 10); FastIncrementalLayout fil = new FastIncrementalLayout(component, settings, settings.MinConstraintLevel, anyCluster => settings); Debug.Assert(settings.Iterations == 0); foreach (var level in Enumerable.Range(settings.MinConstraintLevel, settings.MaxConstraintLevel + 1)) { if (level != fil.CurrentConstraintLevel) { fil.CurrentConstraintLevel = level; if (level == 2) { settings.MinorIterations = 1; settings.ApplyForces = false; } } do { fil.Run(); } while (!settings.IsDone); } // Pad the graph with margins so the packing will be spaced out. component.Margins = settings.ClusterMargin; component.UpdateBoundingBox(); }
private void LayoutComponent(GeometryGraph component) { if (component.Nodes.Count > 1 || component.RootCluster.Clusters.Any()) { // for small graphs (below 100 nodes) do extra iterations settings.MaxIterations = LayoutAlgorithmHelpers.NegativeLinearInterpolation( component.Nodes.Count, /*lowerThreshold:*/ 50, /*upperThreshold:*/ 500, /*minIterations:*/ 5, /*maxIterations:*/ 10); settings.MinorIterations = LayoutAlgorithmHelpers.NegativeLinearInterpolation(component.Nodes.Count, /*lowerThreshold:*/ 50, /*upperThreshold:*/ 500, /*minIterations:*/ 3, /*maxIterations:*/ 20); if (settings.MinConstraintLevel == 0) { // run PivotMDS with a largish Scale so that the layout comes back oversized. // subsequent incremental iterations do a better job of untangling when they're pulling it in // rather than pushing it apart. PivotMDS pivotMDS = new PivotMDS(component) { Scale = 2 }; this.RunChildAlgorithm(pivotMDS, 0.5 / componentCount); } FastIncrementalLayout fil = new FastIncrementalLayout(component, settings, settings.MinConstraintLevel, anyCluster => settings); Debug.Assert(settings.Iterations == 0); foreach (var level in GetConstraintLevels(component)) { if (level > settings.MaxConstraintLevel) { break; } if (level > settings.MinConstraintLevel) { fil.CurrentConstraintLevel = level; } do { fil.Run(); } while (!settings.IsDone); } } // Pad the graph with margins so the packing will be spaced out. component.Margins = settings.NodeSeparation; component.UpdateBoundingBox(); // Zero the graph component.Translate(-component.BoundingBox.LeftBottom); }