<?php
/**
 * @version		$Id: chart.php 135 2009-06-25 04:32:04Z eddieajau $
 * @copyright	Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
 * @license		GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
 * @link		http://www.theartofjoomla.com
 */

// no direct access
defined('_JEXEC') or die;

/**
 * Chart object
 *
 * @package		TAOJ.Quanta
 * @subpackage	com_quanta
 */
abstract class JChart extends JObject
{
	/**
	 * @var	object
	 */
	protected $_chart = null;

	/**
	 * @var array
	 */
	protected $_sets = null;

	/**
	 * @var array
	 */
	protected $_points = null;

	/**
	 * @var object
	 */
	protected $_params = null;

	/**
	 * @var	string
	 */
	protected $_subtype = null;

	/**
	 * @var array
	 */
	protected $_subtypes = array();

	/**
	 * @var boolean
	 */
	protected $_debug = false;

	/**
	 * Constructor
	 *
	 * @param	array	$points
	 * @param	object	$params
	 * @param	array	$sets
	 */
	function __construct(&$points, &$params, &$sets = null)
	{
		// Require the Open Flash Charts main file.
		if (!class_exists('OFC_Chart')) {
			JLoader::import('OFC.OFC_Chart', JPATH_QUANTA.DS.'libraries');
		}

		$this->_sets	= &$sets;
		$this->_points	= &$points;
		$this->_params	= &$params;

		$this->_chart	= new OFC_Chart();
		$this->_debug	= $this->_params->get('debug');
	}

	/**
	 * Checks whether the chart sub-type is valid and sets if so.
	 *
	 * @param	string	The desired subtype.
	 *
	 * @return	mixed	The value passed to the method if available, null otherwise.
	 */
	public function setSubType($value)
	{
		if (!empty($this->_subtypes) && in_array(strtolower($value), $this->_subtypes)) {
			$this->_subtype = $value;
		}
	}

	/**
	 * Initialises the graph.
	 */
	abstract protected function _initialise();

	/**
	 *
	 */
	public function __toString()
	{
		$this->_initialise();

		return (string) $this->_chart;
	}

	/**
	 * Configures the X-Axis of the chart
	 */
	protected function _setXAxis()
	{
		// X-Legend
		if ($title = $this->_params->get('chart-x_title'))
		{
			$legend = new OFC_Elements_Legend_X($title);
			$legend->set_style('{font-size: 14px; color: #000000;}');
			$this->_chart->set_x_legend($legend);
		}
	}

	/**
	 * Configures the Y-Axis of the chart
	 */
	protected function _setYAxis()
	{
		// Y-Legend
		if ($title = $this->_params->get('chart-y_title'))
		{
			$legend = new OFC_Elements_Legend_Y($title);
			$legend->set_style('{font-size: 14px; color: #000000;}');
			$this->_chart->set_y_legend($legend);
		}
	}
}
