diff -r 474f8be55943 -r ab66d6d1f1f4 includes/graphs.php --- a/includes/graphs.php Fri Dec 07 18:47:37 2007 -0500 +++ b/includes/graphs.php Wed Dec 19 22:55:40 2007 -0500 @@ -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 "
"; - } -} -