/// <summary> /// Creates a forest of unbalanced trees and applies a radial layout. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> private void RandomRadialForest(RadDiagram diagram, GraphGenerationSpecifications specs) { this.diagram.Clear(); Dictionary <Node, RadDiagramShape> nodeMap; Dictionary <Edge, RadDiagramConnection> edgeMap; var g = this.diagram.CreateDiagram(GraphExtensions.CreateRandomGraph(250, 4, true), out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value); var settings = new TreeLayoutSettings { TreeLayoutType = TreeLayoutType.RadialTree, HorizontalSeparation = this.HorizontalSeparationSlider.Value, VerticalSeparation = this.VerticalSeparationSlider.Value, UnderneathHorizontalOffset = this.UnderneathHorizontalOffsetSlider.Value, UnderneathVerticalSeparation = this.UnderneathVerticalOffsetSlider.Value, KeepComponentsInOneRadialLayout = true, RadialSeparation = 45d }; var center = g.FindNode(0); settings.Roots.Add(nodeMap[center]); var layout = new TreeLayout(); layout.Layout(this.diagram, settings); this.diagram.AutoFit(); //Colorize(g, nodeMap, center); }
/// <summary> /// Creates a tree which grows symmetrically. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> private void BalancedRadialTree(RadDiagram diagram, GraphGenerationSpecifications specs) { this.diagram.Clear(); Dictionary <Node, RadDiagramShape> nodeMap; Dictionary <Edge, RadDiagramConnection> edgeMap; // the algorithm to create a balanced tree is quite straighforward var g = this.diagram.CreateDiagram(GraphExtensions.CreateBalancedTree(), out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value); // the result is best displayed with the radial tree layout var settings = new TreeLayoutSettings { TreeLayoutType = TreeLayoutType.RadialTree, HorizontalSeparation = this.HorizontalSeparationSlider.Value, VerticalSeparation = this.VerticalSeparationSlider.Value, UnderneathHorizontalOffset = this.UnderneathHorizontalOffsetSlider.Value, UnderneathVerticalSeparation = this.UnderneathVerticalOffsetSlider.Value, StartRadialAngle = Math.PI, // use a specific angle rather than the full 360° to show one of the layout's (hidden) gem EndRadialAngle = 3.47 * Math.PI / 2 }; var center = g.FindNode(-1); settings.Roots.Add(nodeMap[center]); var layout = new TreeLayout(); layout.Layout(this.diagram, settings); // center and size autimagically this.diagram.AutoFit(); // you can colorize the shapes, if you wish // this.Colorize(g, nodeMap, center); }
private void Show() { int treeIndex = 0; double prevMaxY = 0; foreach (var tree in _trees) { var visNodeTable = _visNodeTables[treeIndex]; //Layout var layout = new TreeLayout(tree, visNodeTable) { NodeMarginHorizontal = 60, NodeMarginVertical = 150 }; layout.Layout(); foreach (var visItem in visNodeTable.Items) { visItem.X += 10; visItem.Y += 50 + prevMaxY; } prevMaxY = visNodeTable.Items.Max(item => item.Y); foreach (var visItem in visNodeTable.Items) { IVisualItem visParentItem; var visEdge = GetEdgeVisItem(visItem, out visParentItem); if (visEdge != null) { visEdge.X1 = visItem.X; visEdge.Y1 = visItem.Y; visEdge.X2 = visParentItem.X; visEdge.Y2 = visParentItem.Y; } } treeIndex++; } //Interactions InitInteractions(); //Show _app = new Application(); _app.Run(_window); //_window.Show(); Console.ReadKey(); }
/// <summary> /// Handles the OnClick event of the TreeLayoutButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param> private void TreeLayoutButton_OnClick(object sender, RoutedEventArgs e) { var settings = new TreeLayoutSettings { TreeLayoutType = this.GetTreeLayoutType(), HorizontalSeparation = this.HorizontalSeparationSlider.Value, VerticalSeparation = this.VerticalSeparationSlider.Value, UnderneathHorizontalOffset = this.UnderneathHorizontalOffsetSlider.Value, UnderneathVerticalSeparation = this.UnderneathVerticalOffsetSlider.Value, KeepComponentsInOneRadialLayout = true, RadialSeparation = this.RadialSeparationSlider.Value, RadialFirstLEvelSeparation = this.RadialFirstLevelSeparationSlider.Value }; var layout = new TreeLayout(); settings.Roots.Add(this.diagram.Items[1] as IShape); layout.Layout(this.diagram, settings); this.diagram.AutoFit(); }
/// <summary> /// Creates a balanced radial forest. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> public static void BalancedRadialForest(this RadDiagram diagram, GraphGenerationSpecifications specs) { diagram.Clear(); Dictionary<Node, RadDiagramShape> nodeMap; Dictionary<Edge, RadDiagramConnection> edgeMap; var g = diagram.CreateDiagram(CreateBalancedForest(), out nodeMap, out edgeMap, CreateShape, specs.RandomShapeSize); var settings = new TreeLayoutSettings { TreeLayoutType = specs.TreeType, HorizontalSeparation = specs.HorizontalSeparation, VerticalSeparation = specs.VerticalSeparation, UnderneathHorizontalOffset = specs.UnderneathHorizontalOffset, UnderneathVerticalSeparation = specs.UnderneathVerticalSeparation, KeepComponentsInOneRadialLayout = specs.KeepComponentsInOneRadialLayout }; var center = g.FindNode(1); settings.Roots.Add(nodeMap[center]); var layout = new TreeLayout(); layout.Layout(diagram, settings); diagram.AutoFit(); }
/// <summary> /// Creates a balanced radial forest. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> public static void BalancedRadialForest(this RadDiagram diagram, GraphGenerationSpecifications specs) { diagram.Clear(); Dictionary <Node, RadDiagramShape> nodeMap; Dictionary <Edge, RadDiagramConnection> edgeMap; var g = diagram.CreateDiagram(CreateBalancedForest(), out nodeMap, out edgeMap, CreateShape, specs.RandomShapeSize); var settings = new TreeLayoutSettings { TreeLayoutType = specs.TreeType, HorizontalSeparation = specs.HorizontalSeparation, VerticalSeparation = specs.VerticalSeparation, UnderneathHorizontalOffset = specs.UnderneathHorizontalOffset, UnderneathVerticalSeparation = specs.UnderneathVerticalSeparation, KeepComponentsInOneRadialLayout = specs.KeepComponentsInOneRadialLayout }; var center = g.FindNode(1); settings.Roots.Add(nodeMap[center]); var layout = new TreeLayout(); layout.Layout(diagram, settings); diagram.AutoFit(); }
/// <summary> /// Creates a forest of unbalanced trees and applies a radial layout. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> private void RandomRadialForest(RadDiagram diagram, GraphGenerationSpecifications specs) { this.diagram.Clear(); Dictionary<Node, RadDiagramShape> nodeMap; Dictionary<Edge, RadDiagramConnection> edgeMap; var g = this.diagram.CreateDiagram(GraphExtensions.CreateRandomGraph(250, 4, true), out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value); var settings = new TreeLayoutSettings { TreeLayoutType = TreeLayoutType.RadialTree, HorizontalSeparation = this.HorizontalSeparationSlider.Value, VerticalSeparation = this.VerticalSeparationSlider.Value, UnderneathHorizontalOffset = this.UnderneathHorizontalOffsetSlider.Value, UnderneathVerticalSeparation = this.UnderneathVerticalOffsetSlider.Value, KeepComponentsInOneRadialLayout = true, RadialSeparation = 45d }; var center = g.FindNode(0); settings.Roots.Add(nodeMap[center]); var layout = new TreeLayout(); layout.Layout(this.diagram, settings); this.diagram.AutoFit(); //Colorize(g, nodeMap, center); }
/// <summary> /// Creates a tree which grows symmetrically. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> private void BalancedRadialTree(RadDiagram diagram, GraphGenerationSpecifications specs) { this.diagram.Clear(); Dictionary<Node, RadDiagramShape> nodeMap; Dictionary<Edge, RadDiagramConnection> edgeMap; // the algorithm to create a balanced tree is quite straighforward var g = this.diagram.CreateDiagram(GraphExtensions.CreateBalancedTree(), out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value); // the result is best displayed with the radial tree layout var settings = new TreeLayoutSettings { TreeLayoutType = TreeLayoutType.RadialTree, HorizontalSeparation = this.HorizontalSeparationSlider.Value, VerticalSeparation = this.VerticalSeparationSlider.Value, UnderneathHorizontalOffset = this.UnderneathHorizontalOffsetSlider.Value, UnderneathVerticalSeparation = this.UnderneathVerticalOffsetSlider.Value, StartRadialAngle = Math.PI, // use a specific angle rather than the full 360° to show one of the layout's (hidden) gem EndRadialAngle = 3.47 * Math.PI / 2 }; var center = g.FindNode(-1); settings.Roots.Add(nodeMap[center]); var layout = new TreeLayout(); layout.Layout(this.diagram, settings); // center and size autimagically this.diagram.AutoFit(); // you can colorize the shapes, if you wish // this.Colorize(g, nodeMap, center); }