The optimal position is #1, the top left corner, for text that reads left to right and top to bottom. This positioning allows for the text to be easily read and for the user to move the mouse and their eyes in the same direction that they normally read.
But when the mouse is positioned close to the edge of the viewport the panel should be displayed so as not to be hidden or trigger scrolling.
If the mouse is close to the bottom left of the viewport the panel should be displayed above the mouse as in your #4 example.
When the mouse is close to the bottom right it would resemble #2.
If the mouse is to the right and is far enough above the bottom of the viewport for the panel to be displayed example #3 would be used.