Well, I've submitted a new version of statistics_trends which lets you display recent hits in a bar graph format. Looks great in Firefox - however, in Internet Explorer the bars never reach above a certain height. Any CSS experts out there who can help me figure out how to fix this?
Technical details: each bar consists of a DIV element named "bar" with a black background color, 50px high and 0.5em wide. The hits for the relevant period are displayed in a DIV named "foreground" (from the top down, so the exposed black part of the bar represents the relative hits) with a grey (#ddd) background-color and also a width of 0.5 em, and a dynamic height expressed in percentages (100 minus the percent hits relative to the maximum hits displayed). In IE, the grey bar is always displayed with a certain minimum height regardless of the percentage expressed (even if zero). I've experimented with every setting I can think of involving borders, margins, line-heights, font-sizes, etc. and I can't figure out how to make the black bar go above that height. If anyone can help me I'd appreciate it...
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | statistics_trends.css | 330 bytes | mikeryan |
Comments
Comment #1
Snurb commentedIt may just be me, but on viewing the page source I couldn't see the statistics_trends.css file getting imported anywhere - perhaps that's the problem ? I added the contents of the css file to my site-wide css file, and the bars showed up fine...
Comment #2
mikeryanNope, that's not it - actually, I see the import five times in <head> (I'll fix that for the next release so it only appears once). Removing the .css file just results in the bars not appearing at all.
Any other thoughts on why IE won't render the bar graphs correctly?
Thanks!
Comment #3
Snurb commentedUmm, re-reading this I think I understand what you mean now, but I'm still confused: from your description the grey part of the graph indicates the number of hits (i.e. size of the grey part is larger the larger the number of hits is), but on my site it shows up the other way around (the black part is larger the larger the number of hits is). Or am I misunderstanding you ?
And I think I see the problem you're describing now, too - the grey part at the top of graphs is never smaller than a certain minimum. Looking at it I'm wondering if this is to do with the font size, actually - perhaps the height of the div can never go below the current font size in case any text needs to be put in the div. I can't try this at the moment, but see if code like
<div style="height: 44%; font-size: 1px;" class="foreground">(or a font-size change to the foreground class in the css file) makes any difference ?
Axel Bruns (snurb.info)
Comment #4
Snurb commentedArgh. That was meant to be:
<div style="height: 44%; font-size: 1px;" class="foreground">Axel Bruns (snurb.info)
Comment #5
Snurb commentedGot it now ! As I thought, the reason for the bars never stretching to 100% length in IE is linked to the font size within the divs. Looks like even if the hits bar is meant to be at 100%, there's always still an empty space above it that inherits the height of the font which would be displayed within the divs (even though they're empty...).
Here's a fix - change the css to:
This renders properly in IE (check my site at snurb.info for example). Not sure about other browsers, though.
Technically, this still leaves a one pixel empty space at the top of bars, even if they're meant to be 100% in height, but I think that's the best we can hope for (setting the font-size to 0px doesn't work, which is probably fair enough :-). I've also had to change the width attribute for the bars to a point value, rather than measuring it in ems - the original value of 0.5em would equate to 0.5px now... Instead of the 5pt value I've chosen, you could go for 5em or something similar as well, I guess.
Hope this helps !
Axel Bruns (snurb.info)
Comment #6
Snurb commentedI really have to learn not to post before I'm done... Here's a further fix that deals with the width of the bars - we can just remove the width attribute from the css altogether, and the width of the bars will adjust itself to 100%/number of bars, which looks much nicer (see my site as an example). So:
The only thing I'm not sure about is why the rightmost bar of the 24 hour graph is wider than the other 23 - might be a calculation error in IE ?
Axel Bruns (snurb.info)
Comment #7
mikeryanThanks, I thought I had tried playing with font-size but obviously I hadn't... And thanks for the width observation. I've made a couple more CSS tweaks, to make the <th> center properly and to remove the spaces between bars (a matter of both taste and space - this makes it practical to, say, show the last 60 minutes in a sidebar).
I'm going to run with this live for a day or two before committing it, in case any more tweaks come to mind...
Thanks again!
Comment #8
mikeryanOh, as for the rightmost bar being a different width - this is true in Firefox too, but in that case it's narrower. I believe with the 100% width on the table, the layout priority is making the edges of the table go all the way across over making each column equally wide. Removing the padding between columns does tend to obscure the issue...
Comment #9
Snurb commentedExcellent - somehow the new css file seems to have fixed the unequal width problem for the bars...
One last suggestion: I liked having a small space between bars, to give them a little distance from one another - to make this really nice and small, I added the following to .statistics-trends .bar in the css:
(Again, you can see it in action on my site.)
Axel Bruns (snurb.info)
Comment #10
mikeryanI'm not sure which I like better, the separate bars or the block effect when bars coalesce, but I'll toss that one in as the default (easier for an inexperienced themer to take it out than to figure out how to add it in...). Thanks again!
Comment #11
mikeryanI've done some further refinement to the CSS (note: table-layout: fixed does wonders in terms of making the bar widths come out evenly), as well as implementing a new feature... You can now specify a target number of hits per day you'd like to see on your site, and a red line on each graph shows how you're performing against that target.
Reopen this issue if you see any additional basic layout issues - please open a new issue for other problems, particularly involving the new target feature.
Thanks!
Comment #12
(not verified) commentedComment #13
(not verified) commentedComment #14
(not verified) commentedComment #15
mikeryan