{"action":"created","issue":{"url":"https://api.github.com/repos/novus/nvd3/issues/1124","labels_url":"https://api.github.com/repos/novus/nvd3/issues/1124/labels{/name}","comments_url":"https://api.github.com/repos/novus/nvd3/issues/1124/comments","events_url":"https://api.github.com/repos/novus/nvd3/issues/1124/events","html_url":"https://github.com/novus/nvd3/issues/1124","id":93298227,"number":1124,"title":"tooltip with 'w' gravity jumps down when it hits top of window","user":{"login":"jmensch1","id":9143823,"avatar_url":"https://avatars.githubusercontent.com/u/9143823?v=3","gravatar_id":"","url":"https://api.github.com/users/jmensch1","html_url":"https://github.com/jmensch1","followers_url":"https://api.github.com/users/jmensch1/followers","following_url":"https://api.github.com/users/jmensch1/following{/other_user}","gists_url":"https://api.github.com/users/jmensch1/gists{/gist_id}","starred_url":"https://api.github.com/users/jmensch1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmensch1/subscriptions","organizations_url":"https://api.github.com/users/jmensch1/orgs","repos_url":"https://api.github.com/users/jmensch1/repos","events_url":"https://api.github.com/users/jmensch1/events{/privacy}","received_events_url":"https://api.github.com/users/jmensch1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-06T14:52:44Z","updated_at":"2015-07-14T15:07:00Z","closed_at":null,"body":"I'm using the tooltip with the default 'w' gravity, and when the tooltip hits the top of the window, it jumps down below the mouse instead of hugging the top of the window.  I found the problem in the code that calculates the tooltip position (starting at line 664 in version 1.8.1 dated 2015-06-17) -- \r\n\r\n```\r\nswitch (gravity) {\r\n    case 'e':\r\n        left = pos[0] - width - distance;\r\n        top = pos[1] - (height / 2);\r\n        tLeft = tooltipLeft(tooltipElem);\r\n        tTop = tooltipTop(tooltipElem);\r\n        if (tLeft < scrollLeft) left = pos[0] + distance > scrollLeft ? pos[0] + distance : scrollLeft - tLeft + left;\r\n        if (tTop < scrollTop) top = scrollTop - tTop + top;     // LINE A\r\n        if (tTop + height > scrollTop + windowHeight) top = scrollTop + windowHeight - tTop + top - height;\r\n        break;\r\n    case 'w':\r\n        left = pos[0] + distance;\r\n        top = pos[1] - (height / 2);\r\n        tLeft = tooltipLeft(tooltipElem);\r\n        tTop = tooltipTop(tooltipElem);\r\n        if (tLeft + width > windowWidth) left = pos[0] - width - distance;\r\n        if (tTop < scrollTop) top = scrollTop + 5;       // LINE B\r\n        if (tTop + height > scrollTop + windowHeight) top = scrollTop + windowHeight - tTop + top - height;\r\n        break;\r\n```\r\n\r\nNotice that the formula for calculating top is different for 'e' and 'w' (compare Line A with Line B).  To fix the problem, I simply made Line B the same as Line A, so Line B is now:\r\n\r\n``` \r\nif (tTop < scrollTop) top = scrollTop - tTop + top;  \r\n```\r\n\r\nThis fixed the issue in all browsers.\r\n\r\nThanks for your great work on this library, my client is very happy with it.\r\n"},"comment":{"url":"https://api.github.com/repos/novus/nvd3/issues/comments/121276237","html_url":"https://github.com/novus/nvd3/issues/1124#issuecomment-121276237","issue_url":"https://api.github.com/repos/novus/nvd3/issues/1124","id":121276237,"user":{"login":"liquidpele","id":1065913,"avatar_url":"https://avatars.githubusercontent.com/u/1065913?v=3","gravatar_id":"","url":"https://api.github.com/users/liquidpele","html_url":"https://github.com/liquidpele","followers_url":"https://api.github.com/users/liquidpele/followers","following_url":"https://api.github.com/users/liquidpele/following{/other_user}","gists_url":"https://api.github.com/users/liquidpele/gists{/gist_id}","starred_url":"https://api.github.com/users/liquidpele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liquidpele/subscriptions","organizations_url":"https://api.github.com/users/liquidpele/orgs","repos_url":"https://api.github.com/users/liquidpele/repos","events_url":"https://api.github.com/users/liquidpele/events{/privacy}","received_events_url":"https://api.github.com/users/liquidpele/received_events","type":"User","site_admin":false},"created_at":"2015-07-14T15:07:00Z","updated_at":"2015-07-14T15:07:00Z","body":"Hey there!   Can you send us a pull request with the fix?   "}}