private void CreateTree(int levels, int branchNodes)
        {
            // clean up the active layer
            NDrawingView1.Document.ActiveLayer.RemoveAllChildren();

            // we will be using basic shapes with 40, 40 size
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(40, 40);

            NShape cur  = null;
            NShape edge = null;

            List <NShape> curRowNodes  = null;
            List <NShape> prevRowNodes = null;

            int i, level;
            int levelNodesCount;

            for (level = 1; level <= levels; level++)
            {
                curRowNodes = new List <NShape>();

                //Create a balanced tree
                levelNodesCount = (int)Math.Pow(branchNodes, level - 1);
                for (i = 0; i < levelNodesCount; i++)
                {
                    // create the cur node
                    cur = basicShapesFactory.CreateShape(BasicShapes.Circle);
                    ((NDynamicPort)cur.Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                    NDrawingView1.Document.ActiveLayer.AddChild(cur);

                    // connect with ancestor
                    if (level > 1)
                    {
                        edge = new NLineShape();
                        NDrawingView1.Document.ActiveLayer.AddChild(edge);

                        int parentIndex = (int)Math.Floor((double)(i / branchNodes));
                        edge.FromShape = prevRowNodes[parentIndex];
                        edge.ToShape   = cur;
                    }

                    curRowNodes.Add(cur);
                }

                prevRowNodes = curRowNodes;
            }

            // send links to back
            NBatchReorder batchReorder = new NBatchReorder(NDrawingView1.Document);

            batchReorder.Build(NDrawingView1.Document.ActiveLayer.Children(NFilters.Shape1D));
            batchReorder.SendToBack(false);
        }
        /// <summary>
        /// Creates a triangular grid diagram with the specified count of levels
        /// </summary>
        /// <param name="levels"></param>
        private void CreateTriangularGridDiagram(int levels)
        {
            // clean up the active layer
            document.ActiveLayer.RemoveAllChildren();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(30, 30);

            NShape        cur = null, prev = null;
            NShape        edge          = null;
            List <NShape> curRowShapes  = null;
            List <NShape> prevRowShapes = null;

            for (int level = 1; level < levels; level++)
            {
                curRowShapes = new List <NShape>();

                for (int i = 0; i < level; i++)
                {
                    cur = basicShapesFactory.CreateShape(BasicShapes.Circle);
                    ((NDynamicPort)cur.Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                    cur.Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(192, 194, 194), Color.FromArgb(129, 133, 133));
                    cur.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                    document.ActiveLayer.AddChild(cur);

                    // connect with prev
                    if (i > 0)
                    {
                        edge = new NLineShape();
                        document.ActiveLayer.AddChild(edge);

                        edge.FromShape = prev;
                        edge.ToShape   = cur;
                    }

                    // connect with ancestors
                    if (level > 1)
                    {
                        if (i < prevRowShapes.Count)
                        {
                            edge = new NLineShape();
                            document.ActiveLayer.AddChild(edge);

                            edge.FromShape = prevRowShapes[i];
                            edge.ToShape   = cur;
                        }

                        if (i > 0)
                        {
                            edge = new NLineShape();
                            document.ActiveLayer.AddChild(edge);

                            edge.FromShape = prevRowShapes[i - 1];
                            edge.ToShape   = cur;
                        }
                    }

                    // fix the three corner vertices
                    if (level == 1 || (level == levels - 1 && (i == 0 || i == level - 1)))
                    {
                        cur.LayoutData.ForceXMoveable = false;
                        cur.LayoutData.ForceYMoveable = false;
                        cur.Style.FillStyle           = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(251, 203, 156), Color.FromArgb(247, 150, 56));
                        cur.Style.StrokeStyle         = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                    }

                    curRowShapes.Add(cur);
                    prev = cur;
                }

                prevRowShapes = curRowShapes;
            }

            NBatchReorder batchReorder = new NBatchReorder(document);

            batchReorder.Build(document.ActiveLayer.Children(NFilters.Shape1D));
            batchReorder.SendToBack(false);
        }
        /// <summary>
        /// Creates a random barycenter diagram with the specified settings
        /// </summary>
        /// <param name="fixedCount">number of fixed vertices (must be larger than 3)</param>
        /// <param name="freeCount">number of free vertices</param>
        private void CreateRandomDiagram(int fixedCount, int freeCount)
        {
            if (fixedCount < 3)
            {
                throw new ArgumentException("Needs at least three fixed vertices");
            }

            // clean up the layers
            document.ActiveLayer.RemoveAllChildren();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(30, 30);

            // create the fixed vertices
            NShape[] fixedShapes = new NShape[fixedCount];

            for (int i = 0; i < fixedCount; i++)
            {
                fixedShapes[i] = basicShapesFactory.CreateShape(BasicShapes.Circle);
                ((NDynamicPort)fixedShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                fixedShapes[i].Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(251, 203, 156), Color.FromArgb(247, 150, 56));
                fixedShapes[i].Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));

                // setting the ForceXMoveable and ForceYMoveable properties to false
                // specifies that the layout cannot move the shape in both X and Y directions
                fixedShapes[i].LayoutData.ForceXMoveable = false;
                fixedShapes[i].LayoutData.ForceYMoveable = false;

                document.ActiveLayer.AddChild(fixedShapes[i]);
            }

            // create the free vertices
            NShape[] freeShapes = new NShape[freeCount];
            for (int i = 0; i < freeCount; i++)
            {
                freeShapes[i] = basicShapesFactory.CreateShape(BasicShapes.Circle);
                ((NDynamicPort)freeShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                freeShapes[i].Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(192, 194, 194), Color.FromArgb(129, 133, 133));
                freeShapes[i].Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                document.ActiveLayer.AddChild(freeShapes[i]);
            }

            // link the fixed shapes in a circle
            for (int i = 0; i < fixedCount; i++)
            {
                NLineShape lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                if (i == 0)
                {
                    lineShape.FromShape = fixedShapes[fixedCount - 1];
                    lineShape.ToShape   = fixedShapes[0];
                }
                else
                {
                    lineShape.FromShape = fixedShapes[i - 1];
                    lineShape.ToShape   = fixedShapes[i];
                }
            }

            // link each free shape with two different random fixed shapes
            Random rnd = new Random();

            for (int i = 0; i < freeCount; i++)
            {
                int firstFixed  = rnd.Next(fixedCount);
                int secondFixed = (firstFixed + rnd.Next(fixedCount / 3) + 1) % fixedCount;

                // link with first fixed
                NLineShape lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                lineShape.FromShape = freeShapes[i];
                lineShape.ToShape   = fixedShapes[firstFixed];

                // link with second fixed
                lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                lineShape.FromShape = freeShapes[i];
                lineShape.ToShape   = fixedShapes[secondFixed];
            }

            // link each free shape with another free shape
            for (int i = 1; i < freeCount; i++)
            {
                NLineShape lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                lineShape.FromShape = freeShapes[i - 1];
                lineShape.ToShape   = freeShapes[i];
            }

            NBatchReorder batchReorder = new NBatchReorder(document);

            batchReorder.Build(document.ActiveLayer.Children(NFilters.Shape1D));
            batchReorder.SendToBack(false);
        }
        /// <summary>
        /// Creates a triangular grid diagram with the specified count of levels
        /// </summary>
        /// <param name="levels"></param>
        private void CreateTriangularGridDiagram(int levels)
        {
            // clean up the active page
            NPage activePage = m_DrawingDocument.Content.ActivePage;

            activePage.Items.Clear();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory();

            basicShapesFactory.DefaultSize = new NSize(30, 30);

            NConnectorShapeFactory connectorShapesFactory = new NConnectorShapeFactory();

            NShape             cur = null, prev = null;
            NRoutableConnector edge          = null;
            NList <NShape>     curRowShapes  = null;
            NList <NShape>     prevRowShapes = null;

            for (int level = 1; level < levels; level++)
            {
                curRowShapes = new NList <NShape>();

                for (int i = 0; i < level; i++)
                {
                    cur = basicShapesFactory.CreateShape(ENBasicShape.Circle);
                    cur.Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(192, 194, 194), new NColor(129, 133, 133));
                    cur.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));
                    activePage.Items.Add(cur);

                    // connect with prev
                    if (i > 0)
                    {
                        edge = new NRoutableConnector();
                        edge.MakeLine();
                        activePage.Items.Add(edge);

                        edge.GlueBeginToShape(prev);
                        edge.GlueEndToShape(cur);
                    }

                    // connect with ancestors
                    if (level > 1)
                    {
                        if (i < prevRowShapes.Count)
                        {
                            edge = new NRoutableConnector();
                            edge.MakeLine();
                            activePage.Items.Add(edge);

                            edge.GlueBeginToShape(prevRowShapes[i]);
                            edge.GlueEndToShape(cur);
                        }

                        if (i > 0)
                        {
                            edge = new NRoutableConnector();
                            edge.MakeLine();
                            activePage.Items.Add(edge);

                            edge.GlueBeginToShape(prevRowShapes[i - 1]);
                            edge.GlueEndToShape(cur);
                        }
                    }

                    // fix the three corner vertices
                    if (level == 1 || (level == levels - 1 && (i == 0 || i == level - 1)))
                    {
                        NForceDirectedGraphLayout.SetXMoveable(cur, false);
                        NForceDirectedGraphLayout.SetYMoveable(cur, false);

                        cur.Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(251, 203, 156), new NColor(247, 150, 56));
                        cur.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));
                    }

                    curRowShapes.Add(cur);
                    prev = cur;
                }

                prevRowShapes = curRowShapes;
            }

            // send all edges to back
            NBatchReorder batchReorder = new NBatchReorder(m_DrawingDocument);

            batchReorder.Build(activePage.GetShapes(false, NDiagramFilters.ShapeType1D).CastAll <NDiagramItem>());
            batchReorder.SendToBack(activePage);

            // arrange the elements
            ArrangeDiagram();
        }
        /// <summary>
        /// Creates a random barycenter diagram with the specified settings
        /// </summary>
        /// <param name="fixedCount">number of fixed vertices (must be larger than 3)</param>
        /// <param name="freeCount">number of free vertices</param>
        private void CreateRandomBarycenterDiagram(int fixedCount, int freeCount)
        {
            if (fixedCount < 3)
            {
                throw new ArgumentException("Needs at least three fixed vertices");
            }

            // clean up the active page
            NPage activePage = m_DrawingDocument.Content.ActivePage;

            activePage.Items.Clear();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory();

            basicShapesFactory.DefaultSize = new NSize(30, 30);

            NConnectorShapeFactory connectorsShapesFactory = new NConnectorShapeFactory();

            // create the fixed vertices
            NShape[] fixedShapes = new NShape[fixedCount];

            for (int i = 0; i < fixedCount; i++)
            {
                fixedShapes[i] = basicShapesFactory.CreateShape(ENBasicShape.Circle);

                //((NDynamicPort)fixedShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                fixedShapes[i].Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(251, 203, 156), new NColor(247, 150, 56));
                fixedShapes[i].Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));

                // setting the ForceXMoveable and ForceYMoveable properties to false
                // specifies that the layout cannot move the shape in both X and Y directions
                NForceDirectedGraphLayout.SetXMoveable(fixedShapes[i], false);
                NForceDirectedGraphLayout.SetYMoveable(fixedShapes[i], false);

                activePage.Items.AddChild(fixedShapes[i]);
            }

            // create the free vertices
            NShape[] freeShapes = new NShape[freeCount];
            for (int i = 0; i < freeCount; i++)
            {
                freeShapes[i] = basicShapesFactory.CreateShape(ENBasicShape.Circle);
                freeShapes[i].Geometry.Fill   = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(192, 194, 194), new NColor(129, 133, 133));
                freeShapes[i].Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108));
                activePage.Items.AddChild(freeShapes[i]);
            }

            // link the fixed shapes in a circle
            for (int i = 0; i < fixedCount; i++)
            {
                NRoutableConnector connector = new NRoutableConnector();
                connector.MakeLine();
                activePage.Items.AddChild(connector);

                if (i == 0)
                {
                    connector.GlueBeginToShape(fixedShapes[fixedCount - 1]);
                    connector.GlueEndToShape(fixedShapes[0]);
                }
                else
                {
                    connector.GlueBeginToShape(fixedShapes[i - 1]);
                    connector.GlueEndToShape(fixedShapes[i]);
                }
            }

            // link each free shape with two different random fixed shapes
            Random rnd = new Random();

            for (int i = 0; i < freeCount; i++)
            {
                int firstFixed  = rnd.Next(fixedCount);
                int secondFixed = (firstFixed + rnd.Next(fixedCount / 3) + 1) % fixedCount;

                // link with first fixed
                NRoutableConnector lineShape = new NRoutableConnector();
                lineShape.MakeLine();
                activePage.Items.AddChild(lineShape);

                lineShape.GlueBeginToShape(freeShapes[i]);
                lineShape.GlueEndToShape(fixedShapes[firstFixed]);

                // link with second fixed
                lineShape = new NRoutableConnector();
                lineShape.MakeLine();
                activePage.Items.AddChild(lineShape);

                lineShape.GlueBeginToShape(freeShapes[i]);
                lineShape.GlueEndToShape(fixedShapes[secondFixed]);
            }

            // link each free shape with another free shape
            for (int i = 1; i < freeCount; i++)
            {
                NRoutableConnector connector = new NRoutableConnector();
                connector.MakeLine();
                activePage.Items.AddChild(connector);

                connector.GlueBeginToShape(freeShapes[i - 1]);
                connector.GlueEndToShape(freeShapes[i]);
            }

            // send all edges to back
            NBatchReorder batchReorder = new NBatchReorder(m_DrawingDocument);

            batchReorder.Build(activePage.GetShapes(false, NDiagramFilters.ShapeType1D).CastAll <NDiagramItem>());
            batchReorder.SendToBack(activePage);

            // arrange the elements
            ArrangeDiagram();
        }