_plotdata); } public function current() { return current($this->_plotdata); } public function key() { return key($this->_plotdata); } public function next() { return next($this->_plotdata); } public function rewind() { reset($this->_plotdata); } public function valid() { return key($this->_plotdata) ? TRUE : FALSE; } public function __call($name,$args) { switch ($name) { case 'title': $this->_title = 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($e); } } /** * 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 Google Chart Type :class',array(':class'=>$class)); else return new $c(); } // Our child class should define how to render as a string abstract public function render(); /** * Record one series of data * @param $axis Axis used and legend title, eg: (yr->"Right Y",yl->"Left Y") * @param $data Data for Axis in the format ("x label"=>value); * * Example: * $this->data('yl'=>'Base Down Peak',array('11-12'=>1,'11-11'=>2)); */ public function data(array $axis,array $data) { // Some sanity checking if (count($axis) != 1) throw new Kohana_Exception('We can only take 1 series at time.'); // This should only iterate once foreach ($axis as $key => $l) { if (! in_array($key,array('yr','yl'))) throw new Kohaan_Exception('Unknown AXIS :axis',array(':axis'=>$key)); $this->_axis[$l] = $key; $this->_data[$l] = $data[$l]; // Upate our plot data foreach ($data[$l] as $k=>$v) $this->_plotdata[$k][$l] = $v; ksort($this->_plotdata); $this->_max[$l] = max($data[$l]); } return $this; } /** * Return the colors that will be used for this series */ protected function seriescolors() { return array_slice($this->series_colors,0,count($this->_axis)); } /** * Render the chart data in a table format */ public function table($vertical=TRUE,$class=array()) { if (! $this->_data) return sprintf('
%s
',_('No Data')); $output = sprintf('', isset($class['table']) ? $class['table'] : 'class="google-data-table"'); if ($vertical) { $output .= ''; $output .= ''; foreach ($this->_axis as $l => $axis) $output .= sprintf('',$l); $output .= ''; foreach ($this as $k => $details) { $output .= ''; $output .= sprintf('',$k); foreach ($this->_axis as $l => $axis) $output .= sprintf('',$details[$l]); $output .= ''; } // Horizontal table } else { $output .= ''; $output .= ''; foreach ($this as $k => $details) $output .= sprintf('',$k); $output .= ''; foreach ($this->_axis as $l => $axis) { $output .= ''; $output .= sprintf('',$l); foreach ($this as $k => $v) $output .= sprintf('',$v[$l]); $output .= ''; } } $output .= '
 %s
%s%s
 %s
%s%s
'; return $output; } } ?>