]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
quickie bar chart for poll results
authorBrion Vibber <brion@pobox.com>
Wed, 9 Mar 2011 00:04:32 +0000 (16:04 -0800)
committerBrion Vibber <brion@pobox.com>
Wed, 9 Mar 2011 00:04:32 +0000 (16:04 -0800)
plugins/Poll/poll.css [new file with mode: 0644]
plugins/Poll/pollresultform.php

diff --git a/plugins/Poll/poll.css b/plugins/Poll/poll.css
new file mode 100644 (file)
index 0000000..5ba9c15
--- /dev/null
@@ -0,0 +1,10 @@
+.poll-block {
+    float: left;
+    height: 16px;
+    background: #8aa;
+    margin-right: 8px;
+}
+
+.poll-winner {
+    background: #4af;
+}
index 1db86938fcea6d991abced7d9c5e383e3d326579..f4da10cb535747a270f725446cddc646d5669db4 100644 (file)
@@ -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');
     }
 
     /**