[RFC] Poll results bar relative width

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

[RFC] Poll results bar relative width

Post by PayBas »

Currently, the bars indicating the results of a poll represent the width as an absolute percentage. The result is that when there are multiple poll options that all get about the same amount of votes, the result bars tend to get really short, and not very descriptive. I suggest making the "winning" poll bar 100%, and all other widths relative to it. This is much more esthetically pleasing if you ask me, because it really gives users something to look at. Additionally, I add a "winner" class to the winning poll bar, so it's easier to style it in a special way.

I have already been using this for a long time, using a Javascript method in the footer, but I thought it might be interesting to others (and perhaps inclusion into the core some day).

Code: Select all

<!-- IF S_HAS_POLL and S_DISPLAY_RESULTS -->
var maxperc = 0;
$("dd.poll_option_percent").each(function() {
	var perc = parseFloat($(this).html());
	maxperc = ( perc > maxperc ? perc : maxperc );
})
if (maxperc !== 0) {
	$("fieldset.polls > dl").each(function() {
		if($(this).is("[data-poll-option-id]")) {
			var perc = parseFloat($("dd.poll_option_percent", this).html());
			if (perc == maxperc) {
				$(this).addClass("winner");
			}
			perc = Math.round(perc / maxperc * 100);
			$("dd.resultbar > div", this).css("width", perc+"%");
		}
	})
}
<!-- ENDIF -->
poll.png
(29.89 KiB) Downloaded 713 times

User avatar
M.Gaetan89
Registered User
Posts: 64
Joined: Tue Jan 28, 2014 7:17 pm
Location: Divonne-les-Bains, France
Contact:

Re: [RFC] Poll results bar relative width

Post by M.Gaetan89 »

I like the idea.
Currently the bars width is calculated zith PHP (variable {poll_option.POLL_OPTION_PERCENT} in the template) and I think we should keep the logic there, not adding JS to do this.

User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

Re: [RFC] Poll results bar relative width

Post by PayBas »

M.Gaetan89 wrote:I like the idea.
Currently the bars width is calculated zith PHP (variable {poll_option.POLL_OPTION_PERCENT} in the template) and I think we should keep the logic there, not adding JS to do this.
Of course I agree, sorry if I wasn't clear ;). A PHP solution would be much better.

I just posted this as a proof-of-concept.

User avatar
Mess
Registered User
Posts: 199
Joined: Wed Jun 13, 2012 10:14 am

Re: [RFC] Poll results bar relative width

Post by Mess »

Good idea. I like it.


Post Reply