private bool FindRoot() { HashSet <Representation.node> visitedLeaves = new HashSet <Representation.node>(); Representation.designGraph copiedgraph = graph.copy(); bool istree = true; while (istree == true && copiedgraph.nodes.Count > 1) { istree = false; for (var i = 0; i < copiedgraph.nodes.Count; i++) { if (copiedgraph.nodes[i].arcsFrom.Count == 0) { for (var j = 0; (i < copiedgraph.nodes.Count) && (j < copiedgraph.nodes[i].arcsTo.Count); j++) { string removedname = copiedgraph.nodes[i].arcsTo[j].To.name; copiedgraph.removeNode(copiedgraph.nodes[i].arcsTo[j].To, false); for (var l = 0; l < copiedgraph.arcs.Count; l++) { if (copiedgraph.arcs[l].To != null) { if (copiedgraph.arcs[l].To.name == removedname) { copiedgraph.removeArc(copiedgraph.arcs[l]); } } } istree = true; } break; } } } if (istree == false) { throw new Exception("This graph layout can only be run on trees."); //return false; } var k = 0; for (k = 0; copiedgraph.nodes[0].name != graph.nodes[k].name; k++) { } root = k; return(true); }
protected static void NormalizePositions(Representation.designGraph graph) { if (graph.arcs.Count == 0 || graph.nodes.Count == 0) { return; } //get the topLeft position var topLeft = new Point(float.PositiveInfinity, float.PositiveInfinity); foreach (var n in graph.nodes) { topLeft.X = Math.Min(topLeft.X, n.X); topLeft.Y = Math.Min(topLeft.Y, n.Y); } //translate with the topLeft position foreach (var n in graph.nodes) { n.X -= topLeft.X; n.Y -= topLeft.Y; } }
protected override bool RunLayout() { HashSet <Representation.node> visitedLeaves = new HashSet <Representation.node>(); Representation.designGraph copiedgraph = graph.copy(); bool istree = true; while (istree == true && copiedgraph.nodes.Count > 1) { backgroundWorker.ReportProgress(100 - copiedgraph.nodes.Count); if (backgroundWorker.CancellationPending) { return(false); } istree = false; for (var i = 0; i < copiedgraph.nodes.Count; i++) { if (copiedgraph.nodes[i].arcsFrom.Count == 0) { for (var j = 0; (i < copiedgraph.nodes.Count) && (j < copiedgraph.nodes[i].arcsTo.Count); j++) { string removedname = copiedgraph.nodes[i].arcsTo[j].To.name; copiedgraph.removeNode(copiedgraph.nodes[i], false); for (var l = 0; l < copiedgraph.arcs.Count; l++) { if (copiedgraph.arcs[l].To != null) { if (copiedgraph.arcs[l].To.name == removedname) { copiedgraph.removeArc(copiedgraph.arcs[l]); } } } istree = true; } break; } } } if (istree == false) { backgroundWorker.ReportProgress(100); throw new Exception("The input graph is not a tree. This layout only works on tree structures."); } //return; var k = 0; var x_dist = 0; for (k = 0; k < copiedgraph.nodes.Count; k++) { for (var l = 0; l < graph.nodes.Count; l++) { if (copiedgraph.nodes[k].name == graph.nodes[l].name) { graph.nodes[l].X = x_dist; graph.nodes[l].Y = 0; outputchild(graph.nodes[l], x_dist, 0); x_dist = x_dist + (int)HorizontalSpacing; break; } } } return(true); }