86 lines
1.9 KiB
PHP
86 lines
1.9 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 {
|
|
// What axis are required when we receive data.
|
|
protected $_required_axis = array();
|
|
// The series data in the format axis = value
|
|
protected $_sdata = array();
|
|
protected $_sindex = NULL;
|
|
protected $_soptions = array();
|
|
protected $_sorder = 0;
|
|
protected $_stitle = '';
|
|
|
|
public function __call($name,$args) {
|
|
switch ($name) {
|
|
case 'data':
|
|
$args = array_shift($args);
|
|
|
|
if (array_diff(array_keys($args),$this->_required_axis))
|
|
throw new Kohana_Exception('Invalid data arguments for chart, expecting [:args]',array(':args'=>implode('|',$this->_required_axis)));
|
|
|
|
if (! $args)
|
|
return $this->_sdata;
|
|
|
|
$this->_sdata = $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);
|
|
}
|
|
}
|