<?php
/**
 * @version		$Id: pie.php 143 2009-06-25 11:37:24Z 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;

JLoader::import('chart', JPATH_QUANTA.DS.'libraries');

/**
 * Scatter chart helper
 *
 * @package		TAOJ.Quanta
 * @subpackage	com_quanta
 */
class JChartPie extends JChart
{
	/**
	 * Initialise the chart
	 */
	function _initialise()
	{
		// Create an instance of the chart type.
		$pie = OFC_Chart::getInstance('Pie');
		$pie->set_label_colour('#333333');
		$pie->set_border = 5;

		// Initialise variables.
		$data		= array();
		$maxTotal	= 0;
		$pieTotal	= 0;

		// Loop through the items and find extrema.
		foreach ($this->_points as &$point)
		{
			$maxTotal += $point->y_max;
			$pieTotal += $point->y;
			$colour	= $point->params->get('chart-set_colour');
			$value	= new OFC_Charts_Pie_Value($point->y, $point->label ? $point->label : $point->title, $colour);
			array_push($data, $value);
		}
		if ($this->_params->get('chart-show_balance'))
		{
			$colour	= $this->_params->get('chart-balance_colour', '#ffffff');
			array_unshift($data, new OFC_Charts_Pie_Value($maxTotal - $pieTotal, '', $colour));
		}

		$title = new OFC_Elements_Title('Area Chart');

		$pie->set_start_angle(0);
		$pie->alpha		= 0.75;
		$pie->tip		= '#percent#';
		$pie->values	= $data;

		$this->_chart->add_element($pie);

		if ($v = $this->_params->get('chart-title')) {
			$this->_chart->set_title($v);
		}

		if ($v = $this->_params->get('chart-bgcolour')) {
			$this->_chart->set_bg_colour($v);
		}
	}
}
