novus / nvd3

A reusable charting library written in d3.js
http://nvd3.org/
Other
7.22k stars 2.15k forks source link

Tooltips: nvtooltip-pending-removal div is not removed on multiBarChart #771

Closed robinfhu closed 9 years ago

robinfhu commented 9 years ago

On the development branch, when I open the file examples/multiBarChart.html, I mouse over the chart and I see the following:

screen shot 2015-02-10 at 3 24 23 pm

When I inspect the DOM, there are lots of divs with 'nvtooltip-pending-removal' classed to them.

robinfhu commented 9 years ago

@petersondrew can you please take a look?

RenatoUtsch commented 9 years ago

I know that the bar charts use the old tooltip code, not the code that is used by the charts with interactive guideline (like the line chart).

petersondrew commented 9 years ago

Hmm, I'll take a look when I get into the office tomorrow.

robinfhu commented 9 years ago

Thanks. This is happening for pretty much any chart with the regular hover tooltip.

petersondrew commented 9 years ago

Alright, either I'm going crazy, or we're not comparing apples to apples. I just synced roadranger/nvd3/development with novus/nvd3/development, and when I open the multiBarChartTest.html under test I do not get this behavior at all, on chrome, ff, or IE11.

What browser are you testing in? Do you have any local changes, particularly with the nvd3 css file, that may be contributing?

petersondrew commented 9 years ago

Just in case it's somehow relevant, I appear to be on d3 3.5.4 locally.

robinfhu commented 9 years ago

@petersondrew , is it possible you have changes in roadranger/nvd3/development that were not merged in to our branch? You may have a different environment.

petersondrew commented 9 years ago

I don't believe so. I forked to roadranger/nvd3 yesterday and only committed the changes for #765. This morning I did a pull request from novus/nvd3 to sync my development branch with upstream.

I'm going to pull novus/nvd3 down as well and test there.

petersondrew commented 9 years ago

@robinfhu I just pulled novus/nvd3 and on development branch I do not see any problems with the tooltips on the multibarchart.html page. I tried under /examples and /test.

Can you please clone development into a clean folder, do a bower install, and see if you see the same issues?

robinfhu commented 9 years ago

@petersondrew , the reason is because you need to run 'grunt' once before loading the test pages.

Grunt creates build/nv.d3.js. In development, we don't checkin changes to that file, so you are using an older version of that.

petersondrew commented 9 years ago

Yeah, sorry. I just noticed that. I thought it would have been updated after 1.7.1.

petersondrew commented 9 years ago

@robinfhu I found the problem. The default task for grunt does not copy css. Try grunt production and it will copy nv.d3.css over to build/, which has the proper css for nvtooltip-pending-removal.

We really should remove build from the repo and add it to the.gitignore to avoid all this confusion.

RenatoUtsch commented 9 years ago

Wait, this is very important. Grunt needs to copy the css when doing its default task.

robinfhu commented 9 years ago

Yeah I'll change the grunt file

robinfhu commented 9 years ago

Good catch.

RenatoUtsch commented 9 years ago

I am copying the CSS but I don't see the div being removed...

robinfhu commented 9 years ago

@RenatoUtsch check again, this should work on development branch. Run 'grunt' before opening examples/multiBarChart

RenatoUtsch commented 9 years ago

@robinfhu I did it, and I am on the development branch.

Try checking out a clean copy and doing that.

I am using Chrome and OS X Yosemite.

robinfhu commented 9 years ago

@RenatoUtsch I can't reproduce your issue. Please upload a copy of your nv.d3.js and CSS file to JS fiddle and post it. Thanks.

robinfhu commented 9 years ago

Hold on, I see what you are saying. You need to be more specific. Do you mean that the actual DIVs are not being remove from the page (they are just set to opacity 0) screen shot 2015-02-19 at 9 08 30 am

petersondrew commented 9 years ago

@robinfhu Ah, I see. So with the old style tooltips it doesn't re-use the container.

robinfhu commented 9 years ago

@petersondrew , I was confused. I thought @RenatoUtsch had the same visual issue above. What he REALLY meant is that the div element is just hidden, never physically removed.

robinfhu commented 9 years ago

@petersondrew sorry to bother you about this again, can you find a fix?

petersondrew commented 9 years ago

So, is it better to have a single "remove" method that just hides the div, and force the old tooltip code to re-use the container, or do we change the remove method so that it removes the div and introduce a new function that hides the re-usable container specifically for the interactive layer tooltips?

petersondrew commented 9 years ago

My gut is to improve the old tooltip code and re-use the container, but I haven't dug into it enough to know what ramifications that has on the API

robinfhu commented 9 years ago

@petersondrew do whatever you think is best :-)

petersondrew commented 9 years ago

I'll try to find time for it soon, unfortunately I'm absolutely swamped at the office right now on non web-dev related stuff.

robinfhu commented 9 years ago

@petersondrew thanks. I'd normally dive in and fix it myself, but my solution would be something like find all "pending removals" and just remove them. Since you updated this feature, you probably know of a better way.

liquidpele commented 9 years ago

Personally, I'd like to see the regular tooltip re-use the container as well so that we could make it not vanish and reappear, but glide along like highcharts: http://www.highcharts.com/demo/line-basic

robinfhu commented 9 years ago

I don't think we can, because some charts like 'scatterChart' show more than one tooltip at a time.

liquidpele commented 9 years ago

Are you referring to the little tooltips that show up on the x and y axis too?

robinfhu commented 9 years ago

Yeah. Also I think there are advantages to not creating a reusable container for tooltips. For example, you may want to show tooltips simultaneously in two different charts side by side.

liquidpele commented 9 years ago

Oh, are they shared across charts?? Yea, we should probably not do that...

robinfhu commented 9 years ago

Yeah I'm now concerned about the reusable interactiveGuideline tooltip container. In our software, we have situations where tooltips show up for two charts at the same time. Wonder if this change would break that...

petersondrew commented 9 years ago

@robinfhu Do you mean "this change" as in what we're discussing to address removing these leftover tooltip container divs, or referring to the original change I made to make the container re-usable? If the latter, the pending-removal class (which in hindsight I should have used a new name) is only applied to the div owned by the interactive layer, so multiple interactive layers on a page will not interfere with one another (it uses the element id which is pseudo-randomly generated if I recall correctly).

robinfhu commented 9 years ago

@petersondrew I am referring to the big change you made originally. So if I understand correctly, each chart's tooltip operates independently, so two charts can show tooltips at the same time?

petersondrew commented 9 years ago

That is correct, I modified the interactive layer to locate its tooltip container by id, which is randomly generated per interactive layer instance, rather than by class which was the old behavior.

Play around with it and let me know if it breaks your scenario, but it should just work. :smile:

robinfhu commented 9 years ago

@petersondrew thanks. Once this pending-removal bug is fixed I hope tooltips are in a good state.

RenatoUtsch commented 9 years ago

@robinfhu Sorry that I wasn't specific enough.

The DIVs used to be removed by the old nv.tooltip.cleanup() code, but after that big change @petersondrew made, the divs are now only hidden.

I am having a problem with this find by id thing. If, for example, the interactive guideline tooltips can't find the tooltip by ID, it creates a new one, resulting in the following:

screen shot 2015-02-19 at 1 12 31 pm

The old tooltip code has the same behaviour in this case, but it hides any other existing tooltip DIVs before showing a new one:

screen shot 2015-02-19 at 1 14 40 pm

robinfhu commented 9 years ago

@RenatoUtsch whoa, what do you have to do to get that first screenshot's situation?

RenatoUtsch commented 9 years ago

@robinfhu you have to put the chart inside a Shadow DOM: https://github.com/RenatoUtsch/polynvd3

petersondrew commented 9 years ago

@RenatoUtsch I think locating a div by its id is an acceptable practice. Any issues created by doing so when it comes to virtual/shadom dom is far beyond the scope of this issue (and would need to be addressed solely in your polynvd3 fork, rather than in nvd3).

I'm more than happy to come up with a good way to reuse tooltips outside of the interactive layer, so that we don't orphan tons of divs. However I don't think that abandoning the use of getElementById to support shadom dom, at the expense of the performance gains we've made, is a good idea.

liquidpele commented 9 years ago

Weren't we selecting them by class before? Why would that work in shadowdom and selecting by ID wouldn't?

RenatoUtsch commented 9 years ago

By making a small change in the selection by class I can make the selection look inside all shadow doms.

Because you can have the same ids in different shadow doms, this feature is not available when selecting by ID, as conflicts can arise.

I think the ideal would be for nvd3 to support its usage, as it is something that will be really popular in the future, but I can make changes on my fork only.

RenatoUtsch commented 9 years ago

Oh and yes, the selection used to be by class.

joshjordan commented 9 years ago

Does that imply that getElementById is basically useless when using a shadow DOM? That doesn't really seem like a reasonable requirement to place on a project.

Is there a better way to choose when PR which DOM to apply the id selector to?

On Fri, Feb 20, 2015, 10:10 AM Renato Utsch notifications@github.com wrote:

Oh and yes, the selection used to be by class.

— Reply to this email directly or view it on GitHub https://github.com/novus/nvd3/issues/771#issuecomment-75252956.

joshjordan commented 9 years ago

When or which*

On Fri, Feb 20, 2015, 10:14 AM josh.jordan@gmail.com josh.jordan@gmail.com wrote:

Does that imply that getElementById is basically useless when using a shadow DOM? That doesn't really seem like a reasonable requirement to place on a project.

Is there a better way to choose when PR which DOM to apply the id selector to?

On Fri, Feb 20, 2015, 10:10 AM Renato Utsch notifications@github.com wrote:

Oh and yes, the selection used to be by class.

— Reply to this email directly or view it on GitHub https://github.com/novus/nvd3/issues/771#issuecomment-75252956.

liquidpele commented 9 years ago

shadow dom doesn't really look like something worth supporting yet...

http://caniuse.com/#feat=shadowdom

RenatoUtsch commented 9 years ago

http://webcomponents.org/polyfills/

@joshjordan You can apply the ID selector inside each shadow DOM, but not through all of them.

robinfhu commented 9 years ago

@petersondrew any updates on the fix?