Public Member Functions | |
__construct () | |
setDataRows ($rows) | |
addSeries ($seriesId, array $options) | |
getSeries ($seriesId) | |
getAllSeries () | |
getChartUrl ($directUrl=true) | |
setAxisLabels ($axis, $labels) | |
setHtmlId ($htmlId) | |
getHtmlId () | |
Public Attributes | |
const | API_URL = 'http://chart.apis.google.com/chart' |
Protected Member Functions | |
_getTabTemplate () | |
getRowsData ($attributes, $single=false) | |
_getPow ($number) | |
getWidth () | |
getHeight () | |
Protected Attributes | |
$_allSeries = array() | |
$_axisLabels = array() | |
$_axisMaps = array() | |
$_dataRows = array() | |
$_simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' | |
$_extendedEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.' | |
$_width = '587' | |
$_height = '300' | |
$_encoding = 'e' | |
$_htmlId = '' |
Definition at line 35 of file Graph.php.
__construct | ( | ) |
Constructor
By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes
Reimplemented from Varien_Object.
Reimplemented in Mage_Adminhtml_Block_Dashboard_Tab_Amounts, and Mage_Adminhtml_Block_Dashboard_Tab_Orders.
Definition at line 55 of file Graph.php.
00056 { 00057 parent::__construct(); 00058 $this->setTemplate('dashboard/graph.phtml'); 00059 }
_getPow | ( | $ | number | ) | [protected] |
_getTabTemplate | ( | ) | [protected] |
addSeries | ( | $ | seriesId, | |
array $ | options | |||
) |
getAllSeries | ( | ) |
getChartUrl | ( | $ | directUrl = true |
) |
setting skip step
skipping some x labels for good reading
Format date
Definition at line 90 of file Graph.php.
00091 { 00092 $params = array( 00093 'cht' => 'lc', 00094 'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0', 00095 'chm' => 'B,f4d4b2,0,0,0', 00096 'chco' => 'db4814' 00097 ); 00098 00099 $this->_allSeries = $this->getRowsData($this->_dataRows); 00100 00101 foreach ($this->_axisMaps as $axis => $attr){ 00102 $this->setAxisLabels($axis, $this->getRowsData($attr, true)); 00103 } 00104 00105 $gmtOffset = Mage::getSingleton('core/date')->getGmtOffset(); 00106 00107 list ($dateStart, $dateEnd) = Mage::getResourceModel('reports/order_collection') 00108 ->getDateRange($this->getDataHelper()->getParam('period'), '', '', true); 00109 00110 $dates = array(); 00111 $datas = array(); 00112 00113 while($dateStart->compare($dateEnd) < 0){ 00114 switch ($this->getDataHelper()->getParam('period')) { 00115 case '24h': 00116 $d = $dateStart->toString('yyyy-MM-dd HH:00'); 00117 $dateStart->addHour(1); 00118 break; 00119 case '7d': 00120 case '1m': 00121 $d = $dateStart->toString('yyyy-MM-dd'); 00122 $dateStart->addDay(1); 00123 break; 00124 case '1y': 00125 case '2y': 00126 $d = $dateStart->toString('yyyy-MM'); 00127 $dateStart->addMonth(1); 00128 break; 00129 } 00130 foreach ($this->getAllSeries() as $index=>$serie) { 00131 if (in_array($d, $this->_axisLabels['x'])) { 00132 $datas[$index][] = (float)array_shift($this->_allSeries[$index]); 00133 } else { 00134 $datas[$index][] = 0; 00135 } 00136 } 00137 $dates[] = $d; 00138 } 00139 00140 /** 00141 * setting skip step 00142 */ 00143 if (count($dates) > 8 && count($dates) < 15) { 00144 $c = 1; 00145 } else if (count($dates) >= 15){ 00146 $c = 2; 00147 } else { 00148 $c = 0; 00149 } 00150 /** 00151 * skipping some x labels for good reading 00152 */ 00153 $i=0; 00154 foreach ($dates as $k => $d) { 00155 if ($i == $c) { 00156 $dates[$k] = $d; 00157 $i = 0; 00158 } else { 00159 $dates[$k] = ''; 00160 $i++; 00161 } 00162 } 00163 00164 $this->_axisLabels['x'] = $dates; 00165 $this->_allSeries = $datas; 00166 00167 //Google encoding values 00168 if ($this->_encoding == "s") { 00169 // simple encoding 00170 $params['chd'] = "s:"; 00171 $dataDelimiter = ""; 00172 $dataSetdelimiter = ","; 00173 $dataMissing = "_"; 00174 } else { 00175 // extended encoding 00176 $params['chd'] = "e:"; 00177 $dataDelimiter = ""; 00178 $dataSetdelimiter = ","; 00179 $dataMissing = "__"; 00180 } 00181 00182 // process each string in the array, and find the max length 00183 foreach ($this->getAllSeries() as $index => $serie) { 00184 $localmaxlength[$index] = sizeof($serie); 00185 $localmaxvalue[$index] = max($serie); 00186 $localminvalue[$index] = min($serie); 00187 } 00188 00189 if (is_numeric($this->_max)) { 00190 $maxvalue = $this->_max; 00191 } else { 00192 $maxvalue = max($localmaxvalue); 00193 } 00194 if (is_numeric($this->_min)) { 00195 $minvalue = $this->_min; 00196 } else { 00197 $minvalue = min($localminvalue); 00198 } 00199 00200 $maxlength = max($localmaxlength); 00201 if ($minvalue >= 0 && $maxvalue >= 0) { 00202 $miny = 0; 00203 if ($maxvalue > 10) { 00204 $p = pow(10, $this->_getPow($maxvalue)); 00205 $maxy = (ceil($maxvalue/$p))*$p; 00206 $yLabels = range($miny, $maxy, $p); 00207 } else { 00208 $maxy = ceil($maxvalue+1); 00209 $yLabels = range($miny, $maxy, 1); 00210 } 00211 $yrange = $maxy; 00212 $yorigin = 0; 00213 } 00214 00215 $chartdata = array(); 00216 00217 foreach ($this->getAllSeries() as $index => $serie) { 00218 $thisdataarray = $serie; 00219 if ($this->_encoding == "s") { 00220 // SIMPLE ENCODING 00221 for ($j = 0; $j < sizeof($thisdataarray); $j++) { 00222 $currentvalue = $thisdataarray[$j]; 00223 if (is_numeric($currentvalue)) { 00224 $ylocation = round((strlen($this->_simpleEncoding)-1) * ($yorigin + $currentvalue) / $yrange); 00225 array_push($chartdata, substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter); 00226 } else { 00227 array_push($chartdata, $dataMissing . $dataDelimiter); 00228 } 00229 } 00230 // END SIMPLE ENCODING 00231 } else { 00232 // EXTENDED ENCODING 00233 for ($j = 0; $j < sizeof($thisdataarray); $j++) { 00234 $currentvalue = $thisdataarray[$j]; 00235 if (is_numeric($currentvalue)) { 00236 if ($yrange) { 00237 $ylocation = (4095 * ($yorigin + $currentvalue) / $yrange); 00238 } else { 00239 $ylocation = 0; 00240 } 00241 $firstchar = floor($ylocation / 64); 00242 $secondchar = $ylocation % 64; 00243 $mappedchar = substr($this->_extendedEncoding, $firstchar, 1) . substr($this->_extendedEncoding, $secondchar, 1); 00244 array_push($chartdata, $mappedchar . $dataDelimiter); 00245 } else { 00246 array_push($chartdata, $dataMissing . $dataDelimiter); 00247 } 00248 } 00249 // ============= END EXTENDED ENCODING ============= 00250 } 00251 array_push($chartdata, $dataSetdelimiter); 00252 } 00253 $buffer = implode('', $chartdata); 00254 00255 $buffer = rtrim($buffer, $dataSetdelimiter); 00256 $buffer = rtrim($buffer, $dataDelimiter); 00257 $buffer = str_replace(($dataDelimiter . $dataSetdelimiter), $dataSetdelimiter, $buffer); 00258 00259 $params['chd'] .= $buffer; 00260 00261 $labelBuffer = ""; 00262 $valueBuffer = array(); 00263 $rangeBuffer = ""; 00264 00265 if (sizeof($this->_axisLabels) > 0) { 00266 $params['chxt'] = implode(',', array_keys($this->_axisLabels)); 00267 $indexid = 0; 00268 foreach ($this->_axisLabels as $idx=>$labels){ 00269 if ($idx == 'x') { 00270 /** 00271 * Format date 00272 */ 00273 foreach ($this->_axisLabels[$idx] as $_index=>$_label) { 00274 if ($_label != '') { 00275 switch ($this->getDataHelper()->getParam('period')) { 00276 case '24h': 00277 $this->_axisLabels[$idx][$_index] = $this->formatTime($_label, 'short', false); 00278 break; 00279 case '7d': 00280 case '1m': 00281 $this->_axisLabels[$idx][$_index] = $this->formatDate($_label); 00282 break; 00283 case '1y': 00284 case '2y': 00285 $formats = Mage::app()->getLocale()->getTranslationList('datetime'); 00286 $format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy'; 00287 $format = str_replace(array("yyyy", "yy", "MM"), array("Y", "y", "m"), $format); 00288 $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label)); 00289 break; 00290 } 00291 } else { 00292 $this->_axisLabels[$idx][$_index] = ''; 00293 } 00294 00295 } 00296 00297 $tmpstring = implode('|', $this->_axisLabels[$idx]); 00298 00299 $valueBuffer[] = $indexid . ":|" . $tmpstring; 00300 if (sizeof($this->_axisLabels[$idx]) > 1) { 00301 $deltaX = 100/(sizeof($this->_axisLabels[$idx])-1); 00302 } else { 00303 $deltaX = 100; 00304 } 00305 } else if ($idx == 'y') { 00306 $valueBuffer[] = $indexid . ":|" . implode('|', $yLabels); 00307 if (sizeof($yLabels)-1) { 00308 $deltaY = 100/(sizeof($yLabels)-1); 00309 } else { 00310 $deltaY = 100; 00311 } 00312 // setting range values for y axis 00313 $rangeBuffer = $indexid . "," . $miny . "," . $maxy . "|"; 00314 } 00315 $indexid++; 00316 } 00317 $params['chxl'] = implode('|', $valueBuffer); 00318 }; 00319 00320 // chart size 00321 $params['chs'] = $this->getWidth().'x'.$this->getHeight(); 00322 00323 if (isset($deltaX) && isset($deltaY)) { 00324 $params['chg'] = $deltaX . ',' . $deltaY . ',1,0'; 00325 } 00326 00327 // return the encoded data 00328 if ($directUrl) { 00329 $p = array(); 00330 foreach ($params as $name => $value) { 00331 $p[] = $name . '=' .urlencode($value); 00332 } 00333 return self::API_URL . '?' . implode('&', $p); 00334 } else { 00335 $params = array('ga' => urlencode(base64_encode(serialize($params)))); 00336 return $this->getUrl('*/*/tunnel', $params); 00337 } 00338 }
getHeight | ( | ) | [protected] |
getHtmlId | ( | ) |
getRowsData | ( | $ | attributes, | |
$ | single = false | |||
) | [protected] |
Definition at line 340 of file Graph.php.
00341 { 00342 $items = $this->getCollection()->getItems(); 00343 $options = array(); 00344 foreach ($items as $item){ 00345 if ($single) { 00346 $options[] = $item->getData($attributes); 00347 } else { 00348 foreach ((array)$attributes as $attr){ 00349 $options[$attr][] = $item->getData($attr); 00350 } 00351 } 00352 } 00353 return $options; 00354 }
getSeries | ( | $ | seriesId | ) |
getWidth | ( | ) | [protected] |
setAxisLabels | ( | $ | axis, | |
$ | labels | |||
) |
setDataRows | ( | $ | rows | ) |
setHtmlId | ( | $ | htmlId | ) |
$_extendedEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.' [protected] |
$_simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' [protected] |