googleChartsApi_PMPro

The XML Google Maps googleChartsApi PMPro class.

Defined (1)

The class is defined in the following location(s).

/xmlgooglemaps_googleChartsAPI.php  
  1. class googleChartsApi_PMPro { 
  2. var $yscale;  
  3. var $nodes=50; 
  4. var $ymin; 
  5. var $ymax; 
  6. var $xmax; 
  7. var $xLabelPartitions=4; 
  8. var $simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ; 
  9. var $valuesAtNodes; 
  10.  
  11. function googleChartsApi_PMPro(&$xvalues, &$yvalues, $override_ymin=-9999, $override_ymax=-9999, $override_yscale=0) { 
  12. $this->valuesAtNodes=googleChartsApi_PMPro::getValuesAtNodes($xvalues, $yvalues) ; 
  13. if ($override_ymin == -9999) { 
  14. $min = min($this->valuesAtNodes);  
  15. } else { 
  16. $min = $override_ymin; 
  17. if ($override_ymax == -9999) { 
  18. $max = max($this->valuesAtNodes); 
  19. } else { 
  20. $max = $override_ymax; 
  21. }  
  22. if ($override_yscale==0) {  
  23. $val1 = $max - $min; 
  24. if ($val1 == 0) { 
  25. $this->yscale = 1; 
  26. } else { 
  27. $val2 = $val1; 
  28. $val3 = 1; 
  29. while (round($val2, 0)>10) { 
  30. $val2 /= 10; 
  31. $val3 *= 10; 
  32. }  
  33. while (round($val2, 0)<1) { 
  34. $val2 *= 10; 
  35. $val3 /= 10; 
  36. }  
  37. $val4 = round($val2, 0); 
  38. switch ($val4) 
  39. case 10: $this->yscale = 10 * $val3 / 5; break; 
  40. case 1: $this->yscale = 1 * $val3 / 4; break; 
  41. case 2: $this->yscale = 2 * $val3 / 5; break; 
  42. case 3: $this->yscale = 3 * $val3 / 6; break; 
  43. case 4: $this->yscale = 4 * $val3 / 5; break; 
  44. case 5: $this->yscale = 5 * $val3 / 5; break; 
  45. case 6: $this->yscale = 6 * $val3 / 6; break; 
  46. case 7: $this->yscale = 6 * $val3 / 6; break; 
  47. case 8: $this->yscale = 8 * $val3 / 4; break; 
  48. case 9: $this->yscale = 8 * $val3 / 4; break;  
  49. } else { 
  50. $this->yscale = $override_yscale; 
  51.  
  52. $this->ymin=floor($min/$this->yscale)*$this->yscale; 
  53. $this->ymax=ceil($max/$this->yscale)*$this->yscale; 
  54. $this->ypartitions=($this->ymax-$this->ymin)/$this->yscale; 
  55. if ($this->ypartitions==0) { 
  56. $this->ypartitions=1;  
  57. $this->xmax=ceil($xvalues[count($xvalues)-1]);  
  58.  
  59. function simpleEncodeValues(&$values, $min, $max) { 
  60. $chartData= "" ; 
  61. $distance= $max-$min; 
  62. if ($distance==0) { $distance = 1; } 
  63. for ($l = 0; $l < count($values); $l++) { 
  64. $value=round(($values[$l]-$min)/$distance*61) ; 
  65. $chartData = $chartData . $this->simpleEncoding[$value] ; 
  66. }  
  67. return $chartData ;  
  68.  
  69. function getValuesAtNodes(&$xvalues, &$yvalues) { 
  70. // $xmax= $xvalues[count($xvalues)-1]; 
  71. // $xstep= $xmax / ($this->nodes - 1 ) ; 
  72. // $nextNode= 0; 
  73. // $valuesAtNodes = array(); 
  74. // $k=0; 
  75. // $l=0; 
  76. // for ($j = 0; $j < count($xvalues); $j++) { 
  77. // if ($xvalues[$j]>=$nextNode) { 
  78. // $valuesAtNodes[$k++] = $yvalues[$j]; 
  79. // $nextNode += $xstep; 
  80. // } else { 
  81. // $l++; 
  82. // } 
  83. // } 
  84.  
  85. $valuesAtNodes = array(); 
  86. $xmax = $xvalues[count($xvalues)-1]; 
  87. $xstep = $xmax / ($this->nodes - 1) ; 
  88. $xgrenze = $xstep / 2; 
  89. $xweight = 0; 
  90. $yweight = 0; 
  91. $k=0; 
  92. for ($j = 1; $j < count($xvalues); $j++) { 
  93. $xvalue1 = $xvalues[$j-1]; 
  94. $xvalue2 = $xvalues[$j]; 
  95. $yvalue = $yvalues[$j]; 
  96. $xdiffweight=$xvalue2-$xvalue1; 
  97. if ($xvalue1<$xgrenze) { 
  98. $xweight += $xdiffweight; 
  99. $yweight += $yvalue*$xdiffweight;  
  100. } else {  
  101. if ($xweight==0) { 
  102. $valuesAtNodes[$k++] = 0;  
  103. } else { 
  104. $valuesAtNodes[$k++] = $yweight / $xweight; 
  105. $xweight = $xdiffweight; 
  106. $yweight = $yvalue*$xdiffweight; 
  107. $xgrenze += $xstep; 
  108. if ($xweight==0) { 
  109. $valuesAtNodes[$k++] = 0;  
  110. } else { 
  111. $valuesAtNodes[$k++] = $yweight / $xweight; 
  112. }  
  113. return $valuesAtNodes; 
  114.  
  115. function getEleYLabels($measurementtype) { 
  116. $ylabels=array() ; 
  117. for ($yentry=$this->ymin;$yentry <= $this->ymax;$yentry+=$this->yscale) { 
  118. switch ($measurementtype) { 
  119. case "imperial": 
  120. case "nautic_imperial": 
  121. $ylabels[]=round($yentry, 1)." ft"; 
  122. break; 
  123. case "metric": 
  124. case "nautic_metric": 
  125. default: 
  126. $ylabels[]=round($yentry, 1)." m"; 
  127. break;  
  128. }  
  129. return $ylabels; 
  130.  
  131. function getEleXLabels($measurementtype) { 
  132. $xlabels=array(); 
  133. $xstep=$this->xmax/$this->xLabelPartitions; 
  134. for ($xentry=0;$xentry <= $this->xLabelPartitions;$xentry++) { 
  135. switch ($measurementtype) { 
  136. case "imperial": 
  137. $xlabels[]=round($xentry * $xstep, 1)." mi"; 
  138. break; 
  139. case "nautic_imperial": 
  140. case "nautic_metric": 
  141. $xlabels[]=round($xentry * $xstep, 1)." nm"; 
  142. break; 
  143. case "metric":  
  144. default: 
  145. $xlabels[]=round($xentry * $xstep, 1)." km"; 
  146. break;  
  147. }  
  148. return $xlabels ; 
  149.  
  150. function getSpeedYLabels($measurementtype, $speedscale) { 
  151. $ylabels=array() ; 
  152. for ($yentry=$this->ymin;$yentry <= $this->ymax;$yentry+=$this->yscale) { 
  153. switch (strtolower($measurementtype.$speedscale)) { 
  154. case "imperiallevel2": 
  155. $ylabels[]=round($yentry, 1)." mph"; 
  156. break; 
  157. case "imperiallevel1": 
  158. $ylabels[]=round($yentry, 1)." fps"; 
  159. break; 
  160. case "metriclevel1": 
  161. $ylabels[]=round($yentry, 1)." m/s"; 
  162. break; 
  163. case "nautic_metriclevel1": 
  164. case "nautic_metriclevel2": 
  165. case "nautic_imperiallevel1": 
  166. case "nautic_imperiallevel2": 
  167. $ylabels[]=round($yentry, 1)." kn"; 
  168. break; 
  169. default: 
  170. case "metriclevel2": 
  171. $ylabels[]=round($yentry, 1)." km/h"; 
  172. break; 
  173.  
  174. }  
  175. return $ylabels; 
  176.  
  177. function getSpeedXLabels($measurementtype) { 
  178. $xlabels=array(); 
  179. $xstep=$this->xmax/$this->xLabelPartitions; 
  180. for ($xentry=0;$xentry <= $this->xLabelPartitions;$xentry++) { 
  181. switch (strtolower($measurementtype)) { 
  182. case "imperial": 
  183. $xlabels[]=round($xentry * $xstep, 1)." mi"; 
  184. break; 
  185. case "nautic_imperial": 
  186. case "nautic_metric": 
  187. $xlabels[]=round($xentry * $xstep, 1)." nm"; 
  188. break;  
  189. default: 
  190. case "metric": 
  191. $xlabels[]=round($xentry * $xstep, 1)." km"; 
  192. break; 
  193. return $xlabels ; 
  194. }  
  195.  
  196. function getEleUrl($width, $height, $linecolor, $linewidth, $measurementtype, $title="", $checkpoint=0) { 
  197. $chart = array() ; 
  198. // Type 
  199. $chart['cht']="lc" ; 
  200. // line style 
  201. $chart['chls']=$linewidth.", 0, 0"; 
  202. // fill with horizontal stripes (90 degree)  
  203. $stripeHeight=1/$this->ypartitions; 
  204. $chart['chf']="c, ls, 90, CCCCCC, ".$stripeHeight.", FFFFFF, ".$stripeHeight; 
  205. // Labels  
  206. $chart['chxt'] = "x, y"; 
  207. $chart['chxl'] = "0:|".join("|", $this->getEleXLabels($measurementtype))."|1:|".join("|", $this->getEleYLabels($measurementtype)) ; 
  208. // Checkpoint Line 
  209. if ($checkpoint>0) { 
  210. $checkpoint = $checkpoint*100/$this->xmax; 
  211. $chart['chg'] = $checkpoint.", 0"; 
  212. // Data  
  213. $chart['chd']="s:".$this->simpleEncodeValues($this->valuesAtNodes, $this->ymin, $this->ymax); 
  214. // Size 
  215. $chart['chs']=$width."x".$height; 
  216. $chart['chco']=$linecolor; 
  217. // Title 
  218. if (strlen($title)>0) { 
  219. $chart['chtt'] = str_replace(" ", "+", $title); 
  220. $chart['chts'] = "555555, 12"; 
  221. $params=array() ; 
  222. foreach ($chart as $key => $value) { 
  223. $params[] = $key."=".$value; 
  224. return "http://chart.apis.google.com/chart?".join("&", $params); 
  225.  
  226. function getSpeedUrl($width, $height, $linecolor, $linewidth, $measurementtype, $speedscale, $title="", $checkpoint=0) { 
  227. $chart = array() ; 
  228. // Type 
  229. $chart['cht']="lc" ; 
  230. // line style 
  231. $chart['chls']=$linewidth.", 0, 0"; 
  232. // fill with horizontal stripes (90 degree) 
  233. $stripeHeight=1/$this->ypartitions; 
  234. $chart['chf']="c, ls, 90, CCCCCC, ".$stripeHeight.", FFFFFF, ".$stripeHeight; 
  235. // Labels 
  236. $chart['chxt']="x, y"; 
  237. $chart['chxl']="0:|".join("|", $this->getSpeedXLabels($measurementtype))."|1:|".join("|", $this->getSpeedYLabels($measurementtype, $speedscale)) ; 
  238. // Data 
  239. $chart['chd']="s:".$this->simpleEncodeValues($this->valuesAtNodes, $this->ymin, $this->ymax); 
  240. // Checkpoint Line 
  241. if ($checkpoint>0) { 
  242. $checkpoint = $checkpoint*100/$this->xmax; 
  243. $chart['chg'] = $checkpoint.", 0"; 
  244. }  
  245. // Size 
  246. $chart['chs']=$width."x".$height; 
  247. $chart['chco']=$linecolor; 
  248. // Title 
  249. if (strlen($title)>0) { 
  250. $chart['chtt'] = str_replace(" ", "+", $title); 
  251. $chart['chts'] = "555555, 12"; 
  252. }  
  253. $params=array() ; 
  254. foreach ($chart as $key => $value) { 
  255. $params[] = $key."=".$value; 
  256. return "http://chart.apis.google.com/chart?".join("&", $params); 
  257.