コード例 #1
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);
        }
コード例 #2
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));
        }
コード例 #3
0
ファイル: Form.cs プロジェクト: BOURAGBA/PFE
 public GraphControl(mxGraph graph)
 {
     this.graph      = graph;
     this.AutoScroll = true;
     this.Paint     += new PaintEventHandler(PaintBuffer);
     this.graph.Model.GraphModelChange += new mxGraphModelChangeEventHandler(RefreshBuffer);
 }
コード例 #4
0
        /// <summary>
        /// Creates an image for the given arguments.
        /// </summary>
        public static Image CreateImage(mxGraph graph, Object[] cells, double scale, Color?background,
                                        bool antiAlias, mxRectangle clip, mxGdiCanvas graphicsCanvas)
        {
            mxImageCanvas canvas = (mxImageCanvas)DrawCells(graph, cells, scale, clip,
                                                            new ImageCanvasFactory(graphicsCanvas, background, antiAlias));

            return(canvas.Destroy());
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <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(
        }
コード例 #7
0
ファイル: Layout.cs プロジェクト: zswang/mxgraph
        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);
        }
コード例 #8
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();
        }
コード例 #9
0
ファイル: Form.cs プロジェクト: 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);
        }
コード例 #10
0
ファイル: mxCodecTest.cs プロジェクト: sinrusia/Hello-sky
        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);
        }
コード例 #11
0
ファイル: mxFastOrganicLayout.cs プロジェクト: zswang/mxgraph
 /// <summary>
 /// Constructs a new fast organic layout for the specified graph.
 /// </summary>
 /// <param name="graph"></param>
 public mxFastOrganicLayout(mxGraph graph)
 {
     this.graph = graph;
 }
コード例 #12
0
ファイル: mxGraphView.cs プロジェクト: mbao01/mxgraph-clean
 /// <summary>
 /// Constructs a new view for the given graph.
 /// </summary>
 /// <param name="graph">Reference to the enclosing graph.</param>
 public mxGraphView(mxGraph graph)
 {
     this.graph = graph;
 }
コード例 #13
0
        /// <summary>
        /// Draws the given cells using a Graphics2D canvas and returns the buffered image
        /// that represents the cells.
        /// </summary>
        public static mxICanvas DrawCells(mxGraph graph, Object[] cells, double scale,
                                          mxRectangle clip, CanvasFactory factory)
        {
            mxICanvas canvas = null;

            if (cells == null)
            {
                cells = new Object[] { graph.Model.Root };
            }

            if (cells != null)
            {
                // Gets the current state of the view
                mxGraphView view = graph.View;
                Dictionary <Object, mxCellState> states = view.States;
                double oldScale = view.Scale;

                // Keeps the existing translation as the cells might
                // be aligned to the grid in a different way in a graph
                // that has a translation other than zero
                bool eventsEnabled = view.IsEventsEnabled;

                // Disables firing of scale events so that there is no
                // repaint or update of the original graph
                view.IsEventsEnabled = false;

                try
                {
                    // TODO: Factor-out into mxTemporaryCellStates class
                    view.States = new Dictionary <Object, mxCellState>();
                    view.Scale  = scale;

                    // Validates the vertices and edges without adding them to
                    // the model so that the original cells are not modified
                    for (int i = 0; i < cells.Length; i++)
                    {
                        view.ValidateCellState(view.ValidateCell(cells[i]));
                    }

                    if (clip == null)
                    {
                        clip = graph.GetPaintBounds(cells);
                    }

                    if (clip != null && clip.Width > 0 && clip.Height > 0)
                    {
                        Rectangle rect = clip.GetRectangle();
                        canvas = factory.CreateCanvas(rect.Width + 1,
                                                      rect.Height + 1);

                        if (canvas != null)
                        {
                            double previousScale     = canvas.Scale;
                            Point  previousTranslate = canvas.Translate;

                            try
                            {
                                canvas.Translate = new Point(-rect.X, -rect.Y);
                                canvas.Scale     = view.Scale;

                                for (int i = 0; i < cells.Length; i++)
                                {
                                    graph.DrawCell(canvas, cells[i]);
                                }
                            }
                            finally
                            {
                                canvas.Scale     = previousScale;
                                canvas.Translate = previousTranslate;
                            }
                        }
                    }
                }
                finally
                {
                    view.Scale           = oldScale;
                    view.States          = states;
                    view.IsEventsEnabled = eventsEnabled;
                }
            }

            return(canvas);
        }
コード例 #14
0
 /**
  * Constructs a new stack layout layout for the specified graph,
  * spacing, orientation and offset.
  */
 public mxCircleLayout(mxGraph graph, double radius)
 {
     this.graph  = graph;
     this.radius = radius;
 }
コード例 #15
0
 /**
  * Constructs a new stack layout layout for the specified graph,
  * spacing, orientation and offset.
  */
 public mxCircleLayout(mxGraph graph)
 {
     radius     = 100;
     this.graph = graph;
 }
コード例 #16
0
 /// <summary>
 /// Creates an image for the given arguments.
 /// </summary>
 public static Image CreateImage(mxGraph graph, Object[] cells, double scale, Color?background,
                                 bool antiAlias, mxRectangle clip)
 {
     return(CreateImage(graph, cells, scale, background, antiAlias, clip, new mxGdiCanvas()));
 }
コード例 #17
0
        public static void LoadModelFromXml(this mxGraph mx_graph, XmlDocument xml)
        {
            mxCodec codec = new mxCodec(xml);

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