-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug with tooltip positioning. #1674
Conversation
travis seems to be failing because of the environment the tests are running, not because of the PR. Also, all the tests passed in my machine. |
I have the same issue. And this PR does not solve my problem. Also you have this commit In my case, this commit fixes issue with tooltip positioning. |
@workgena the problem is that that commit breakes tooltip positioning in other cases. |
Found strong dependence on bootstrap version. Boostrap 2.3.1 Boostrap 3.3.6 This is CSS issue with bootstrap v3.3.6. Tooltip position has exact offset as has modal. To see it more clearly - resize demonstration window. This is reason for error: .modal.fade .modal-dialog {
-webkit-transition: -webkit-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
-webkit-transform: translate(0, -25%);
-ms-transform: translate(0, -25%);
-o-transform: translate(0, -25%);
transform: translate(0, -25%);
}
.modal.in .modal-dialog {
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
-o-transform: translate(0, 0);
transform: translate(0, 0);
} |
Those jsfiddles worked for me. What browser are you using? I tested on Safari, Firefox and Chrome, and in all of them your two jsfiddles worked. I even tried resizing the windows and everything was okay with both the chart and that modal example. |
OS X Chrome and Firefox good: http://awesomescreenshot.com/0845wb86a8 |
Okay, I saw it. Will take a look at it later. |
element with a translation, if it exists.
Thanks, I made an even better fix because of what you said. This one now will probably work in all cases. Your example is working now. I can't find any more problems with this PR, have everyone's problems been solved? |
Again, all checks have passed in my machine, this is a problem with the travis environment. |
Cool, will look at some PRS tonight. |
Applied this PR on my project and it works fine. It would be good to have nvd3 1.8.4 with this fix. |
break; | ||
} | ||
|
||
obj = obj.parentNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always going to walk up the whole object tree every time it adjusts the tooltip position... which is a lot... What was getBoundingClientRect().top and left doing that was wrong exactly? From what I can tell it is supposed to take translate into account, there's even a bugzilla bug about it that they fixed at one point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is always going to walk the object tree, but it will stop in the case of
a translation. The problem is that if there is a parent that has a css
translation, the fixed positioning of children will be based on the
position of this parent, not the screen. And as d3.event.client* is based
on the position of the screen, it has to take into account the translation
of this parent. The complexity of walking up the tree is not good, I agree.
I had a good idea. We can just look at the parent of the tooltip, and if
it doesn't have a translation property, we add a translate(0,0). We would
only have to take into account the immediate parent of the tooltip and it
would always work.
I'll do this later today, thanks for the good idea @liquidpele.
Em Qui, 26 de mai de 2016 11:23 AM, liquidpele notifications@github.com
escreveu:
In src/tooltip.js
#1674 (comment):
\* If a parent of the container has a translate transformation, fix the
\* positioning. The fixed position of the tooltip will be based starting
\* at this element.
*/
- var fixTranslation = function(pos) {
var obj = chartContainer;
while(obj && obj.style) {
if(getComputedStyle(obj).transform != 'none') {
var rect = obj.getBoundingClientRect();
pos.left -= rect.left;
pos.top -= rect.top;
break;
}
obj = obj.parentNode;
This is always going to walk up the whole object tree every time it
adjusts the tooltip position... which is a lot... What was
getBoundingClientRect().top and left doing that was wrong exactly? From
what I can tell it is supposed to take translate into account, there's even
a bugzilla bug about it that they fixed at one point.—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/novus/nvd3/pull/1674/files/7aef28714acf8368a01264f36ea7f6d6db95c912#r64754094
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A less invasive approach would be to put the nvd3 chart and the tooltip
inside a new div, and add a translate(0,0) to the new div. This would
ensure that adding the additional translation wouldn't break the rest of
the code of the user that depends on fixed positioning.
What do you think?
Em Qui, 26 de mai de 2016 12:04 PM, Renato Utsch renatoutsch@gmail.com
escreveu:
It is always going to walk the object tree, but it will stop in the case
of a translation. The problem is that if there is a parent that has a css
translation, the fixed positioning of children will be based on the
position of this parent, not the screen. And as d3.event.client* is based
on the position of the screen, it has to take into account the translation
of this parent. The complexity of walking up the tree is not good, I agree.I had a good idea. We can just look at the parent of the tooltip, and if
it doesn't have a translation property, we add a translate(0,0). We would
only have to take into account the immediate parent of the tooltip and it
would always work.I'll do this later today, thanks for the good idea @liquidpele.
Em Qui, 26 de mai de 2016 11:23 AM, liquidpele notifications@github.com
escreveu:In src/tooltip.js
#1674 (comment):
\* If a parent of the container has a translate transformation, fix the
\* positioning. The fixed position of the tooltip will be based starting
\* at this element.
*/
- var fixTranslation = function(pos) {
var obj = chartContainer;
while(obj && obj.style) {
if(getComputedStyle(obj).transform != 'none') {
var rect = obj.getBoundingClientRect();
pos.left -= rect.left;
pos.top -= rect.top;
break;
}
obj = obj.parentNode;
This is always going to walk up the whole object tree every time it
adjusts the tooltip position... which is a lot... What was
getBoundingClientRect().top and left doing that was wrong exactly? From
what I can tell it is supposed to take translate into account, there's even
a bugzilla bug about it that they fixed at one point.—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/novus/nvd3/pull/1674/files/7aef28714acf8368a01264f36ea7f6d6db95c912#r64754094
Turn off CSS transforms for the time being, with a cost of painting speed. Issue is currently being looked at on the nvd3 repo PR: novus/nvd3#1674
From what I've researched, we have only two choices to avoid having to walk up the DOM tree:
I personally prefer the 2nd choice. First, it won't break any user code (except code that called chartContainer()? But I don't see a good use for changing it except for internal nvd3 code). Second, NVD3 originally worked like that, with the tooltip directly inside document.body, so we'll just be regressing to the original behavior (but much better now, the old code was a mess). I'll implement the 2nd choice and update this PR. Anybody against it? @liquidpele? |
I prefer putting tooltip into document.body. Many similar things(popup, modals, etc.) in other js-libs work this way. |
* Use react-grid-layout instead of gridster * visualizations show and resize * display slice name and description; links work * positioning of widgets to match gridster, rowHeight matches * Change margins, rowHeight, unpositioned viz, and expandedSlices to match gridster * Saving dashboard, deleting slices, formatting on slices (chart control and resize handle), expanded slices fixed. * responsiveness + use es6 classes * Minor ui fixes + linting * CSS transforms on slices messes up nvd3 tooltip positioning. Turn off CSS transforms for the time being, with a cost of painting speed. Issue is currently being looked at on the nvd3 repo PR: novus/nvd3#1674 * Remove breakpoint listener, fires when it shouldn't (i.e. too often) * resize is no longer buggy, minor cleanup * gridster class, const, landscape error * one source of data for data to front end from python
Done. Now the tooltip is directly into document.body. All the tests passed in my machine. The performance is not a problem anymore @liquidpele. |
Awesome, good job! |
Maybe a new 1.8.4 release would be good now, to finally put an end to all these tooltip-related bugs =) |
FIxes #1532.
This fix corrects the position of the tooltip based on the translate property of the parents.
https://jsfiddle.net/genhmq3v/1/