Skip to content

Instantly share code, notes, and snippets.

@artlung
Created March 8, 2011 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlung/860932 to your computer and use it in GitHub Desktop.
Save artlung/860932 to your computer and use it in GitHub Desktop.
Visualizing WebSanDiego Post Counts
<?php
// http://tech.groups.yahoo.com/group/websandiego/
$string = <<<END
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2011 14 0 0
2010 30 8 17 0 14 16 7 2 12 3 6 4
2009 17 12 17 20 15 11 1 22 2 8 9 0
2008 34 38 16 41 34 22 37 43 32 28 6 17
2007 41 61 68 20 19 33 5 27 28 38 41 22
2006 82 113 92 71 98 80 68 65 64 125 36 24
2005 186 114 116 196 138 98 182 152 137 103 112 95
2004 422 344 447 296 194 419 417 303 133 128 191 116
2003 471 323 436 222 412 347 506 351 327 307 172 193
2002 553 545 471 483 442 375 389 529 456 531 245 189
2001 691 530 635 726 846 835 707 736 448 495 391 437
2000 310 416 303 360 699 595 600 590 305 418 406 238
1999 0 0 58 124 51 131 121 203 101 202 385 239
END;
$data = explode("\n", $string);
$structured = array();
foreach($data as $row) {
$structured[] = explode("\t", $row);
}
$websandiego = array();
foreach($structured as $row) {
$year = array_shift($row);
// print $year;
if ((int)$year > 1998) {
$websandiego[$year] = $row;
}
}
ksort($websandiego);
print "<ul>";
foreach($websandiego as $year => $months) {
$total_for_year = array_sum($months);
$total_for_year_width = (int)($total_for_year / 12);
print "<li><div class=\"year\">{$year}</div><!-- ({$total_for_year} posts total)--->";
// print "<div style=\"width: {$total_for_year_width}px;background-color: #ccc;color:#0c0;height:30px;overflow:hidden;\"></div>";
// print "<div class=\"total\">{$year} ({$total_for_year} posts total)</div>";
$monthnumber = 1;
foreach ($months as $month){
$width = (int)$month;
$monthcode = ($year * 100) + $monthnumber;
// print $monthcode;
// left the list in september 2007
if ($monthcode >= 200709) {
$color = "#666";
// moved away from san diego dec/jan 2005
} else if ($monthcode >= 200501) {
$color = 'yellow';
} else {
$color = '#0c0';
}
// January 2005, moved away from san diego
// September 7, 2007, left websandiego
print "<div style=\"width: {$width}px;background-color: {$color};color:{$color};height:2px;overflow:hidden;position:relative;left:0px;border-bottom:1px solid #fff\" title=\"{$month} {$monthcode}\">&nbsp;</div>";
$monthnumber++;
}
print "</li>";
}
print "</ul>";
?>
<style type="text/css">
ul {
/* -webkit-transform: rotate(-90deg);*/
}
.year {
width: 70px;
background-color: #999;
color: #fff;
float: left;
height: 35px;
border-radius: 4px;
margin: 0 2px 1px 0;
text-align: center;
vertical-align: center;
line-height: 35px;
text-shadow: 2px 1px 1px #666;
font-weight: bold;
}
body {
font-family: 'helvetica neue', sans-serif;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment