<?php
/**
 * PHP Integration of Open Flash Chart
 *
 * @version		$Id: OFC_Charts_Pie.php 123 2009-06-19 08:57:39Z eddieajau $
 * @copyright	Copyright (C) 2008 John Glazebrook <open-flash-chart@teethgrinder.co.uk>
 * @license		GNU Lesser General Public License version 2.1 or later.
 * @link		http://teethgrinder.co.uk/open-flash-chart-2/
 */

defined('PATH_OFC') or die;

require_once PATH_OFC.'/Charts/OFC_Charts_Base.php';

/**
 * @package		OpenFlashCharts
 */
class OFC_Charts_Pie extends OFC_Charts_Base
{
	/**
	 * @var	string	The chart type.
	 */
	public $type = 'pie';

	public $alpha = 1;

	public $animate = array();

	public $values = null;

	public $tip = null;

	/**
	 * Constructor
	 */
	public function __construct()
	{
		parent::__construct();
	}

	// boolean
	public function add_animation($v)
	{
		if ($v Instanceof OFC_Charts_Animation) {
			$this->animate[] = $v;
		}
	}

	// real
	public function set_start_angle($angle)
	{
		$this->{'start-angle'} = $angle;
	}

	/**
	 * @param
	 */
	public function set_border($value)
	{
		$this->border = $value;
	}

	/**
	 * Set the colours array
	 *
	 * @param	array	An array of hex colours for the slices
	 */
	public function set_colours($value)
	{
		$this->colours = $value;
	}

	public function set_gradient_fill()
	{
		$this->{'gradient-fill'} = true;
	}

	public function set_label_colour($v)
	{
		$this->{'label-colour'} = $v;
	}

	/**
	 * Turn off the labels
	 */
	public function set_no_labels()
	{
		$this->{'no-labels'} = true;
	}

	public function on_click($event)
	{
		$this->{'no-click'} = $event;
	}
}

/**
 * @package		OpenFlashCharts
 */
class OFC_Charts_Pie_Value
{
	/**
	 * @var	number
	 */
	public $value = null;

	/**
	 * @var	string
	 */
	public $text = null;

	/**
	 * @var	string
	 */
	public $tip = null;

	/**
	 * Constructor
	 *
	 * @param	number	The integer or floating-point value
	 * @param	string	The label for the value
	 * @param	string	The hex colour for the label and slice
	 * @param	string	The tip for the slice
	 * @param	string	The onclick event for the slice
	 */
	public function __construct($value, $label = null, $colour = null, $tip = null, $onClick = null)
	{
		$this->value = (double) $value;
		if ($label !== null) {
			$this->label = $label;
		}
		if ($colour !== null) {
			$this->colour = $colour;
		}
		if ($tip !== null) {
			$this->tip = $tip;
		}
		if ($onClick !== null) {
			$this->{'on-click'}	= $onClick;
		}
	}

	/**
	 * @param	string	An hex colour.
	 */
	public function set_colour($value)
	{
		$this->colour = $value;
	}

	/**
	 * @param	string	The label text
	 */
	public function set_label($label, $label_colour = null, $font_size = null)
	{
		$this->label = $label;

		if ($label_colour !== null) {
			$this->{'label-colour'} = $label_colour;
		}

		if ($font_size !== null) {
			$this->{'font-size'} = $font_size;
		}
	}

	/**
	 * @param	string	An hex colour.
	 */
	public function set_label_colour($value)
	{
		$this->{'label-colour'} = $value;
	}

	/**
	 * @param	int	A font size for the label.
	 */
	public function set_label_font_size($value)
	{
		$this->{'font-size'} = $value;
	}

	/**
	 * @param	int	A font size for the label.
	 */
	public function set_on_click($value)
	{
		$this->{'on-click'} = $value;
	}

	/**
	 * @param	int	A font size for the label.
	 */
	public function set_tooltip($value)
	{
		$this->tip = $value;
	}
}

/**
 * @package		OpenFlashCharts
 */
abstract class OFC_Charts_Animation
{
	/**
	 * @var	string
	 */
	public $type = null;
}

/**
 * fade the pie slice from $alpha (pie set_alpha) to 100% opaque.
 */
class OFC_Charts_Animation_Fade extends OFC_Charts_Animation
{
	/**
	 * @var	string
	 */
	public $type = 'fade';
}

/**
 * Bounce the pie slice out a little
 */
class OFC_Charts_Animation_Bounce extends OFC_Charts_Animation
{
	/**
	 * @var	string
	 */
	public $type = 'bounce';

	/**
	 * @param	int $distance	The distance to bounce in pixels.
	 */
	public function __construct($distance)
	{
		$this->distance = (int) $distance;
	}
}
