// optimize the creation of the ForceDirectedNetwork: // only create it when there are Nodes or Links added or removed protected override void PerformLayout() { Diagram diagram = this.Diagram; if (diagram == null) { return; } var cfdlayout = diagram.Layout as ContinuousForceDirectedLayout; if (cfdlayout != null) { // assume there are no Groups with their own Layout if (!cfdlayout.ValidLayout) { // make sure there's no animation interfering with ContinuousForceDirectedLayout this.Animated = false; // don't set Wait cursor during drag diagram.Cursor = null; // the ForceDirectedNetwork needs to be cleared whenever a Node or Link is added or removed var net = cfdlayout.Network; if (net == null) // create a new one { net = new ForceDirectedNetwork(); net.AddNodesAndLinks(diagram.Nodes.Where(n => CanLayoutPart(n, cfdlayout)), diagram.Links.Where(l => CanLayoutPart(l, cfdlayout))); cfdlayout.Network = net; } else // update all vertex.Bounds { foreach (ForceDirectedVertex v in net.Vertexes) { Node n = v.Node; if (n != null) { v.Bounds = n.Bounds; } } } // don't need to re-collect the appropriate Nodes and Links to pass to DoLayout this.IsLayingOut = true; cfdlayout.DoLayout(null, null); this.IsLayingOut = false; cfdlayout.ValidLayout = true; // DoLayout normally discards the Network; keep it for next time cfdlayout.Network = net; } } else { base.PerformLayout(); } }
public override ForceDirectedNetwork MakeNetwork(IEnumerable <Node> nodes, IEnumerable <Link> links) { ForceDirectedNetwork net = base.MakeNetwork(nodes, links); foreach (ForceDirectedVertex v in net.Vertexes) { Node node = v.Node; if (node != null) { v.IsFixed = node.IsSelected; } } return(net); }