Esempio n. 1
0
        public void MoveNode(int id, float newX, float newY)
        {
            if (newX < 0 || newX > Width || newY < 0 || newY > Height)
            {
                throw new ArgumentOutOfRangeException();
            }
            DrawableGraphNode curr = (DrawableGraphNode)CurrGraph.Nodes[id];

            curr.Position = new PointF(newX, newY);
        }
Esempio n. 2
0
        public void ChangeNodeColor(int idNode, Color color)
        {
            if (idNode < 0 || idNode >= CurrGraph.Nodes.Count)
            {
                throw new ArgumentOutOfRangeException();
            }
            DrawableGraphNode node = CurrGraph.Nodes[idNode] as DrawableGraphNode;

            node.FillingColor = color;
        }
Esempio n. 3
0
        public void Draw(Graphics field, RectangleF clipRect)
        {
            field.Clear(Color.White);
            foreach (DrawableGraphNode node in CurrGraph.Nodes)
            {
                foreach (var edge in node.To)
                {
                    DrawableGraphNode to = CurrGraph.Nodes[edge.Item1] as DrawableGraphNode;
                    field.DrawLine(Pens.Black, TranslateFromLocal(node.Position, clipRect),
                                   TranslateFromLocal(to.Position, clipRect));
                    PointF fromDot   = TranslateFromLocal(node.Position, clipRect);
                    PointF toDot     = TranslateFromLocal(to.Position, clipRect);
                    PointF weightDot = new PointF((fromDot.X + toDot.X) / 2,
                                                  (fromDot.Y + toDot.Y) / 2);
                    field.DrawString(edge.Item2.ToString(),
                                     new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace),
                                              node.Radius / 2),
                                     Brushes.SaddleBrown,
                                     weightDot);
                }
            }

            foreach (DrawableGraphNode node in CurrGraph.Nodes)
            {
                PointF dot = TranslateFromLocal(node.Position, clipRect);
                dot = new PointF(dot.X - node.Radius, dot.Y - node.Radius);
                RectangleF rect = new RectangleF(dot,
                                                 new SizeF(node.Radius * 2, node.Radius * 2));
                field.DrawEllipse(Pens.Black, rect);
                field.FillEllipse(new SolidBrush(node.FillingColor), rect);
                field.DrawString(node.Id.ToString(),
                                 new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace),
                                          node.Radius / 2),
                                 Brushes.Black,
                                 dot.X + node.Radius / 2,
                                 dot.Y + node.Radius / 2);
            }
        }