From 921eb1eb23043d090655b94fa5a7cc7575b81815 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 8 Mar 2011 16:04:32 -0800 Subject: [PATCH] quickie bar chart for poll results --- plugins/Poll/poll.css | 10 ++++++++++ plugins/Poll/pollresultform.php | 29 ++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 plugins/Poll/poll.css 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'); } /** -- 2.39.5