public void ApplyLayout(LayoutGraph graph) { var rows = graph.GetNodeArray(); // sort the rows by their vertical coordinate Array.Sort(rows, (node1, node2) => (int)(graph.GetCenterY(node1) - graph.GetCenterY(node2))); // layout the nodes in a column double currentY = 0; foreach (var node in rows) { graph.SetLocation(node, 0, currentY); currentY += graph.GetHeight(node) + Distance; } // there should be no edges between the 'row' nodes but if there are some, all their bends shall be removed foreach (var edge in graph.Edges) { graph.SetPoints(edge, new YList()); } }
public override void ApplyLayout(LayoutGraph graph) { ApplyLayoutCore(graph); foreach (Node n in graph.Nodes) { foreach (Edge e in n.OutEdges) { bool lastSegmentOverlap = false; IEdgeLayout er = graph.GetLayout(e); if (er.PointCount() > 0) { // last bend point YPoint bendPoint = er.GetPoint(er.PointCount() - 1); IEnumerator <Edge> ecc = n.OutEdges.GetEnumerator(); loop : while (ecc.MoveNext()) { Edge eccEdge = ecc.Current; if (eccEdge != e) { YPointPath path = graph.GetPath(eccEdge); for (ILineSegmentCursor lc = path.LineSegments(); lc.Ok; lc.Next()) { LineSegment seg = lc.LineSegment; if (seg.Contains(bendPoint)) { lastSegmentOverlap = true; goto loop; } } } } } YList points = graph.GetPointList(e); for (ListCell c = points.FirstCell; c != null; c = c.Succ()) { YPoint p = (YPoint)c.Info; if (c.Succ() == null && !lastSegmentOverlap) { break; } YPoint p0 = (YPoint)(c.Pred() == null ? graph.GetSourcePointAbs(e) : c.Pred().Info); YPoint p2; if (Math.Abs(p0.X - p.X) < 0.01) { p2 = new YPoint(p.X, p.Y - 0.001); } else { p2 = new YPoint(p.X - 0.001, p.Y); } points.InsertBefore(p2, c); } graph.SetPoints(e, points); } } }