GoogleChartAxisCollection.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2008-2009 by Denis M. Gabaidulin                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     final class GoogleChartAxisCollection
00016     {
00017         private $axes = array();
00018         
00022         public static function create()
00023         {
00024             return new self;
00025         }
00026         
00030         public function addAxis(GoogleChartAxis $axis)
00031         {
00032             $typeId = $axis->getType()->getId();
00033             
00034             if (isset($this->axes[$typeId]))
00035                 throw new WrongArgumentException('Axis already exists');
00036             
00037             $this->axes[$typeId] = $axis;
00038             
00039             return $this;
00040         }
00041         
00045         public function getAxisByTypeId($typeId)
00046         {
00047             if (isset($this->axes[$typeId]))
00048                 return $this->axes[$typeId];
00049             else
00050                 return null;
00051         }
00052         
00053         public function toString()
00054         {
00055             $typeString = GoogleChartAxisType::getParamName().'=';
00056             
00057             $rangeString = GoogleChartDataRange::getParamName().'=';
00058             
00059             $labelsString = null;
00060             
00061             $types = $ranges = $labels = array();
00062             
00063             $i = 0;
00064             
00065             foreach ($this->axes as $axis) {
00066                 $types[] = $axis->getType()->toString();
00067                 
00068                 if ($range = $axis->getRange())
00069                     $ranges[$i] =
00070                         $i
00071                         .','
00072                         .$range->getMin()
00073                         .','
00074                         .$range->getMax();
00075                 
00076                 if ($interval = $axis->getInterval())
00077                     $ranges[$i] .= ','.$interval;
00078                         
00079                 if ($label = $axis->getLabel())
00080                     $labels[$i] = $label;
00081                 
00082                 $i++;
00083             }
00084             
00085             $typeString .= implode(',', $types);
00086             
00087             $rangeString.= implode('|', $ranges);
00088             
00089             if ($labels) {
00090                 $labelsString = '&'.GoogleChartAxisLabel::getParamName().'=';
00091                 
00092                 foreach ($labels as $index => $label) {
00093                     $labelsString .= $index.':|'.$label->toString();
00094                 }
00095             }
00096             
00097             return $typeString.'&'.$rangeString.$labelsString;
00098         }
00099     }
00100 ?>