예제 #1
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);
        }
예제 #2
0
파일: Form.cs 프로젝트: ngertrudiz/mxgraph
 public GraphControl(mxGraph graph)
 {
     this.graph = graph;
     this.AutoScroll = true;
     this.Paint += new PaintEventHandler(PaintBuffer);
     this.graph.Model.GraphModelChange += new mxGraphModelChangeEventHandler(RefreshBuffer);
 }
예제 #3
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));
        }
예제 #4
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);
        }
예제 #5
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();
        }
예제 #6
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);
        }
예제 #7
0
파일: Form.cs 프로젝트: ngertrudiz/mxgraph
        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);
        }
예제 #8
0
 /// <summary>
 /// Constructs a new fast organic layout for the specified graph.
 /// </summary>
 /// <param name="graph"></param>
 public mxFastOrganicLayout(mxGraph graph)
 {
     this.graph = graph;
 }
예제 #9
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;

                    // Creates virtual parent state for validation
                    mxCellState state = view.CreateState(new mxCell());

                    // 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.ValidateBounds(state, cells[i]);
                    }

                    for (int i = 0; i < cells.Length; i++)
                    {
                        view.ValidatePoints(state, 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;
        }
예제 #10
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());
 }
예제 #11
0
 /// <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;
 }