From: Brion Vibber Date: Wed, 9 Mar 2011 00:04:32 +0000 (-0800) Subject: quickie bar chart for poll results X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=921eb1eb23043d090655b94fa5a7cc7575b81815;p=quix0rs-gnu-social.git quickie bar chart for poll results --- diff --git a/plugins/Poll/poll.css b/plugins/Poll/poll.css new file mode 100644 index 0000000000..5ba9c1588f --- /dev/null +++ b/plugins/Poll/poll.css @@ -0,0 +1,10 @@ +.poll-block { + float: left; + height: 16px; + background: #8aa; + margin-right: 8px; +} + +.poll-winner { + background: #4af; +} diff --git a/plugins/Poll/pollresultform.php b/plugins/Poll/pollresultform.php index 1db86938fc..f4da10cb53 100644 --- a/plugins/Poll/pollresultform.php +++ b/plugins/Poll/pollresultform.php @@ -109,14 +109,33 @@ class PollResultForm extends Form $out = $this->out; $counts = $poll->countResponses(); + $width = 200; + $max = max($counts); + if ($max == 0) { + $max = 1; // quick hack :D + } + $out->element('p', 'poll-question', $poll->question); - $out->elementStart('ul', 'poll-options'); + $out->elementStart('table', 'poll-results'); foreach ($poll->getOptions() as $i => $opt) { - $out->elementStart('li'); - $out->text($counts[$i] . ' ' . $opt); - $out->elementEnd('li'); + $w = intval($counts[$i] * $width / $max) + 1; + + $out->elementStart('tr'); + + $out->elementStart('td'); + $out->text($opt); + $out->elementEnd('td'); + + $out->elementStart('td'); + $out->element('span', array('class' => 'poll-block', + 'style' => "width: {$w}px"), + "\xc2\xa0"); // nbsp + $out->text($counts[$i]); + $out->elementEnd('td'); + + $out->elementEnd('tr'); } - $out->elementEnd('ul'); + $out->elementEnd('table'); } /**