79 lines
1.6 KiB
PHP
79 lines
1.6 KiB
PHP
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||
|
|
||
|
/**
|
||
|
* This class provides access to HighCharts Series Data Types
|
||
|
*
|
||
|
* @package HighChart/Types
|
||
|
* @category Helper
|
||
|
* @author Deon George
|
||
|
* @copyright (c) 2012-2013 Deon George
|
||
|
* @license http://dev.leenooks.net/license.html
|
||
|
*/
|
||
|
abstract class HighChart_Type {
|
||
|
// The series data in the format X=Y, eg: "12-11"=>16057,...
|
||
|
protected $_sdata = array();
|
||
|
protected $_sindex = NULL;
|
||
|
protected $_soptions = array();
|
||
|
protected $_sorder = 0;
|
||
|
protected $_stitle = '';
|
||
|
|
||
|
public function __call($name,$args) {
|
||
|
switch ($name) {
|
||
|
case 'data':
|
||
|
if (! $args)
|
||
|
return $this->_sdata;
|
||
|
|
||
|
$this->_sdata = array_shift($args);
|
||
|
break;
|
||
|
|
||
|
case 'index':
|
||
|
if (! $args)
|
||
|
return $this->_sindex;
|
||
|
|
||
|
$this->_sindex = array_shift($args);
|
||
|
break;
|
||
|
|
||
|
case 'name':
|
||
|
if (! $args)
|
||
|
return $this->_stitle;
|
||
|
|
||
|
$this->_stitle = array_shift($args);
|
||
|
break;
|
||
|
|
||
|
case 'order':
|
||
|
if (! $args)
|
||
|
return $this->_sorder;
|
||
|
|
||
|
$this->_sorder = array_shift($args);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
throw new Kohana_Exception('Unknown method :name',array(':name'=>$name));
|
||
|
}
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Incrementally add to a series
|
||
|
*/
|
||
|
public function series_add($name,$v,$options=array()) {
|
||
|
if (! empty($this->_sdata[$name]))
|
||
|
throw new Kohana_Exception('Column :column already has some data',array(':column'=>$name));
|
||
|
|
||
|
$this->_sdata[$name] = $v;
|
||
|
|
||
|
foreach ($options as $k=>$v)
|
||
|
$this->_soptions[$k][$name] = $v;
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Calculate the total of all data in the series
|
||
|
*/
|
||
|
public function total() {
|
||
|
return array_sum($this->_sdata);
|
||
|
}
|
||
|
}
|