-
Notifications
You must be signed in to change notification settings - Fork 41
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
Size of histogram is miscalculated, too big overflows it's parent #111
Comments
OK, another weird thing I can't yet explain: If I do a hard-refresh in the browser on a page that reproduces -- it stops reproducing the problem. If I load the page normally, it does reproduce the problem. Clearly has something to do with timing of the JS loads. |
Some more things I am remembering/discovering investigating the code. We use So we have some interesting code around here: https://github.com/projectblacklight/blacklight_range_limit/blob/master/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js#L129-L142 Which tries to:
(There might be a better way to do all this, but this is what the code has been doing for years). In my app, that container div eventually settles down to Later the container is only 201px, but the chart is already drawn. Not sure why the container is temporarily 1000px+ instead. This is definitely kind of hacky code; I wonder if there's an entirely better way to do all this code using modern browser possibilities, but it might be a pretty major rewrite. This gem could probably use a pretty major rewrite, but meanwhile I continue to investigate to see what i can do. |
OK, the code for sizing the chart fires in But they ALL can happen before CSS stylesheets are even loaded. There is no guarantee that the page layout is actually complete when the event fires. (refs https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event https://javascript.info/onload-ondomcontentloaded#readystate) So somehow, the event is firing when in some cases the div's don't really have their final size yet; they have a non-0 size for some reason, but have a size that equals the entire widht of the viewport. Later they will have the "right" size, but we don't wait long enough, and it's not entirely clear if there's any good way to wait long enough. Still don't understand exactly how this is possible, since my stylesheets are loaded in html head... but I guess the browser loads them (or at least applies them) async for some reason? This whole design is kind of problematic and fragile; but it's unclear how to fix it. Still looking for at least hacky fixes. |
My own app in which I'm reproducing the problem loads it's JS with I am not entirely sure if removing that makes problem go away; of course, we'd like to be able to do that. It looks like an ordinary |
OK, yes.
It's not entirely clear to me how to fix this or the best way to minimize it.
Any thoughts or feedback from anyone else welcome! |
And here's a really hacky workaround that works in my own local app, with no changes to blacklight_range_limit. We want to trigger a chart redraw on So we can send a fake So in my local code: window.addEventListener('load', function(event) {
$("#facet-year_facet_isim").trigger("shown.bs.collapse");
}); Seems to solve the problem for me, doesn't seem to cause any problems even with the facet has no pre-existing limit and begins collapsed. VERY HACKY. |
Thanks @jrochkind , I am going to try some of the workaround solutions you provided. |
Just confirming that @jrochkind hack works for us though we used |
The JS drawing the histogram need sto be told it's width/height. There is some JS code in blacklight_range_limit that tries to calculate what it should be based on how much space is available.
This is currently failing in some circumstances. And you get something like this:
For me, this happens whenever I am loading a page with an existing range limit applied, so it opens with that facet section starting out open. Clicking on the facet section header to close and then re-open the section -- actually triggers a recalculation/redisplay and corrects it's size.
For me, on MacOS Chrome, this is pretty reproducible. Pretty much every time I load a page with an existing facet limit, it happens. However, on the very same app, other people on other browser/platform combos sometimes don't see the problem.
@pmulak on Slack also independently observed the problem, and said it reproduced on Firefox Chrome. Here where I am, we have one Windows Chrome that does reproduce it, and one that doens't. I think it's not actually browser-specific, but just hard to reproduce for as of yet mysterious reasons.
Somehow at the point the JS code is trying to determine the on-screen layout space available for the chart, it is not succesfully getting the right value. I previously spent some time investigating and was not able to figure it out, it's some creaky code (that i probably wrote originally many years ago). But I am now going to spend more time, and will try to leave notes here.
The text was updated successfully, but these errors were encountered: