Location: PHPKode > scripts > phpchartPlus > phpchartplus/Sources/phpchartPlus.php
<?php

/*
**************************************************
Class: phpchartPlus.php
**************************************************
Author: Tsiavos Chris <hide@address.com>
Date: October 2004
**************************************************/

/**
*Includes the ConfigParser class
*/
require_once("ConfigParser.php");

/**
*Includes the DataParser class
*/
require_once("DataParser.php");

/**
*Includes the BarChart class
*/
require_once("BarChart.php");

/**
*Includes the AreaChart class
*/
require_once("AreaChart.php");

/**
*Includes the LineChart class
*/
require_once("LineChart.php");

/**
*Includes the PieChart class
*/
require_once("PieChart.php");

/**
*Includes the ColorAllocator class
*/
require_once("ColorAllocator.php");

/**
*Includes the Font class
*/
require_once("Font.php");

class ImageSupport_Exception extends Exception {
	
	function ImageSupport_Exception($data) {
		Exception::__construct($data);
	}
	
}

class FontSupport_Exception extends Exception {

	function FontSupport_Exception($data) {
		Exception::__construct($data);
	}
	
}

/**
*Instanciates the appropriate Chart class
*Instanciates the appropriate Chart class(BarChart,LineChart,AreaChart,PieChart) and associates it with instances of
*ConfigParser,DataParser,Font and ColorAllocator classes
*/	 
final class phpchartPlus {
	
	public $Chart_;
	public $ConfigParser_;
	public $DataParser_;
	
	private $Font_;
	private $ColorAllocator_;
	
function __construct() {

	$this->ConfigParser_=new ConfigParser();
	$this->DataParser_=new DataParser();
	
	$this->ColorAllocator_=new ColorAllocator();
	$this->Font_=new Font();
}

/**
*Instanciates the appropriate Chart class
*@access public
*@return void
*/
public function get_Instance() {
	
	$this->get_php_im_support();
	$this->get_php_ft_support();
	
	switch($this->ConfigParser_->get_ChartType()) {
		
		case "Bar":
		$this->Chart_=new BarChart();
		break;
		
		case "Area":
		$this->Chart_=new AreaChart();
		break;
		
		case "Line":
		$this->Chart_=new LineChart();
		break;
		
		case "Pie":
		$this->Chart_=new PieChart();
	}

$this->Chart_->set_ConfigParser($this->ConfigParser_);
$this->Chart_->set_DataParser($this->DataParser_);

$this->Chart_->set_ColorAllocator($this->ColorAllocator_);
$this->Chart_->set_Font($this->Font_);
}

/**
*Verifies php's support for the selected image output type
*@access private
*@throws ImageSupport_Exception 
*@return void
*/
private function get_php_im_support() {

	switch($this->ConfigParser_->get_ImageOutputType()) {
		case "png":
			if (!function_exists("imagepng")) 
			throw new ImageSupport_Exception("phpChartPlus:No php support for png images.Reconfigure GD with PNG support enabled");
		break;
		case "gif":
			if (!function_exists("imagegif"))
			throw new ImageSupport_Exception("phpChartPlus: No php support for gif images.Reconfigure GD with GIF support enabled");
		break;
		case "jpeg":
			if (!function_exists("imagejpeg")) 
			throw new ImageSupport_Exception("phpchartPlus:No php support for jpeg images.Reconfigure GD with JPEG support enabled");
	}
}

/**
*Verifies php's support for FreeType2 Fonts
*@access private
*@throws FontSupport_Exception
*@return void
*/
private function get_php_ft_support() {
	if ($this->ConfigParser_->get_FontFileLocation()!=NULL) 
	{
		if (!function_exists("imagefttext"))
		throw new FontSupport_Exception("phpchartPlus:No php support for FreeType fonts.Reconfigure with 'with-freetype-dir=' directive enabled");
	}
}


}

?>
Return current item: phpchartPlus