コード例 #1
0
        private void refreshSimplifiedChart()
        {
            if (_rootNode == null)
            {
                return;
            }

            INode simpleNode = SimplifyNode(_rootNode);

            var rootNode = new ChartNode(simpleNode.Prettify(), simpleNode.Evaluate());

            if (simpleNode.Children != null)
            {
                foreach (var child in simpleNode.Children)
                {
                    recursiveAddChartNode(child, rootNode);
                }
            }

            var bitmap = OrganizationChart.Generate(rootNode, simplePictureBox.Width);

            // liberamos los recursor y ponemos nuestra nueva imagen.
            simplePictureBox.Image?.Dispose();
            simplePictureBox.Image = bitmap;
        }
コード例 #2
0
        private void recursiveAddChartNode(INode node, ChartNode parent)
        {
            var ourNode = new ChartNode(node.Prettify(), node.Evaluate());

            if (node.Children != null)
            {
                foreach (var child in node.Children)
                {
                    recursiveAddChartNode(child, ourNode);
                }
            }

            parent.Children.Add(ourNode);
        }
コード例 #3
0
        // Redraw la vista chart
        private void refreshChart()
        {
            if (_rootNode == null)
            {
                return;
            }

            var rootNode = new ChartNode(_rootNode.Prettify(), _rootNode.Evaluate());

            if (_rootNode.Children != null)
            {
                foreach (var child in _rootNode.Children)
                {
                    recursiveAddChartNode(child, rootNode);
                }
            }

            var bitmap = OrganizationChart.Generate(rootNode, pictureBox1.Width);

            // liberamos los recursor y ponemos nuestra nueva imagen.
            pictureBox1.Image?.Dispose();
            pictureBox1.Image = bitmap;
        }
コード例 #4
0
ファイル: OrganizationChart.cs プロジェクト: Guad/vizlogic
        public static Bitmap Generate(ChartNode root, int width)
        {
            const int picHeight = 70;
            // Altura de un nodo.

            // Bitmap de nuestro nivel
            var ourLevel = new Bitmap(width, picHeight);

            Font txtFont = new Font(FontFamily.GenericSansSerif, 14f, FontStyle.Regular);

            SizeF strSize;

            using (var g = Graphics.FromImage(ourLevel))
            {
                strSize = g.MeasureString(root.Text, txtFont);
                // Dibujamos nuestro nodo en medio de la imagen
                g.FillRectangle(root.State ? Brushes.Green : Brushes.Red, width / 2 - strSize.Width / 2 - 5, 5, strSize.Width + 10, strSize.Height + 10);
                g.DrawRectangle(Pens.DarkGray, width / 2 - strSize.Width / 2 - 5, 5, strSize.Width + 10, strSize.Height + 10);
                g.DrawString(root.Text, txtFont, Brushes.White, width / 2 - strSize.Width / 2, 10);
            }

            // Recogemos las imagenes de nuestros hijos en un array diferente, para conocer la altura maxima
            Bitmap[] childPics = new Bitmap[root.Children.Count];
            for (int i = 0; i < root.Children.Count; i++)
            {
                childPics[i] = Generate(root.Children[i], width / root.Children.Count);
            }

            int maxHeight = 0;

            // Si hay hijos, cogemos la altura maxima para la imagen final.
            if (root.Children.Count > 0)
            {
                maxHeight = childPics.Max(bm => bm.Height);
            }

            // Altura: nuestra altura + altura maxima de un hijo
            var newBitmap = new Bitmap(width, picHeight + maxHeight);

            using (var g = Graphics.FromImage(newBitmap))
            {
                g.DrawImage(ourLevel, 0, 0);

                for (int i = 0; i < childPics.Length; i++)
                {
                    // Dibujamos cada hijo equitativamente.
                    g.DrawImage(childPics[i], i * (width / root.Children.Count), picHeight);

                    g.DrawLine(Pens.Black, width / 2, strSize.Height + 15, i * (width / root.Children.Count) + (width / root.Children.Count) / 2, picHeight + 5);

                    // Liberamos los recursos.
                    childPics[i].Dispose();
                }
            }

            // Liberamos recursos.
            ourLevel.Dispose();
            txtFont.Dispose();

            return(newBitmap);
        }