private Size DrawReturnConnection(Size size, SequenceDiagramConnection connection)
        {
            var callerNodeMiddlePoint = _nodeMiddlePoints[connection.CallerId];
            var calledNodeMiddlePoint = connection.CalledId == Guid.Empty ? 0 : _nodeMiddlePoints[connection.CalledId];

            var text = new FormattedText("return " + connection.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Fonts.FontLight, 12, Brushes.Gray);

            _context.DrawText(text, new Point(calledNodeMiddlePoint + 10, size.Height));

            if ((text.Width + calledNodeMiddlePoint + 10) > size.Width)
            {
                size.Width = text.Width + calledNodeMiddlePoint + 20;
            }

            _context.DrawLine(new Pen(Brushes.Gray, 1), new Point(calledNodeMiddlePoint, size.Height + 20), new Point(callerNodeMiddlePoint, size.Height + 20));

            var startX   = (int)calledNodeMiddlePoint;
            var startY   = (int)size.Height + 20;
            var start    = new Point(startX, startY);
            var segments = new[] { new LineSegment(new Point(startX + 5, startY + 5), true), new LineSegment(new Point(startX + 5, startY - 5), true) };
            var figure   = new PathFigure(start, segments, true);
            var geo      = new PathGeometry(new[] { figure });

            _context.DrawGeometry(Brushes.Gray, new Pen(Brushes.Gray, 1), geo);

            size.Height += 35;

            return(size);
        }
        private void DrawConnectionLine(SequenceDiagramConnection connection, double callerNodeMiddlePoint, double calledNodeMiddlePoint)
        {
            if (connection.CallerId == connection.CalledId)
            {
                double x1 = callerNodeMiddlePoint;
                double x2 = callerNodeMiddlePoint - 10;
                double y1 = _diagramSize.Height + 10;
                double y2 = _diagramSize.Height + 20;

                var path = new SvgPath(_svgRoot, string.Format("M{0},{1}L{2},{1}",
                                                               x1.ToString("0.00", CultureInfo.InvariantCulture),
                                                               y1.ToString("0.00", CultureInfo.InvariantCulture),
                                                               x2.ToString("0.00", CultureInfo.InvariantCulture)));
                path.StrokeWidth = 1;
                path.Stroke      = "#979797";

                var path2 = new SvgPath(_svgRoot, string.Format("M{0},{1}L{0},{2}",
                                                                x2.ToString("0.00", CultureInfo.InvariantCulture),
                                                                y1.ToString("0.00", CultureInfo.InvariantCulture),
                                                                y2.ToString("0.00", CultureInfo.InvariantCulture)));
                path2.StrokeWidth = 1;
                path2.Stroke      = "#979797";

                var path3 = new SvgPath(_svgRoot, string.Format("M{0},{1}L{2},{1}",
                                                                x2.ToString("0.00", CultureInfo.InvariantCulture),
                                                                y2.ToString("0.00", CultureInfo.InvariantCulture),
                                                                x1.ToString("0.00", CultureInfo.InvariantCulture)));
                path3.StrokeWidth = 1;
                path3.Stroke      = "#979797";

                _svgGraphic.Add(path);
                _svgGraphic.Add(path2);
                _svgGraphic.Add(path3);
            }
            else
            {
                var path = new SvgPath(_svgRoot, string.Format("M{0},{2}L{1},{2}",
                                                               callerNodeMiddlePoint.ToString("0.00", CultureInfo.InvariantCulture),
                                                               calledNodeMiddlePoint.ToString("0.00", CultureInfo.InvariantCulture),
                                                               (_diagramSize.Height + 20).ToString("0.00", CultureInfo.InvariantCulture)));
                path.StrokeWidth = 1;
                path.Stroke      = "#979797";

                _svgGraphic.Add(path);
            }

            _diagramSize.Height += 20;
        }
        private void DrawConnection(SequenceDiagramConnection connection)
        {
            var callerNodeMiddlePoint = connection.CallerId == Guid.Empty ? 0 : _nodeMiddlePoints[connection.CallerId];
            var calledNodeMiddlePoint = _nodeMiddlePoints[connection.CalledId];

            var textWidth = connection.Text.GetWidth(12, Fonts.FontLight);
            var link      = new SvgLink(_svgRoot, connection.Text, string.Format("{{{{method-link:{0}}}}}", connection.CalledMethodIdentifier), callerNodeMiddlePoint + 10, _diagramSize.Height + 10);

            link.Text.FontSize = 12;
            _svgGraphic.Add(link);

            if ((textWidth + callerNodeMiddlePoint + 10) > _diagramSize.Width)
            {
                _diagramSize.Width = textWidth + callerNodeMiddlePoint + 20;
            }

            DrawConnectionLine(connection, callerNodeMiddlePoint, calledNodeMiddlePoint);
            DrawConnectionArrow(calledNodeMiddlePoint);
        }
        private Size DrawConnection(Size size, SequenceDiagramConnection connection)
        {
            var callerNodeMiddlePoint = connection.CallerId == Guid.Empty ? 0 : _nodeMiddlePoints[connection.CallerId];
            var calledNodeMiddlePoint = _nodeMiddlePoints[connection.CalledId];

            var text = new FormattedText(connection.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Fonts.FontLight, 12, Brushes.Black);

            _context.DrawText(text, new Point(callerNodeMiddlePoint + 10, size.Height));

            if ((text.Width + callerNodeMiddlePoint + 10) > size.Width)
            {
                size.Width = text.Width + callerNodeMiddlePoint + 20;
            }

            size = DrawConnectionLine(connection, callerNodeMiddlePoint, calledNodeMiddlePoint, size);
            size = DrawConnectionArrow(calledNodeMiddlePoint, size);

            return(size);
        }
        private Size DrawConnectionLine(SequenceDiagramConnection connection, double callerNodeMiddlePoint, double calledNodeMiddlePoint, Size size)
        {
            if (connection.CallerId == connection.CalledId)
            {
                double x1 = callerNodeMiddlePoint;
                double x2 = callerNodeMiddlePoint - 10;
                double y1 = size.Height + 10;
                double y2 = size.Height + 20;

                _context.DrawLine(new Pen(Brushes.Black, 1), new Point(x1, y1), new Point(x2, y1));
                _context.DrawLine(new Pen(Brushes.Black, 1), new Point(x2, y1), new Point(x2, y2));
                _context.DrawLine(new Pen(Brushes.Black, 1), new Point(x2, y2), new Point(x1, y2));
            }
            else
            {
                _context.DrawLine(new Pen(Brushes.Black, 1),
                                  new Point(callerNodeMiddlePoint, size.Height + 20),
                                  new Point(calledNodeMiddlePoint, size.Height + 20));
            }

            size.Height += 20;
            return(size);
        }
        private void DrawReturnConnection(SequenceDiagramConnection connection)
        {
            var callerNodeMiddlePoint = _nodeMiddlePoints[connection.CallerId];
            var calledNodeMiddlePoint = connection.CalledId == Guid.Empty ? 0 : _nodeMiddlePoints[connection.CalledId];

            var textWidth = ("return " + connection.Text).GetWidth(12, Fonts.FontLight);
            var text      = new SvgText(_svgRoot, "return " + connection.Text, calledNodeMiddlePoint + 10, _diagramSize.Height + 10);

            text.FontSize = 12;
            _svgGraphic.Add(text);

            if ((textWidth + calledNodeMiddlePoint + 10) > _diagramSize.Width)
            {
                _diagramSize.Width = textWidth + calledNodeMiddlePoint + 20;
            }

            var path = new SvgPath(_svgRoot, string.Format("M{0},{1}L{2},{1}",
                                                           calledNodeMiddlePoint.ToString("0.00", CultureInfo.InvariantCulture),
                                                           (_diagramSize.Height + 20).ToString("0.00", CultureInfo.InvariantCulture),
                                                           callerNodeMiddlePoint.ToString("0.00", CultureInfo.InvariantCulture)));

            path.StrokeWidth = 1;
            path.Stroke      = "#979797";
            _svgGraphic.Add(path);

            var startX = (int)calledNodeMiddlePoint;
            var startY = (int)_diagramSize.Height + 20;

            var points = string.Format("{0},{1} {2},{3} {2},{4}", startX, startY, startX + 5, startY + 5, startY - 5);
            var arrow  = new SvgPolygon(_svgRoot, points);

            arrow.Stroke = arrow.Fill = "#979797";

            _svgGraphic.Add(arrow);

            _diagramSize.Height += 35;
        }