The tooltip should be more responsive

When the tooltip is rendered close to the edge of the screen it should display on the side of the mouse that has space for it. These changes accomplish this and centralize the logic. Used in the "histogram", "pie", "terms", and "hits" panels.