Revision history for BarGraph


Revision [19130]

Last edited on 2008-01-28 00:14:03 by DennyShimkoski [Modified links pointing to docs server]

No Differences

Revision [16865]

Edited on 2007-05-31 23:26:42 by DennyShimkoski [Reverted]
Additions:
$colspan = 2 + $show_numbers;
$div_bar = ($percent > 20) ? "$percent%</div>" : "</div> $percent%";
$div_bar = "<div style=\"width:{$width}px;$color\">  " . $div_bar;
}
else
$normal = 0;
$div_bar = '0%';
}
$color = !(empty($value['color'])) ? "background-color:{$value[color]}" : '';
$numbers = $show_numbers == true ? "<td class=\"n\" style=\"text-align:right\">$n/$total</td>" : '';
echo "\n<tr><th class=\"var\">{$value[label]}</th>$numbers<td class=\"n\">$div_bar</td></tr>";
}
echo '<tr><td style="height:1px;padding:0;margin:0;" colspan="' . ($colspan - 1) . "\"></td><td style=\"height:1px;padding:0;margin:0;width:{$this->width}px;\"></div></td></tr>";
echo "\n</table>";
}
}
}
?>
%%
Save the following code as ##actions/bargraph.php##
if (isset($vars['title']) && isset($vars['data']))
require_once('3rdparty/plugins/bar_graph.php');
$graph = new bar_graph($vars['title']);
if (isset($vars['total'])) $graph->total = $vars['total'];
$data = split(';', $vars['data']);
foreach ($data as $row)
$row = split(':', $row);
$color = isset($row[2]) ? $row[2] : '';
$graph->add($row[0], $row[1], $color);
}
$show_numbers = isset($vars['numbers']) && $vars['numbers'] == 'false' ? false : true;
$graph->show($show_numbers);
}
?>
%%
====The CSS====
%%(css)
.bar_graph {background-color: #eef; border: 1px solid #007; font-size: .9em}
.bar_graph th.title {color:#007; background-color: #ccf; border-style: solid; border-width: 1px; border-color: #eef #007 #007 #eef}
.bar_graph th, .bar_graph td {font-family: verdana, sans-serif; text-align:left;}
.bar_graph th.var {background-color:#ddf;border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n {font-size:10px;background-color:#ddf;border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n div {float:left; text-align:right; color:#333; background-color: #eee; border-style: solid; border-width: 1px; border-color: #fff #003 #003 #fff; padding-right: 5px;}
%%
Feel free to post any alternate styles you come up with.
====The Examples====
I used the data from InfoHandler to see what it would look like...
%%
{{bargraph title="Page Revisions by User" data="JsnX:124;DarTar:53;JavaWoman:5;WikkaInstaller:1" total="183"}}
{{bargraph title="Page Revisions by User" data="JsnX:124;DarTar:53;JavaWoman:5;WikkaInstaller:1" total="183" show_numbers="false"}}
{{bargraph title="Global Statistics" data="Hits:1/1:#aaf;Revisions:183/10193:#eee;Comments:96/2051:#cfc;Backlinks:50/5549:#fcc;Referrers:34294/67978:#ffc"}}
%%
====The Screenshot====
{{image alt="Screenshot of the BarGraph action's output" url="http://bytebrite.com/img/bg2ss.gif"}}
====Authors====
DennyShimkoski
----
CategoryUserContributions
Deletions:
$colspan = 2 $show_numbers;
$div_bar = ($percent > 20) ? "$percent%</div>" : "</div>


Revision [16663]

Edited on 2007-05-31 10:32:26 by AqmSwn [Reverted]
Additions:
$colspan = 2 $show_numbers;
$div_bar = ($percent > 20) ? "$percent%</div>" : "</div>
Deletions:
$colspan = 2 + $show_numbers;
$div_bar = ($percent > 20) ? "$percent%</div>" : "</div> $percent%";
$div_bar = "<div style=\"width:{$width}px;$color\">  " . $div_bar;
}
else
$normal = 0;
$div_bar = '0%';
}
$color = !(empty($value['color'])) ? "background-color:{$value[color]}" : '';
$numbers = $show_numbers == true ? "<td class=\"n\" style=\"text-align:right\">$n/$total</td>" : '';
echo "\n<tr><th class=\"var\">{$value[label]}</th>$numbers<td class=\"n\">$div_bar</td></tr>";
}
echo '<tr><td style="height:1px;padding:0;margin:0;" colspan="' . ($colspan - 1) . "\"></td><td style=\"height:1px;padding:0;margin:0;width:{$this->width}px;\"></div></td></tr>";
echo "\n</table>";
}
}
}
?>
%%
Save the following code as ##actions/bargraph.php##
if (isset($vars['title']) && isset($vars['data']))
require_once('3rdparty/plugins/bar_graph.php');
$graph = new bar_graph($vars['title']);
if (isset($vars['total'])) $graph->total = $vars['total'];
$data = split(';', $vars['data']);
foreach ($data as $row)
$row = split(':', $row);
$color = isset($row[2]) ? $row[2] : '';
$graph->add($row[0], $row[1], $color);
}
$show_numbers = isset($vars['numbers']) && $vars['numbers'] == 'false' ? false : true;
$graph->show($show_numbers);
}
?>
%%
====The CSS====
%%(css)
.bar_graph {background-color: #eef; border: 1px solid #007; font-size: .9em}
.bar_graph th.title {color:#007; background-color: #ccf; border-style: solid; border-width: 1px; border-color: #eef #007 #007 #eef}
.bar_graph th, .bar_graph td {font-family: verdana, sans-serif; text-align:left;}
.bar_graph th.var {background-color:#ddf;border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n {font-size:10px;background-color:#ddf;border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n div {float:left; text-align:right; color:#333; background-color: #eee; border-style: solid; border-width: 1px; border-color: #fff #003 #003 #fff; padding-right: 5px;}
%%
Feel free to post any alternate styles you come up with.
====The Examples====
I used the data from InfoHandler to see what it would look like...
%%
{{bargraph title="Page Revisions by User" data="JsnX:124;DarTar:53;JavaWoman:5;WikkaInstaller:1" total="183"}}
{{bargraph title="Page Revisions by User" data="JsnX:124;DarTar:53;JavaWoman:5;WikkaInstaller:1" total="183" show_numbers="false"}}
{{bargraph title="Global Statistics" data="Hits:1/1:#aaf;Revisions:183/10193:#eee;Comments:96/2051:#cfc;Backlinks:50/5549:#fcc;Referrers:34294/67978:#ffc"}}
%%
====The Screenshot====
{{image alt="Screenshot of the BarGraph action's output" url="http://bytebrite.com/img/bg2ss.gif"}}
====Authors====
DennyShimkoski
----
CategoryUserContributions


Revision [10831]

Edited on 2005-08-25 19:22:10 by DennyShimkoski [Reverted]
Additions:
>>**See also:**
~-PageStatsAction
>>=====A Simple HTML-Based Bar Graph=====
Deletions:
=====A Simple HTML-Based Bar Graph=====


Revision [10826]

Edited on 2005-08-25 18:32:34 by DennyShimkoski [Reverted]
Additions:
The following bar_graph class should be saved as ##3rdparty/plugins/bar_graph.php## --
/* Copyright (C) 2005 Denny Shimkoski (denny @ bytebrite DOT com)
$width = ceil($normal * $this->width);
$div_bar = ($percent > 20) ? "$percent%</div>" : "</div> $percent%";
$div_bar = "<div style=\"width:{$width}px;$color\">  " . $div_bar;
$normal = 0;
$div_bar = '0%';
echo "\n<tr><th class=\"var\">{$value[label]}</th>$numbers<td class=\"n\">$div_bar</td></tr>";
Save the following code as ##actions/bargraph.php##
require_once('3rdparty/plugins/bar_graph.php');
Deletions:
Save it as ##actions/bargraph.php##
/* Copyright (C) 2005 Denny Shimkoski
$div_close = ($percent > 20) ? "$percent%</div>" : "</div> $percent%";
$normal = 1;
$div_close = 'Error: division by zero (please set total)</div>';
$width = ceil($normal * $this->width);
echo "\n<tr><th class=\"var\">{$value[label]}</th>$numbers<td class=\"n\"><div style=\"width:{$width}px;$color\">  $div_close</td></tr>";


Revision [10667]

Edited on 2005-08-13 06:05:12 by DennyShimkoski [Fixed rounding error (changed ceil to round)]
Additions:
$percent = round($normal * 100, 2);
$div_close = ($percent > 20) ? "$percent%</div>" : "</div> $percent%";
Deletions:
$percent = ceil($normal * 100);
$div_close = ($percent > 15) ? "$percent%</div>" : "</div> $percent%";


Revision [10666]

Edited on 2005-08-13 05:58:28 by DennyShimkoski [Fixed rounding error (changed ceil to round)]
Additions:
The previous version of this action assumed the largest specified value was the 100% marker. This behavior has been removed in favor of explicitly setting a "total" value. This way 60% will actually look like 60%!
var $total;
function bar_graph($title = '', $total = 0, $width = 250, $class = 'bar_graph')
$this->total = $total;
function show($show_numbers = true)
$colspan = 2 + $show_numbers;
if (!empty($this->title)) echo "\n<tr><th class=\"title\" colspan=\"$colspan\">$this->title</th></tr>";
$total = $this->total;
if (strpos($value['n'], '/')) list($n, $total) = split('/', $value['n']); else $n = $value['n'];
if ($total)
$normal = $n / $total;
$percent = ceil($normal * 100);
$div_close = ($percent > 15) ? "$percent%</div>" : "</div> $percent%";
$normal = 1;
$div_close = 'Error: division by zero (please set total)</div>';
$color = !(empty($value['color'])) ? "background-color:{$value[color]}" : '';
$numbers = $show_numbers == true ? "<td class=\"n\" style=\"text-align:right\">$n/$total</td>" : '';
echo "\n<tr><th class=\"var\">{$value[label]}</th>$numbers<td class=\"n\"><div style=\"width:{$width}px;$color\">  $div_close</td></tr>";
echo '<tr><td style="height:1px;padding:0;margin:0;" colspan="' . ($colspan - 1) . "\"></td><td style=\"height:1px;padding:0;margin:0;width:{$this->width}px;\"></div></td></tr>";
if (isset($vars['total'])) $graph->total = $vars['total'];
$show_numbers = isset($vars['numbers']) && $vars['numbers'] == 'false' ? false : true;
$graph->show($show_numbers);
.bar_graph {background-color: #eef; border: 1px solid #007; font-size: .9em}
.bar_graph th.title {color:#007; background-color: #ccf; border-style: solid; border-width: 1px; border-color: #eef #007 #007 #eef}
.bar_graph th.var {background-color:#ddf;border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n {font-size:10px;background-color:#ddf;border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n div {float:left; text-align:right; color:#333; background-color: #eee; border-style: solid; border-width: 1px; border-color: #fff #003 #003 #fff; padding-right: 5px;}
Feel free to post any alternate styles you come up with.
I used the data from InfoHandler to see what it would look like...
{{bargraph title="Page Revisions by User" data="JsnX:124;DarTar:53;JavaWoman:5;WikkaInstaller:1" total="183"}}
{{bargraph title="Page Revisions by User" data="JsnX:124;DarTar:53;JavaWoman:5;WikkaInstaller:1" total="183" show_numbers="false"}}
{{bargraph title="Global Statistics" data="Hits:1/1:#aaf;Revisions:183/10193:#eee;Comments:96/2051:#cfc;Backlinks:50/5549:#fcc;Referrers:34294/67978:#ffc"}}
{{image alt="Screenshot of the BarGraph action's output" url="http://bytebrite.com/img/bg2ss.gif"}}
Deletions:
function bar_graph($title = '', $width = 250, $class = 'bar_graph')
function show($show_percentage = false)
$max = 0;
if (!empty($this->title)) echo "\n<tr><th class=\"title\" colspan=\"2\">$this->title</th></tr>";
foreach ($this->values as $value) $max = $value['n'] > $max ? $value['n'] : $max;
$normal = $value['n'] / $max;
$percent = ceil($normal * 100);
if ($percent > 15)
$div_close = ($show_percentage) ? "$percent%</div>" : $value['n'] . '</div>';
$div_close = ($show_percentage) ? "</div> $percent%" : '</div> ' . $value['n'];
$color = !(empty($value['color'])) ? "background-color:{$value['color']}" : '';
echo "\n<tr><th>{$value['label']}</th><td class=\"n\"><div style=\"width:{$width}px;$color\">  $div_close</td></tr>";
$show_percentage = isset($vars['percents']);
$graph->show($show_percentage);
.bar_graph {background-color: #eef; border: 1px solid darkblue; font-size: .9em}
.bar_graph th.title {color:#007; background-color: #dde; border-style: solid; border-width: 1px; border-color: #fff #aae #aae #fff}
.bar_graph td.n {font-size:10px;}
.bar_graph td.n div {float:left; text-align:right; color:#333; background-color: #669; border-style: solid; border-width: 1px; border-color: #fff #003 #003 #fff; padding-right: 5px;}
{{bargraph title="Some Variables" data="Variable 1:100:#aaf;Variable 2:16:#eee;Variable 3:146:#cfc"}}
{{bargraph title="Some Variables" data="Variable 1:100:#aaf;Variable 2:18:#eee;Variable 3:146:#cfc" percents="true"}}
{{image alt="Screenshot of the BarGraph action's output" url="http://bytebrite.com/img/bgss.gif"}}


Revision [10607]

Edited on 2005-08-11 02:15:39 by DennyShimkoski [Fixed rounding error (changed ceil to round)]
Additions:
/* Copyright (C) 2005 Denny Shimkoski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */


Revision [10543]

Edited on 2005-08-07 23:09:02 by NilsLindenberg [added info]
Additions:
Save it as ##actions/bargraph.php##


Revision [10536]

The oldest known version of this page was created on 2005-08-07 20:40:46 by DennyShimkoski [added info]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki