Changeset - 0913b2b63e96
[Not reviewed]
default
0 2 2
Ethan Zonca - 15 years ago 2010-12-24 00:53:41
ez@ethanzonca.com
Added extremely alpha graphing code
4 files changed with 120 insertions and 0 deletions:
0 comments (0 inline, 0 general)
admin.php
Show inline comments
 
@@ -19,6 +19,7 @@
 
 */
 

	
 
  include_once 'inc/class.page.php';
 

	
 
  $scripts = array('jQuery','jQueryUI'); 
 
  $adminpage = new page('Administration',$scripts,FALSE);
 
  $datepicker = '$(function() {
 
@@ -141,6 +142,9 @@
 
  }
 
?>
 

	
 
<h3>Stats</h3>
 
<img src="statsGraph.php" />
 

	
 
<h3>Update</h3>
 
<p>You are currently running version <?php echo SP_PACKAGE_VERSION; ?>. The latest available release is VERSION.</p>
 

	
inc/class.graph.php
Show inline comments
 
new file 100644
 
<?php
 

	
 
class barGraph {
 

	
 
// This array of values is just here for the example.
 
private $values = array();
 
private $image = null;
 

	
 
// Pass me a multidimensional array with 'count', the size, and 'label', the label
 
public function __construct($userVals, $width=600, $height=300) {
 

	
 
  $this->values = $userVals;
 

	
 

	
 
  // Get the total number of columns we are going to plot
 
  $columns  = count($this->values);
 
  if($columns == 0) {
 
    throw new Exception("No input data!");
 
  }
 
  if($width < 5 || $height < 5) {
 
    throw new Exception("Image size too small!");
 
  }
 

	
 
  // Set the amount of space between each column
 
  $padding = 5; 
 

	
 
  // Get the width of 1 column
 
  $column_width = $width / $columns ;
 

	
 
  // Generate the image variables
 
  $im        = imagecreate($width,$height);
 
  $gray      = imagecolorallocate ($im,0xcc,0xcc,0xcc);
 
  $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
 
  $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
 
  $white     = imagecolorallocate ($im,0xff,0xff,0xff);
 
  $black     = imagecolorallocate($im, 0, 0, 0);
 
    
 
  // Fill in the background of the image
 
  imagefilledrectangle($im,0,0,$width,$height,$white);
 
    
 
  $maxv = 0;
 

	
 
  // Calculate the maximum value we are going to plot
 
  for($i=0;$i<$columns;$i++)
 
    $maxv = max($this->values[$i]['count'], $maxv);
 

	
 
  // Now plot each column 
 
  for($i=0;$i<$columns;$i++) {
 
    $column_height = ($height / 100) * (( $this->values[$i]['count'] / $maxv) *100);
 
    $x1 = $i*$column_width;
 
    $y1 = $height-$column_height;
 
    $x2 = (($i+1)*$column_width)-$padding;
 
    $y2 = $height;
 

	
 
    imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);
 

	
 
    $label = $this->values[$i]['label'];
 
    $font = '/usr/share/fonts/liberation/LiberationSans-Regular.ttf';
 
    imagettftext($im, 10, 0, $x1 + ($column_width / 2) - 20, $height - 5, $black, $font, $label);
 
 
 
  }
 

	
 
  // Send the PNG header information. Replace for JPEG or GIF or whatever
 
  $this->image = $im;
 

	
 
  header ("Content-type: image/png");
 
  imagepng($this->image);
 
}
 

	
 
}
 

	
 
?>
scripts/scheduleInput.js
Show inline comments
 
@@ -220,6 +220,7 @@ function addTips(id) {
 
      name: 'dark',
 
      tip: true
 
    },
 
    show: { effect: { type: 'fade', length: 2000 } },
 
/*    show: { ready: false }, */
 
/*    hide: { when: { event: 'inactive' } }, */
 
    corner: { target: 'topMiddle', tooltip: 'bottomMiddle' },
statsGraph.php
Show inline comments
 
new file 100644
 
<?php
 

	
 
  include_once 'inc/class.graph.php';
 

	
 
  // Make array of values
 
  $arr = array();
 

	
 
  // @TODO - pull in isBeforeDate from admin library, create isAfterDate (!isBeforeDate)
 

	
 
  $startDate = "0";
 
  $stopDate = "99999999999999999999";
 
  $dir = 'saved_schedules/';
 
  // Do this the new fun php5 OO-way
 
  foreach(new DirectoryIterator($dir) as $key => $file) {
 
    if(is_numeric($file->getFilename())){
 
      $uctime = $file->getCTime();
 
      $ctime = date("m/d/Y",$uctime);
 
      $ctime = strtotime($ctime); // Results in a day-specific unix timestamp
 

	
 
      if($ctime < $stopDate && $ctime > $startDate) {
 
        $currDate = $file->getCTime();
 
        if(!isset($arr[$currDate])) {
 
          $arr[$currDate] = 1;
 
        }
 
        else { 
 
          $arr[$currDate]++;
 
        }
 
      }
 
    }
 
  }
 

	
 
  $gphArr = array();
 
  $i = 0;
 
  foreach($arr as $index => $item) {
 
    $gphArr[$i]['count'] = $item;
 
    $gphArr[$i]['label'] = date("j/n", $index);
 
    $i++;
 
  }
 
//echo "<pre>";
 
//  print_r($gphArr); 
 
  // Graph array
 
  $myGraph = new barGraph($gphArr, 900, 100);
 
?>
0 comments (0 inline, 0 general)