Allow the gravity to be a string, or a function to calculate it dynamically

If it is a function, it will be called with the position of the element,
and its dimensions. This can be used to control the tooltip positioning as necessary.