Example #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));
        }
Example #2
0
        public static XmlDocument ModelToXML(this mxGraph mx_graph)
        {
            var     doc   = new XmlDocument();
            mxCodec codec = new mxCodec();
            XmlNode node  = codec.Encode(mx_graph.Model);


            doc.LoadXml(node.OuterXml);
            return(doc);
        }
Example #3
0
        public void MXGraphTest()
        {
            log.logStartPhase("MXGraph", "Texting Draw.io create/load/save");

            folderNode rootNode = new folderNode();

            rootNode.AttachSubfolders();

            var dgml = new DirectedGraph();

            dgml.Populate <folderNode>(rootNode, x => x,
                                       x => x.path,
                                       x => x.caption,
                                       true,
                                       false);

            mxGraph mxg = directedGraphToMXGraph.ConvertToMXGraph(dgml);

            String drawio_path = folderResults.pathFor("MXGraphTest.drawio", imbSCI.Data.enums.getWritableFileMode.overwrite, "Resaving loaded DMGL object");

            String drawio_jpg = folderResults.pathFor("MXGraphTest.jpg", imbSCI.Data.enums.getWritableFileMode.overwrite, "Resaving loaded DMGL object");


            Image img = mxCellRenderer.CreateImage(mxg, mxg.GetChildCells(mxg, false, false), 1.0, Color.LightGray, true, new mxRectangle(0, 0, 1000, 500));

            img.Save(drawio_jpg, ImageFormat.Jpeg);

            var     doc   = new XmlDocument();
            mxCodec codec = new mxCodec();
            XmlNode node  = codec.Encode(mxg.Model);


            doc.LoadXml(node.OuterXml);
            doc.Save(drawio_path);


            log.logEndPhase();
        }
Example #4
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);
        }
Example #5
0
        public static void LoadModelFromXml(this mxGraph mx_graph, XmlDocument xml)
        {
            mxCodec codec = new mxCodec(xml);

            codec.Decode(xml.DocumentElement, mx_graph.Model);
        }