_divname = array_shift($args); break; case 'height': $this->_height = array_shift($args); break; case 'pointurl': $this->_pointurl = array_shift($args); break; case 'subtitle': $this->_subtitle = array_shift($args); break; case 'title': $this->_title = array_shift($args); break; case 'tooltip': $this->_tooltip = array_shift($args); break; case 'width': $this->_width = array_shift($args); break; case 'xmetric': $this->_xmetric = 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(); } /** * Common required items for all graphs * @todo: Call this in all sub-classes for consitency */ final protected function render_init() { Script::add(array( 'type'=>'file', 'data'=>'media/js/highcharts.js', )); Script::add(array( 'type'=>'file', 'data'=>'media/js/modules/exporting.js', )); } /** * Common required items for all graphs * @todo: Call this in all sub-classes for consitency */ final protected function render_post() { return sprintf('
',$this->_divname); } /** * Add values to a series * * @param: string Series Type * @param: string Series Name (used for the legend) */ public function series($type,$name) { if ($this->_data_type AND ! in_array($type,$this->_data_type)) 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[$name])) $this->_series[$name] = array(); $c = count($this->_series[$name]); $this->_series[$name][$c] = new $x; return $this->_series[$name][$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]; } } ?>