quickie bar chart for poll results

This commit is contained in:
Brion Vibber 2011-03-08 16:04:32 -08:00
parent d990357be9
commit 921eb1eb23
2 changed files with 36 additions and 7 deletions

10
plugins/Poll/poll.css Normal file
View File

@ -0,0 +1,10 @@
.poll-block {
float: left;
height: 16px;
background: #8aa;
margin-right: 8px;
}
.poll-winner {
background: #4af;
}

View File

@ -109,14 +109,33 @@ class PollResultForm extends Form
$out = $this->out; $out = $this->out;
$counts = $poll->countResponses(); $counts = $poll->countResponses();
$out->element('p', 'poll-question', $poll->question); $width = 200;
$out->elementStart('ul', 'poll-options'); $max = max($counts);
foreach ($poll->getOptions() as $i => $opt) { if ($max == 0) {
$out->elementStart('li'); $max = 1; // quick hack :D
$out->text($counts[$i] . ' ' . $opt);
$out->elementEnd('li');
} }
$out->elementEnd('ul');
$out->element('p', 'poll-question', $poll->question);
$out->elementStart('table', 'poll-results');
foreach ($poll->getOptions() as $i => $opt) {
$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('table');
} }
/** /**