PDA

View Full Version : [RELEASE vB2.02beta] Bargraph thread rating


JWS
04 Mar 2001, 00:30
This hack will let you have a bargraph to show ratings of threads instead of stars. In addition, it doesn't round to whole numbers and the bargraph shows smaller increments as a result.

Here's a sample of what it looks like:

http://forums.maxima.org/bar_clip.gif

The gist of it is this: take the average rating value (say 2.45), round it off to 1 decimal of precision (i.e. 2.4) and multiply by 10 (to get "24"). Now the width of the bargraph is set to 24 pixels wide.

The image included as an attachment is a 1x6 image that stretches without getting distorted. You could make your own image or make variations of the image to get different results.

Basically, you need to change the following:

In forumdisplay.php around line 377, you'll see:


if ($foruminfo[allowratings]) {
if ($thread[votenum] >= $showvotes && $thread[votenum] != 0) {
$rating = intval(round($thread[voteavg]));
$thread[rating] = $rating . 'stars.gif';
} else {
$thread[rating] = 'clear.gif';
}

Change this to:

if ($foruminfo[allowratings]) {
if ($thread[votenum] >= $showvotes && $thread[votenum] != 0) {
$rating = round($thread[voteavg],1);
$bar_width = $rating * 10;
$thread[rating] = 'bar.gif';
} else {
$thread[rating] = 'clear.gif';
}

Then in the forumdisplaybit_threadrate template, add the following parameters to the SRC tag of the image:

width="$bar_width" height="6"

Hope this helps someone! It looks pretty neat!

04 Mar 2001, 00:52
Cool! I was going to change teh star*.gif's from stars to a bar of different lengths, i think i'll use your way, this way i can rate threads from 1-10 instead of 1-5 and the page will load faster, as it only loads one very small gif, not 10 big gifs! nice job :)

04 Mar 2001, 00:54
Glad you like it. Just keep in mind that you'll need to widen the <td> width of the column for the ratings if you go up to 10. Other than that, you should be good to go!

Originally posted by Joe
Cool! I was going to change teh star*.gif's from stars to a bar of different lengths, i think i'll use your way, this way i can rate threads from 1-10 instead of 1-5 and the page will load faster, as it only loads one very small gif, not 10 big gifs! nice job :)

04 Mar 2001, 00:58
Couldnt i just times the gif size by 5, instead of 10? :) Maybe i will stick to a 5 choice rating *shrug* i'll have to think about it .

04 Mar 2001, 01:03
No, because the "*10" gets the decimal into the ones place so that you can set the width. Doing it by 5 would just get you another decimal possibly and you can't set a width to a decimal place. :)

Just make sure that the table cell width coincides with how big you're making your bar and you'll be fine.

Originally posted by Joe
Couldnt i just times the gif size by 5, instead of 10? :) Maybe i will stick to a 5 choice rating *shrug* i'll have to think about it .

04 Mar 2001, 01:05
ahh, thanks ;) heh

04 Mar 2001, 01:11
thx man. great job

ThomasP
05 Aug 2001, 15:03
Thanks JWS,

works very well on 2.0.3.

It's around 451 in 2.0.3 and here are the slightly different changes:

Find:

if ($foruminfo[allowratings]) {
if ($thread[votenum] >= $showvotes) {
$rating = intval(round($thread[voteavg]));
$thread[rating] = $rating . 'stars.gif';
} else {
$thread[rating] = 'clear.gif';
}


Change to:

if ($foruminfo[allowratings]) {
if ($thread[votenum] >= $showvotes) {
$rating = round($thread[voteavg],1);
$bar_width = $rating * 10;
$thread[rating] = 'bar.gif';
} else {
$thread[rating] = 'clear.gif';
}


cu,
-Tom

JamesUS
05 Aug 2001, 17:20
Moved into the releases forum for you :)