# HG changeset patch # User Dan # Date 1198039543 18000 # Node ID a82133ce2d7620e057562ce073c0215de2d675b1 # Parent 5f1cd51bf1be985e73697bb76d81864457a6f3f3 A number of updates to the graphing code (it should actually work now) diff -r 5f1cd51bf1be -r a82133ce2d76 includes/graphs.php --- a/includes/graphs.php Tue Dec 18 23:44:55 2007 -0500 +++ b/includes/graphs.php Tue Dec 18 23:45:43 2007 -0500 @@ -2,7 +2,7 @@ /* * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between - * Version 1.0.3 (Dyrad) + * Version 1.1.1 * Copyright (C) 2006-2007 Dan Fuhry * * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License @@ -740,198 +740,310 @@ // Graph Generator for PHP // Originally located at http://szewo.com/php/graph, but link was broken, so this file was retrieved from: // http://web.archive.org/web/20030130065944/szewo.com/php/graph/graph.class.php3.txt -// License unknown +// License unknown, however sources on the web have shown this to be either GPL or public domain. class GraphMaker_compat { - var $_values; - var $_ShowLabels; - var $_ShowCounts; - var $_ShowCountsMode; + var $_values; + var $_ShowLabels; + var $_ShowCounts; + var $_ShowCountsMode; - var $_BarWidth; - var $_GraphWidth; - var $_BarImg; - var $_BarBorderWidth; - var $_BarBorderColor; - var $_RowSortMode; - var $_TDClassHead; - var $_TDClassLabel; - var $_TDClassCount; - var $_GraphTitle; + var $_BarWidth; + var $_GraphWidth; + var $_BarImg; + var $_BarBorderWidth; + var $_BarBorderColor; + var $_BarBackgroundColor; + var $_RowSortMode; + var $_TDClassHead; + var $_TDClassLabel; + var $_TDClassCount; + var $_GraphTitle; - function __construct() { - $this->_values = array(); - $this->_ShowLabels = true; - $this->_BarWidth = 16; - $this->_GraphWidth = 360; - $this->_BarImg = "NULL"; - $this->_BarBorderWidth = 0; - $this->_BarBorderColor = "red"; - $this->_ShowCountsMode = 2; - $this->_RowSortMode = 1; - $this->_TDClassHead = "grphh"; - $this->_TDClassLabel = "grph"; - $this->_TDClassCount = "grphc"; - $this->_GraphTitle="Graph title"; - } - - function GraphMaker_compat() { - $this->__construct(); - } + function __construct() { + $this->_values = array(); + $this->_ShowLabels = true; + $this->_BarWidth = 32; + $this->_GraphWidth = 360; + $this->_BarImg = scriptPath . "/images/graphbit.png"; + $this->_BarBorderWidth = 0; + $this->_BarBorderColor = "red"; + $this->_ShowCountsMode = 2; + $this->_RowSortMode = 1; + $this->_TDClassHead = "graph-title"; + $this->_TDClassLabel = "graph-label"; + $this->_TDClassCount = "graph-count"; + $this->_GraphTitle="Graph title"; + $this->_BarBackgroundColor = "#456798"; + } - function SetBarBorderWidth($width) { - $this->_BarBorderWidth = $width; - } - function SetBorderColor($color) { - $this->_BarBorderColor = $color; - } + function GraphMaker_compat() { + $this->__construct(); + } + + function SetBarBorderWidth($width) { + $this->_BarBorderWidth = $width; + } + function SetBorderColor($color) { + $this->_BarBorderColor = $color; + } + + function SetBarBackgroundColor($color) + { + $this->_BarBackgroundColor = $color; + } // mode = 1 labels asc, 2 label desc - function SetSortMode($mode) { - switch ($mode) { - case 1: - asort($this->_values); - break; - case 2: - arsort($this->_values); - break; - default: - break; - } + function SetSortMode($mode) { + switch ($mode) { + case 1: + asort($this->_values); + break; + case 2: + arsort($this->_values); + break; + default: + break; + } - } + } - function AddValue($labelName, $theValue) { - array_push($this->_values, array("label" => $labelName, "value" => $theValue)); + function AddValue($labelName, $theValue) { + array_push($this->_values, array("label" => $labelName, "value" => $theValue)); + } - } - function SetBarWidth($width) { - $this->_BarWidth = $width; - } - function SetBarImg($img) { - $this->_BarImg = $img; - } - function SetShowLabels($lables) { - $this->_ShowLabels = $labels; - } - function SetGraphWidth($width) { - $this->_GraphWidth = $width; - } - function SetGraphTitle($title) { - $this->_GraphTitle = $title; - } - //mode = percentage or counts - function SetShowCountsMode($mode) { - $this->_ShowCountsMode = $mode; - } - //mode = none(0) label(1) or count(2) - function SetRowSortMode($sortmode) { - $this->_RowSortMode = $sortmode; - } + function SetBarData($data) + { + foreach ( $data as $name => $value ) + { + $this->AddValue($name, $value); + } + } + function DrawGraph() + { + $this->BarGraphVert(); + } + function SetBarWidth($width) + { + $this->_BarWidth = $width; + } + function SetBarImg($img) + { + $this->_BarImg = $img; + } + function SetShowLabels($lables) + { + $this->_ShowLabels = $labels; + } + function SetGraphWidth($width) + { + $this->_GraphWidth = $width; + } + function SetGraphTitle($title) + { + $this->_GraphTitle = $title; + } + //mode = percentage or counts + function SetShowCountsMode($mode) + { + $this->_ShowCountsMode = $mode; + } + //mode = none(0) label(1) or count(2) + function SetRowSortMode($sortmode) + { + $this->_RowSortMode = $sortmode; + } + + function SetTDClassHead($class) + { + $this->_TDClassHead = $class; + } + function SetTDClassLabel($class) + { + $this->_TDClassLabel = $class; + } + function SetTDClassCount($class) + { + $this->_TDClassCount = $class; + } + function GetMaxVal() + { + $maxval = 0; + foreach ( $this->_values as $value ) + { + if ( $maxval < $value["value"] ) + { + $maxval = $value["value"]; + } + } + return $maxval; + } + function BarGraphVert() + { + $maxval = $this->GetMaxVal(); + foreach($this->_values as $value) + { + $sumval += $value["value"]; + } + + $this->SetSortMode($this->_RowSortMode); + + echo "\n\n
\n\n "; + + if ( strlen($this->_GraphTitle) > 0 ) + { + echo "\n \n \n "; + } + + echo "\n "; + $css_class = 'row1'; + + foreach($this->_values as $value) + { + $css_class = ( $css_class == 'row1' ) ? 'row3' : 'row1'; + echo " "; - foreach($this->_values as $value) { - echo ""; - } - echo ""; - } - - echo "
_values)."\" class=\"".$this->_TDClassHead."\">".$this->_GraphTitle."
\n "; + $width = $this->_BarWidth; + $height = ceil( $value["value"] * $this->_GraphWidth / $maxval ); + + echo "
_BarBackgroundColor}; border: ".$this->_BarBorderWidth."px solid ".$this->_BarBorderColor."\">\n "; + echo "
\n "; + + // echo "_BarImg."\" height=\"$width\" width=\"$height\" "; + // echo " style=\"border: ".$this->_BarBorderWidth."px solid ".$this->_BarBorderColor."\""; + // echo ">"; - function SetTDClassHead($class) { - $this->_TDClassHead = $class; - } - function SetTDClassLabel($class) { - $this->_TDClassLabel = $class; - } - function SetTDClassCount($class) { - $this->_TDClassCount = $class; - } - function GetMaxVal() { - $maxval = 0; - foreach($this->_values as $value) if($maxval<$value["value"]) $maxval = $value["value"]; - return $maxval; - } - function BarGraphVert() { - $maxval = $this->GetMaxVal(); - foreach($this->_values as $value) $sumval += $value["value"]; - $this->SetSortMode($this->_RowSortMode); - echo ""; - if (strlen($this->_GraphTitle)>0) echo ""; - echo ""; - foreach($this->_values as $value) { - echo ""; - } - echo ""; - if ($this->_ShowCountsMode>0) { - echo ""; - foreach($this->_values as $value) { - switch ($this->_ShowCountsMode) { - case 1: - $count = round(100*$value["value"]/$sumval)."%"; - break; - case 2: - $count = $value["value"]; - break; /* Exit the switch and the while. */ - default: - break; - } - echo ""; - } - echo ""; - } + echo "\n "; + } + echo "\n "; + if ( $this->_ShowCountsMode > 0 ) + { + $css_class = 'row1'; + echo "\n "; + foreach($this->_values as $value) + { + $css_class = ( $css_class == 'row1' ) ? 'row3' : 'row1'; + switch ($this->_ShowCountsMode) + { + case 1: + $count = round ( 100 * $value["value"] / $sumval ) . "%"; + break; + case 2: + $count = $value["value"]; + break; + default: + break; + } + echo " \n "; + } + echo "\n"; + } + + if ($this->_ShowLabels) + { + $css_class = 'row1'; + echo " \n "; + foreach($this->_values as $value) + { + $css_class = ( $css_class == 'row1' ) ? 'row3' : 'row1'; + echo " \n "; + } + echo "\n"; + } + + echo "
_TDClassHead."\">".$this->_GraphTitle."
"; - $height = $this->_BarWidth; - $width=ceil($value["value"]*$this->_GraphWidth/$maxval); - echo "
_BarBorderWidth."px solid ".$this->_BarBorderColor."\""; - echo ">"; - echo "
$count
_TDClassCount."\">$count
_TDClassLabel."\""; + echo ">".$value["label"]."
"; + } - if ($this->_ShowLabels) { - echo "
".$value["label"]."
"; - } + function BarGraphHoriz() + { + $maxval = $this->GetMaxVal(); + + foreach($this->_values as $value) + { + $sumval += $value["value"]; + } + + $this->SetSortMode($this->_RowSortMode); + + echo ""; + + if ( strlen($this->_GraphTitle) > 0 ) + { + echo ""; + } + foreach($this->_values as $value) + { + if ($this->_ShowLabels) + { + echo ""; + echo ""; + } + echo ""; + if ( $this->_ShowCountsMode > 0 ) + { + switch ($this->_ShowCountsMode) + { + case 1: + $count = round(100 * $value["value"] / $sumval )."%"; + break; + case 2: + $count = $value["value"]; + break; /* Exit the switch and the while. */ + default: + break; + } + echo ""; + } + echo ""; + } + echo "
_ShowCountsMode > 0 ) + { + echo " colspan=\"2\""; + } + echo " class=\"".$this->_TDClassHead."\">".$this->_GraphTitle."
_TDClassLabel."\""; + if ( $this->_ShowCountsMode > 0 ) + { + echo " colspan=\"2\""; + } + echo ">".$value["label"]."
_TDClassCount."\">$count"; + $height = $this->_BarWidth; + $width = ceil( $value["value"] * $this->_GraphWidth / $maxval ); + echo "
_BarBorderWidth."px solid ".$this->_BarBorderColor."\">\n "; + echo "
\n "; + //echo "_BarImg."\" height=$height width=$width "; + //echo " style=\"border: ".$this->_BarBorderWidth."px solid ".$this->_BarBorderColor."\""; + //echo ">"; + echo "
"; + } + /** + * Dummy functions for compatibility with the GD version of the class + */ + + function SetGraphPadding($a, $b, $c, $d) + { + return true; + } + function SetBarPadding($a) + { + return true; + } + function SetAxisStep($a) + { + return true; + } + function SetGraphBackgroundTransparent($r, $g, $b, $a) + { + return true; + } + function SetGraphTransparency($a) + { + return true; + } + function SetGraphAreaHeight($a) + { + return true; + } +} - - function BarGraphHoriz() { - $maxval = $this->GetMaxVal(); - foreach($this->_values as $value) $sumval += $value["value"]; - $this->SetSortMode($this->_RowSortMode); - echo ""; - if (strlen($this->_GraphTitle)>0) { - echo ""; - } - foreach($this->_values as $value) { - if ($this->_ShowLabels) { - echo ""; - echo ""; - } - echo ""; - if ($this->_ShowCountsMode>0) { - switch ($this->_ShowCountsMode) { - case 1: - $count = round(100*$value["value"]/$sumval)."%"; - break; - case 2: - $count = $value["value"]; - break; /* Exit the switch and the while. */ - default: - break; - } - echo ""; - } - echo ""; - } - echo "
_ShowCountsMode>0) echo " colspan=2"; - echo " class=\"".$this->_TDClassHead."\">".$this->_GraphTitle."
".$value["label"]."
$count"; - $height = $this->_BarWidth; - $width=ceil($value["value"]*$this->_GraphWidth/$maxval); - echo "_BarImg."\" height=$height width=$width "; - echo " style=\"border: ".$this->_BarBorderWidth."px solid ".$this->_BarBorderColor."\""; - echo ">"; - echo "
"; - } -} -