public LayoutForm() { mxGraph graph = new mxGraph(); Object parent = graph.GetDefaultParent(); graph.Model.BeginUpdate(); try { int nodeCount = 100; int edgeCount = 100; Object[] nodes = new Object[nodeCount]; for (int i = 0; i < nodeCount; i++) { nodes[i] = graph.InsertVertex(parent, null, 'N' + i, 0, 0, 30, 30); } Random r = new Random(); for (int i = 0; i < edgeCount; i++) { int r1 = (int)(r.NextDouble() * nodeCount); int r2 = (int)(r.NextDouble() * nodeCount); graph.InsertEdge(parent, null, r1 + '-' + r2, nodes[r1], nodes[r2]); } mxIGraphLayout layout = new mxFastOrganicLayout(graph); layout.execute(parent); } finally { graph.Model.EndUpdate(); } graph.View.Scale = 0.2; graphControl = new GraphControl(graph); graphControl.Dock = DockStyle.Fill; Controls.Add(graphControl); Size = new Size(320, 200); }
public GraphForm() { // Registers custom shapes XmlDocument doc = mxUtils.ParseXml(mxUtils.ReadFile("../../../../java/examples/com/mxgraph/examples/swing/shapes.xml")); XmlNodeList list = doc.DocumentElement.GetElementsByTagName("shape"); for (int i = 0; i < list.Count; i++) { XmlElement shape = (XmlElement)list.Item(i); mxStencilRegistry.AddStencil(shape.GetAttribute("name"), new mxStencil(shape)); } // Creates graph with model mxGraph graph = new mxGraph(); Object parent = graph.GetDefaultParent(); // Adds cells into the graph graph.Model.BeginUpdate(); try { Object v1 = graph.InsertVertex(parent, null, "Hello", 20, 20, 80, 30, "shape=and;fillColor=#ff0000;gradientColor=#ffffff;shadow=1"); Object v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30, "shape=or;shadow=1"); Object e1 = graph.InsertEdge(parent, null, "e1", v1, v2); } finally { graph.Model.EndUpdate(); } // Creates a component for the graph graphControl = new GraphControl(graph); graphControl.Dock = DockStyle.Fill; Controls.Add(graphControl); Size = new Size(320, 200); }