111 lines
2.7 KiB
PHP
111 lines
2.7 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides access to HighCharts Chart Drawing
|
|
*
|
|
* @package HighChart
|
|
* @category Helper
|
|
* @author Deon George
|
|
* @copyright (c) 2012-2013 Deon George
|
|
* @license http://dev.leenooks.net/license.html
|
|
*/
|
|
abstract class HighChart {
|
|
protected $_series = array();
|
|
|
|
protected $_divname = 'hchart';
|
|
|
|
// Chart title
|
|
protected $_title = '';
|
|
|
|
// Default chart size.
|
|
protected $_height = '300';
|
|
protected $_width = '575';
|
|
protected $_ymetric = '';
|
|
|
|
// Colors to use for series
|
|
private $_series_colours = array('AAACCC','E0E0E0','CCC888','EEEBBB','666CCC','888888');
|
|
|
|
// Render the chart data in a json format
|
|
abstract public function json();
|
|
|
|
// Our child class should define how to render as a string
|
|
abstract public function render();
|
|
|
|
public function __call($name,$args) {
|
|
switch ($name) {
|
|
case 'div': $this->_divname = array_shift($args);
|
|
break;
|
|
case 'height': $this->_height = array_shift($args);
|
|
break;
|
|
case 'title': $this->_title = array_shift($args);
|
|
break;
|
|
case 'width': $this->_width = array_shift($args);
|
|
break;
|
|
case 'ymetric': $this->_ymetric = array_shift($args);
|
|
break;
|
|
default:
|
|
throw new Kohana_Exception('Unknown method :name',array(':name'=>$name));
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Render the URL that generates the graph
|
|
*/
|
|
final public function __toString() {
|
|
try {
|
|
return (string)$this->render();
|
|
} catch (Exception $e) {
|
|
echo Debug::vars(array('m'=>__METHOD__,'e'=>$e));die();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Pick the driver that will render the graph
|
|
* @param $class The child class to invoke
|
|
*/
|
|
final public static function factory($class) {
|
|
$c = sprintf('%s_%s',get_called_class(),$class);
|
|
|
|
if (! class_exists($c))
|
|
throw new Kohana_Exception('Unknown HighChart Type :class',array(':class'=>$class));
|
|
else
|
|
return new $c();
|
|
}
|
|
|
|
public function series($type,$axis) {
|
|
if (! in_array($type,$this->_valid_axis))
|
|
throw new Kohana_Exception('Type not allowed for Chart :type',array(':type'=>$type));
|
|
|
|
$x = 'HighChart_Type_'.ucfirst($type);
|
|
if (! class_exists($x))
|
|
throw new Kohana_Exception('Class does not exist :class',array(':class'=>$x));
|
|
|
|
if (! isset($this->_series[$axis]))
|
|
$this->_series[$axis] = array();
|
|
|
|
$c = count($this->_series[$axis]);
|
|
|
|
$this->_series[$axis][$c] = new $x;
|
|
|
|
return $this->_series[$axis][$c];
|
|
}
|
|
|
|
/**
|
|
* Return the colors that will be used for this series
|
|
*/
|
|
protected function series_colour($c) {
|
|
if (is_null($c))
|
|
return NULL;
|
|
|
|
static $colours = NULL;
|
|
|
|
if (is_null($colours))
|
|
$colors = count($this->_series_colours);
|
|
|
|
return '#'.$this->_series_colours[$c%$colors];
|
|
}
|
|
}
|
|
?>
|