Skip to content
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

Merged
merged 4 commits into from
Jun 10, 2016
Merged

Conversation

RenatoUtsch
Copy link
Contributor

@RenatoUtsch RenatoUtsch commented May 22, 2016

FIxes #1532.

This fix corrects the position of the tooltip based on the translate property of the parents.

https://jsfiddle.net/genhmq3v/1/

@RenatoUtsch
Copy link
Contributor Author

RenatoUtsch commented May 22, 2016

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.

@workgena
Copy link

I have the same issue. And this PR does not solve my problem.

Also you have this commit
RenatoUtsch@f1754e3

In my case, this commit fixes issue with tooltip positioning.

@RenatoUtsch
Copy link
Contributor Author

RenatoUtsch commented May 24, 2016

@workgena the problem is that that commit breakes tooltip positioning in other cases.
Can you please create a jsfiddle to show your issue, so that I can work on it?

@workgena
Copy link

workgena commented May 25, 2016

Found strong dependence on bootstrap version.

Boostrap 2.3.1
http://jsfiddle.net/pL9sdgLu/1/

Boostrap 3.3.6
http://jsfiddle.net/bg5gsm2a/7/

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);
}

@RenatoUtsch
Copy link
Contributor Author

RenatoUtsch commented May 25, 2016

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.

@workgena
Copy link

workgena commented May 25, 2016

OS X Chrome and Firefox

good: http://awesomescreenshot.com/0845wb86a8
with error: http://awesomescreenshot.com/03e5wb7t2c

@RenatoUtsch
Copy link
Contributor Author

Okay, I saw it. Will take a look at it later.

@RenatoUtsch
Copy link
Contributor Author

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?

@RenatoUtsch
Copy link
Contributor Author

Again, all checks have passed in my machine, this is a problem with the travis environment.

@liquidpele

@liquidpele
Copy link
Contributor

Cool, will look at some PRS tonight.

@workgena
Copy link

Applied this PR on my project and it works fine.
Checked StackedArea and MultiBar charts.
Thx @RenatoUtsch

It would be good to have nvd3 1.8.4 with this fix.

break;
}

obj = obj.parentNode;
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

georgeke added a commit to georgeke/caravel that referenced this pull request Jun 1, 2016
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
@RenatoUtsch
Copy link
Contributor Author

RenatoUtsch commented Jun 2, 2016

From what I've researched, we have only two choices to avoid having to walk up the DOM tree:

  1. Add a 'translate(0,0)' to the tooltip parent if it doesn't have a translate transformation, so that we only need to look at it instead of the whole tree. The problem with this is that we're changing a div that we didn't create, and this can (and probably will) break user code.
  2. Make the tooltip div a direct child of document.body, so that we only have to look if the document.body has a transformation. The problem with this is that we're not putting the tooltip together with the SVG.

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?

@workgena
Copy link

workgena commented Jun 2, 2016

I prefer putting tooltip into document.body. Many similar things(popup, modals, etc.) in other js-libs work this way.

mistercrunch pushed a commit to apache/superset that referenced this pull request Jun 2, 2016
* 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
@RenatoUtsch
Copy link
Contributor Author

Done. Now the tooltip is directly into document.body. All the tests passed in my machine.

The performance is not a problem anymore @liquidpele.

@liquidpele
Copy link
Contributor

Awesome, good job!

@liquidpele liquidpele merged commit 9444bea into novus:master Jun 10, 2016
@RenatoUtsch
Copy link
Contributor Author

Maybe a new 1.8.4 release would be good now, to finally put an end to all these tooltip-related bugs =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltip Position Wrong when the chart is in a dialog
3 participants