Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Creates an instance of a graph to add vertices and edges. The instance can
            // then be used to create the corresponding XML using a codec. Note that this
            // is only required if a graph is programmatically created. If the XML for the
            // graph is already at hand, it can be sent directly here.
            mxGraph graph  = new mxGraph();
            Object  parent = graph.GetDefaultParent();

            // Adds vertices and edges to the graph.
            graph.Model.BeginUpdate();
            try
            {
                Object v1 = graph.InsertVertex(parent, null, "Hello,", 20, 20, 80, 30);
                Object v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30);
                Object e1 = graph.InsertEdge(parent, null, "Edge", v1, v2);
            }
            finally
            {
                graph.Model.EndUpdate();
            }

            // Encodes the model into XML and passes the resulting XML string into a page
            // variable, so it can be read when the page is rendered on the server. Note
            // that the page instance is destroyed after the page was sent to the client.
            mxCodec codec = new mxCodec();

            Xml = mxUtils.GetXml(codec.Encode(graph.Model));
        }
Ejemplo n.º 2
0
        static void example1()
        {
            // 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);
                Object v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30);
                Object e1 = graph.InsertEdge(parent, null, "e1", v1, v2);
            }
            finally
            {
                graph.Model.EndUpdate();
            }

            // Example to save the graph in multiple images
            //Image img = mxCellRenderer.CreateImage(graph, null, 1, Color.White, true, new mxRectangle(0, 0, 150, 200));
            //img.Save("example1.png", ImageFormat.Png);

            //Image img2 = mxCellRenderer.CreateImage(graph, null, 1, (Color?)BackColor, true, new mxRectangle(150, 0, 150, 200));
            //img2.Save("example2.png", ImageFormat.Png);
        }
        /// <summary>
        /// Converts a <see cref="DirectedGraph"/> graph object into <see cref="mxGraph"/>
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public static mxGraph ConvertToMXGraph(this DirectedGraph input)
        {
            // Creates graph with model
            mxGraph graph = new mxGraph();

            mxFastOrganicLayout layout = new mxFastOrganicLayout(graph);

            Object parent = graph.GetDefaultParent();

            graph.Model.BeginUpdate();

            Dictionary <String, mxCell> nodeId = new Dictionary <string, mxCell>();

            foreach (DGML.core.Node node in input.Nodes)
            {
                if (!nodeId.ContainsKey(node.Id))
                {
                    nodeId.Add(node.Id, (mxCell)graph.InsertVertex(parent, node.Id, node.Label, 0, 0, 200, 35, node.Category));
                }
            }

            foreach (DGML.core.Link link in input.Links)
            {
                if (!nodeId.ContainsKey(link.Source))
                {
                    continue;
                }
                if (!nodeId.ContainsKey(link.Target))
                {
                    continue;
                }

                var source = nodeId[link.Source];
                var target = nodeId[link.Target];

                if ((source != null) && (target != null))
                {
                    graph.InsertEdge(parent, link.Id, link.Label, source, target);
                }
            }

            layout.execute(parent);

            return(graph);

            //    layout.execute(
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
Archivo: Form.cs Proyecto: BOURAGBA/PFE
        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);
        }
Ejemplo n.º 6
0
        public static void Main()
        {
            // Creates graph with model
            mxGraph graph = new mxGraph();

            // Adds cells into the model
            Object parent = graph.GetDefaultParent();

            graph.Model.BeginUpdate();
            Object v1, v2, e1;

            try
            {
                v1 = graph.InsertVertex(parent, null, "Hello", 20, 20, 80, 30);
                v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30);
                e1 = graph.InsertEdge(parent, null, "e1", v1, v2);
            }
            finally
            {
                graph.Model.EndUpdate();
            }

            mxCodec codec = new mxCodec();
            XmlNode node  = codec.Encode(graph.Model);
            string  xml1  = mxUtils.GetPrettyXml(node);

            codec = new mxCodec();
            Object model = codec.Decode(node);

            codec = new mxCodec();
            node  = codec.Encode(model);
            string xml2 = mxUtils.GetPrettyXml(node);

            Console.WriteLine("mxCodecTest Passed: " + (xml1.Equals(xml2)));
            Thread.Sleep(100000);
        }