Autoscroll diagram on node outside viewport

The aim is to let user moving node outside the actual viewport (using drag tool) without stop dragging, scroll the diagram, restart dragging but performing a clever auto-scroll.

I use this code, but it is not really good…

public void MovePanel(Node node)
if (node == null) return;
DiagramPanel panel = node.Panel;
if (panel == null) return;

        // get the bounds of the Node, in model coordinates
        Rect r = node.Bounds;
        // get the bounds of the visible extent of the view, in model coordinates
        Rect v = panel.ViewportBounds;

        // scroll the panel in the right direction
        double dX = v.X;
        double dY = v.Y;
        double dDelta = 20.0;
        double dMore = 30.0;

        if (r.Y + r.Height >= v.Y + v.Height + dMore) dY += dDelta;
        else if (r.Y <= v.Y + dMore) dY -= dDelta;

        if (r.X + r.Width >= v.X + v.Width + dMore) dX += dDelta;
        else if (r.X <= v.X + dMore) dX -= dDelta;

        if (dX != v.X || dY != v.Y)
            panel.Position = new Point(dX, dY);