print_graph

The Gravity PDF print graph function.

Description

print_graph( $g, $pgwidth ); 

Parameters (2)

0. $g
The g.
1. $pgwidth
The pgwidth.

Usage

  1. if ( !function_exists( 'print_graph' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'gravity-pdf/vendor/blueliquiddesigns/mpdf/graph.php'; 
  3.  
  4. // The g. 
  5. $g = null; 
  6.  
  7. // The pgwidth. 
  8. $pgwidth = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = print_graph($g, $pgwidth); 
  12.  

Defined (1)

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

/vendor/blueliquiddesigns/mpdf/graph.php  
  1. function print_graph($g, $pgwidth) 
  2. $splines = false; 
  3. $bandw = false; 
  4. $percent = false; 
  5. $show_percent = false; 
  6. $stacked = false; 
  7. $h = false; 
  8. $show_values = false; 
  9. $hide_grid = false; 
  10. $hide_y_axis = false; 
  11.  
  12. if (isset($g['attr']['TYPE']) && $g['attr']['TYPE']) { 
  13. $type = strtolower($g['attr']['TYPE']); 
  14. if (!in_array($type, array('bar', 'horiz_bar', 'line', 'radar', 'pie', 'pie3d', 'xy', 'scatter'))) { 
  15. $type = 'bar'; 
  16. } // Default=bar 
  17.  
  18. if (isset($g['attr']['STACKED']) && $g['attr']['STACKED']) { 
  19. $stacked = true; 
  20. } // stacked for bar or horiz_bar 
  21. if (isset($g['attr']['SPLINES']) && $g['attr']['SPLINES'] && $type == 'xy') { 
  22. $splines = true; 
  23. } // splines for XY line graphs 
  24. if (isset($g['attr']['BANDW']) && $g['attr']['BANDW']) { 
  25. $bandw = true; 
  26. } // black and white 
  27. if (isset($g['attr']['LEGEND-OVERLAP']) && $g['attr']['LEGEND-OVERLAP']) { 
  28. $overlap = true; 
  29. } // avoid overlap of Legends over graph (line, bar, horiz_bar only) 
  30. if (isset($g['attr']['PERCENT']) && $g['attr']['PERCENT'] && $type != 'xy' && $type != 'scatter') { 
  31. $percent = true; 
  32. } // Show data series as percent of total in series 
  33. if (isset($g['attr']['SHOW-VALUES']) && $g['attr']['SHOW-VALUES']) { 
  34. $show_values = true; 
  35. } // Show the individual data values 
  36. if (isset($g['attr']['HIDE-GRID']) && $g['attr']['HIDE-GRID']) { 
  37. $hide_grid = true; 
  38. } // Hide the y-axis gridlines 
  39. if (isset($g['attr']['HIDE-Y-AXIS']) && $g['attr']['HIDE-Y-AXIS']) { 
  40. $hide_y_axis = true; 
  41. } // Hide the y-axis 
  42. // Antialias: If true - better quality curves, but graph line will only be 1px even in PDF 300dpi 
  43. // default=true for most except line and radar 
  44. if (isset($g['attr']['ANTIALIAS']) && ($g['attr']['ANTIALIAS'] == '' || $g['attr']['ANTIALIAS'] == 0)) { 
  45. $antialias = false; 
  46. } else if (isset($g['attr']['ANTIALIAS']) && $g['attr']['ANTIALIAS'] > 0) { 
  47. $antialias = true; 
  48. } else if ($type == 'line' || $type == 'radar') { 
  49. $antialias = false; 
  50. } else { 
  51. $antialias = true; 
  52.  
  53. if ($g['attr']['DPI']) { 
  54. $dpi = intval($g['attr']['DPI']); 
  55. if (!$dpi || $dpi < 50 || $dpi > 2400) { 
  56. $dpi = 150; 
  57. } // Default dpi 150 
  58. $k = (0.2645 / 25.4 * $dpi); 
  59.  
  60. // mPDF 4.5.009 
  61. global $JpgUseSVGFormat; 
  62. if (isset($JpgUseSVGFormat) && $JpgUseSVGFormat) { 
  63. $img_type = svg; 
  64. $k = 1; // Overrides as Vector scale does not need DPI 
  65. } else { 
  66. $img_type = 'png'; 
  67.  
  68. if (isset($g['attr']['TITLE']) && $g['attr']['TITLE']) { 
  69. $title = $g['attr']['TITLE']; 
  70.  
  71. if (isset($g['attr']['LABEL-X']) && $g['attr']['LABEL-X']) { 
  72. $xlabel = $g['attr']['LABEL-X']; 
  73. } // NOT IMPLEMENTED?????? 
  74. if (isset($g['attr']['LABEL-Y']) && $g['attr']['LABEL-Y']) { 
  75. $ylabel = $g['attr']['LABEL-Y']; 
  76.  
  77. if (isset($g['attr']['AXIS-X']) && $g['attr']['AXIS-X']) { 
  78. $xaxis = strtolower($g['attr']['AXIS-X']); 
  79. if (!in_array($xaxis, array('text', 'lin', 'linear', 'log'))) { 
  80. $xaxis = 'text'; 
  81. } // Default=text 
  82. if ($xaxis == 'linear') { 
  83. $xaxis = 'lin'; 
  84.  
  85. if (isset($g['attr']['AXIS-Y']) && $g['attr']['AXIS-Y']) { 
  86. $yaxis = strtolower($g['attr']['AXIS-Y']); 
  87. if (!in_array($yaxis, array('lin', 'linear', 'log', 'percent'))) { 
  88. $yaxis = 'lin'; 
  89. } // Default=lin 
  90. if ($yaxis == 'percent') { 
  91. $show_percent = true; 
  92. $yaxis = 'lin'; 
  93. } // Show percent sign on scales 
  94. if ($yaxis == 'linear') { 
  95. $yaxis = 'lin'; 
  96.  
  97. if ($splines) { 
  98. $xaxis = 'lin'; 
  99. $axes = $xaxis . $yaxis; // e.g.textlin, textlog, loglog, loglin, linlog (XY) 
  100. // mPDF 4.0 
  101. if (isset($g['attr']['cWIDTH']) && $g['attr']['cWIDTH']) { 
  102. $w = ($g['attr']['cWIDTH'] / 0.2645); 
  103. } // pixels 
  104. if (isset($g['attr']['cHEIGHT']) && $g['attr']['cHEIGHT']) { 
  105. $h = ($g['attr']['cHEIGHT'] / 0.2645); 
  106.  
  107.  
  108. if (isset($g['attr']['SERIES']) && strtolower($g['attr']['SERIES']) == 'rows') { 
  109. $dataseries = 'rows'; 
  110. } else { 
  111. $dataseries = 'cols'; 
  112.  
  113. // Defaults - define data 
  114. $rowbegin = 2; 
  115. $colbegin = 2; 
  116. if ($type == 'scatter' || $type == 'xy') { 
  117. if ($dataseries == 'rows') { 
  118. $rowbegin = 1; 
  119. } else { 
  120. $colbegin = 1; 
  121. $rowend = 0; 
  122. $colend = 0; 
  123.  
  124. if (isset($g['attr']['DATA-ROW-BEGIN']) && ($g['attr']['DATA-ROW-BEGIN'] === '0' || $g['attr']['DATA-ROW-BEGIN'] > 0)) { 
  125. $rowbegin = $g['attr']['DATA-ROW-BEGIN']; 
  126.  
  127. if (isset($g['attr']['DATA-COL-BEGIN']) && ($g['attr']['DATA-COL-BEGIN'] === '0' || $g['attr']['DATA-COL-BEGIN'] > 0)) { 
  128. $colbegin = $g['attr']['DATA-COL-BEGIN']; 
  129.  
  130. if (isset($g['attr']['DATA-ROW-END']) && ($g['attr']['DATA-ROW-END'] === '0' || $g['attr']['DATA-ROW-END'] <> 0)) { 
  131. $rowend = $g['attr']['DATA-ROW-END']; 
  132. if (isset($g['attr']['DATA-COL-END']) && ($g['attr']['DATA-COL-END'] === '0' || $g['attr']['DATA-COL-END'] <> 0)) { 
  133. $colend = $g['attr']['DATA-COL-END']; 
  134.  
  135. $nr = count($g['data']); 
  136. $nc = 0; 
  137. foreach ($g['data'] AS $r) { 
  138. $cc = 0; 
  139. foreach ($r AS $c) { 
  140. $cc++; 
  141. $nc = max($nc, $cc); 
  142. if ($colend == 0) { 
  143. $colend = $nc; 
  144. } else if ($colend < 0) { 
  145. $colend = $nc + $colend; 
  146.  
  147. if ($rowend == 0) { 
  148. $rowend = $nr; 
  149. } else if ($rowend < 0) { 
  150. $rowend = $nr + $rowend; 
  151.  
  152. if ($colend < $colbegin) { 
  153. $colend = $colbegin; 
  154. if ($rowend < $rowbegin) { 
  155. $rowend = $rowbegin; 
  156.  
  157. // if ($type == 'xy' || $type=='scatter') { $colstart=0; } 
  158. // Get Data + Totals 
  159. $data = array(); 
  160. $totals = array(); 
  161. for ($r = ($rowbegin - 1); $r < $rowend; $r++) { 
  162. for ($c = ($colbegin - 1); $c < $colend; $c++) { 
  163. if (isset($g['data'][$r][$c])) { 
  164. $g['data'][$r][$c] = floatval($g['data'][$r][$c]); 
  165. } else { 
  166. $g['data'][$r][$c] = 0; 
  167. if ($dataseries == 'rows') { 
  168. $data[($r + 1 - $rowbegin)][($c + 1 - $colbegin)] = $g['data'][$r][$c]; 
  169. $totals[($r + 1 - $rowbegin)] += $g['data'][$r][$c]; 
  170. } else { 
  171. $data[($c + 1 - $colbegin)][($r + 1 - $rowbegin)] = $g['data'][$r][$c]; 
  172. if (isset($totals[($c + 1 - $colbegin)])) { 
  173. $totals[($c + 1 - $colbegin)] += $g['data'][$r][$c]; 
  174. } else { 
  175. $totals[($c + 1 - $colbegin)] = $g['data'][$r][$c]; 
  176. // PERCENT 
  177. if ($percent && $type != 'pie' && $type != 'pie3d') { 
  178. for ($r = 0; $r < count($data); $r++) { 
  179. for ($c = 0; $c < count($data[$r]); $c++) { 
  180. $data[$r][$c] = $data[$r][$c] / $totals[$r] * 100; 
  181. // Get Legends and labels 
  182. $legends = array(); 
  183. $labels = array(); 
  184. $longestlegend = 0; 
  185. $longestlabel = 0; 
  186. if ($dataseries == 'cols') { 
  187. if ($colbegin > 1) { 
  188. for ($r = ($rowbegin - 1); $r < $rowend; $r++) { 
  189. $legends[($r + 1 - $rowbegin)] = $g['data'][$r][0]; 
  190. $longestlegend = max($longestlegend, strlen($g['data'][$r][0])); 
  191. if ($rowbegin > 1) { 
  192. for ($c = ($colbegin - 1); $c < $colend; $c++) { 
  193. $labels[($c + 1 - $colbegin)] = $g['data'][0][$c]; 
  194. $longestlabel = max($longestlabel, strlen($g['data'][0][$c])); 
  195. } else if ($dataseries == 'rows') { 
  196. if ($colbegin > 1) { 
  197. for ($r = ($rowbegin - 1); $r < $rowend; $r++) { 
  198. $labels[($r + 1 - $rowbegin)] = $g['data'][$r][0]; 
  199. $longestlabel = max($longestlabel, strlen($g['data'][$r][0])); 
  200. if ($rowbegin > 1) { 
  201. for ($c = ($colbegin - 1); $c < $colend; $c++) { 
  202. $legends[($c + 1 - $colbegin)] = $g['data'][0][$c]; 
  203. $longestlegend = max($longestlegend, strlen($g['data'][0][$c])); 
  204. // Default sizes 
  205. $defsize = array(); 
  206. $defsize['pie'] = array('w' => 600, 'h' => 300); 
  207. $defsize['pie3d'] = array('w' => 600, 'h' => 300); 
  208. $defsize['radar'] = array('w' => 600, 'h' => 300); 
  209. $defsize['line'] = array('w' => 600, 'h' => 400); 
  210. $defsize['xy'] = array('w' => 600, 'h' => 400); 
  211. $defsize['scatter'] = array('w' => 600, 'h' => 400); 
  212. $defsize['bar'] = array('w' => 600, 'h' => 400); 
  213. $defsize['horiz_bar'] = array('w' => 600, 'h' => 500); 
  214.  
  215.  
  216. // Use default ratios 
  217. if ($w && !$h) { 
  218. $h = $w * $defsize[$type]['h'] / $defsize[$type]['w']; 
  219. if ($h && !$w) { 
  220. $w = $h * $defsize[$type]['w'] / $defsize[$type]['h']; 
  221. if (!$h && !$w) { 
  222. $w = $defsize[$type]['w']; 
  223. $h = $defsize[$type]['h']; 
  224.  
  225.  
  226. if (count($data) > 0 && $type) { 
  227. $figure_file = "graph_cache/" . rand(11111, 999999999) . "." . $img_type; 
  228. if ($bandw) { 
  229. $colours = array('snow1', 'black', 'snow4', 'snow3', 'snow2', 'cadetblue4', 'cadetblue3', 'cadetblue1', 'bisque4', 'bisque2', 'beige'); 
  230. } else { 
  231. $colours = array('cyan', 'darkorchid4', 'cadetblue3', 'khaki1', 'darkolivegreen2', 'cadetblue4', 'coral', 'cyan4', 'rosybrown3', 'wheat1'); 
  232. $fills = array('navy', 'orange', 'red', 'yellow', 'purple', 'navy', 'orange', 'red', 'yellow', 'purple'); 
  233. $patterns = array(PATTERN_DIAG1, PATTERN_CROSS1, PATTERN_STRIPE1, PATTERN_DIAG3, PATTERN_CROSS2, PATTERN_DIAG2, PATTERN_DIAG4, PATTERN_CROSS3, PATTERN_CROSS4, PATTERN_STRIPE1); 
  234. $markers = array(MARK_DIAMOND, MARK_SQUARE, MARK_CIRCLE, MARK_UTRIANGLE, MARK_DTRIANGLE, MARK_FILLEDCIRCLE, MARK_CROSS, MARK_STAR, MARK_X); 
  235.  
  236. // LEGENDS 
  237. if ($type == 'pie' || $type == 'pie3d') { 
  238. $graph = new PieGraph(($w * $k), ($h * $k)); 
  239. } else if ($type == 'radar') { 
  240. $graph = new RadarGraph(($w * $k), ($h * $k)); 
  241. } else { 
  242. $graph = new Graph(($w * $k), ($h * $k)); 
  243.  
  244. // mPDF 4.5.009 
  245. // $graph->img->SetImgFormat($img_type) ; 
  246. // if (strtoupper($img_type)=='JPEG') { $graph->img->SetQuality(90); } 
  247. if ($antialias) { 
  248. $graph->img->SetAntiAliasing(); 
  249. $graph->SetShadow(true, 2 * $k); 
  250. $graph->SetMarginColor("white"); 
  251. // TITLE 
  252. $graph->title->Set($title); 
  253. $graph->title->SetMargin(10 * $k); 
  254. $graph->title->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); 
  255. $graph->title->SetColor("black"); 
  256. $graph->legend->SetLineSpacing(3 * $k); 
  257. $graph->legend->SetMarkAbsSize(6 * $k); 
  258. $graph->legend->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  259.  
  260. // Set GRAPH IMAGE MARGINS 
  261. if ($type == 'pie' || $type == 'pie3d') { 
  262. $psize = 0.3; 
  263. $pposxabs = ($w / 2); 
  264. $pposy = 0.55; 
  265. if ($longestlegend) { // if legend showing 
  266. $pposxabs -= ((($longestlegend * 5) + 20) / 2); 
  267. $pposx = ($pposxabs / $w); 
  268. $graph->legend->Pos(0.02, 0.5, 'right', 'center'); 
  269. } else if ($type == 'radar') { 
  270. $psize = 0.5; 
  271. $pposxabs = ($w / 2); 
  272. $pposy = 0.55; 
  273. if ($longestlabel) { // if legend showing 
  274. $pposxabs -= ((($longestlabel * 5) + 20) / 2); 
  275. $pposx = ($pposxabs / $w); 
  276. $graph->legend->Pos(0.02, 0.5, 'right', 'center'); 
  277. } else if ($type == 'xy' || $type == 'scatter') { 
  278. $pml = 50; 
  279. $pmr = 20; 
  280. $pmt = 60; 
  281. $pmb = 50; 
  282. $xaxislblmargin = $pmb - 30; 
  283. $yaxislblmargin = $pml - 15; 
  284. $graph->legend->Pos(0.02, 0.1, 'right', 'top'); 
  285. } else if ($type == 'line' || $type == 'bar') { 
  286. $pml = 50; 
  287. $pmr = 20; 
  288. $pmt = 60; 
  289. $pmb = 50; 
  290. $xlangle = 0; 
  291. $ll = ($longestlegend * 5); // 45 degrees 8pt fontsize 
  292. if ($ll > 5 || ($ll > 3 && count($data) > 10)) { 
  293. $pmb = max($pmb, $ll + 30); 
  294. $xlangle = 50; 
  295. $xaxislblmargin = $pmb - 30; 
  296. $yaxislblmargin = $pml - 15; 
  297. if ($longestlabel && !$overlap) { // if legend showing 
  298. $pmr = ((($longestlabel * 5) + 40)); 
  299. $graph->legend->Pos(0.02, 0.1, 'right', 'top'); 
  300. } else if ($type == 'horiz_bar') { 
  301. $pml = 50; 
  302. $pmr = 20; 
  303. $pmt = 50; 
  304. $pmb = 45; 
  305. $ll = ($longestlegend * 6.5); // 8pt fontsize 
  306. $pml = max($pml, $ll + 20); 
  307. $xaxislblmargin = $pml - 20; 
  308. $yaxislblmargin = $pmb - 15; 
  309. if ($longestlabel && !$overlap) { // if legend showing 
  310. $pmr = ((($longestlabel * 5) + 40)); 
  311. $graph->legend->Pos(0.02, 0.1, 'right', 'top'); 
  312.  
  313.  
  314. // DRAW THE GRAPHS 
  315. if ($type == 'pie') { 
  316. $p1 = new PiePlot($data[0]); 
  317. $p1->SetSliceColors($colours); 
  318.  
  319. if ($show_values) { 
  320. $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  321. if ($percent) { 
  322. $p1->SetLabelType(PIE_VALUE_PERADJ); 
  323. } //PIE_VAL_PER = default 
  324. else { 
  325. $p1->SetLabelType(PIE_VALUE_ABS); 
  326. if ($percent || $show_percent) { 
  327. $p1->value->SetFormat("%d%%"); 
  328. } else { 
  329. $p1->value->SetFormat("%s"); 
  330. // Enable and set policy for guide-lines. Make labels line up vertically 
  331. $p1->SetGuideLines(true); 
  332. $p1->SetGuideLinesAdjust(1.5); 
  333. } else { 
  334. $p1->value->Show(false); 
  335. $p1->SetLegends($legends); 
  336. $p1->SetSize($psize); 
  337. $p1->SetCenter($pposx, $pposy); 
  338. if ($labels[0]) { 
  339. $graph->subtitle->Set($labels[0]); 
  340. $graph->subtitle->SetMargin(10 * $k); 
  341. $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); 
  342. $graph->subtitle->SetColor("black"); 
  343. $graph->Add($p1); 
  344. } else if ($type == 'pie3d') { 
  345. $p1 = new PiePlot3d($data[0]); 
  346. $p1->SetSliceColors($colours); 
  347. if ($show_values) { 
  348. $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  349. if ($percent) { 
  350. $p1->SetLabelType(PIE_VALUE_PERADJ); 
  351. } //PIE_VAL_PER = default 
  352. else { 
  353. $p1->SetLabelType(PIE_VALUE_ABS); 
  354. if ($percent || $show_percent) { 
  355. $p1->value->SetFormat("%d%%"); 
  356. } else { 
  357. $p1->value->SetFormat("%s"); 
  358. } else { 
  359. $p1->value->Show(false); 
  360. $p1->SetLegends($legends); 
  361. $p1->SetEdge(); 
  362. $p1->SetSize($psize); 
  363. $p1->SetCenter($pposx, $pposy); 
  364.  
  365. if ($labels[0]) { 
  366. $graph->subtitle->Set($labels[0]); 
  367. $graph->subtitle->SetMargin(10 * $k); 
  368. $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); 
  369. $graph->subtitle->SetColor("black"); 
  370.  
  371. $graph->Add($p1); 
  372. // RADAR 
  373. else if ($type == 'radar') { 
  374. $graph->SetSize($psize); 
  375. $graph->SetPos($pposx, $pposy); 
  376.  
  377. $graph->SetTitles($legends); // labels each axis 
  378.  
  379. $graph->axis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  380. $graph->axis->title->SetMargin(5 * $k); 
  381. $graph->axis->SetWeight(1 * $k); 
  382. $graph->axis->HideLabels(); 
  383. $graph->axis->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k); 
  384. $graph->HideTickMarks(); 
  385.  
  386. $group = array(); 
  387. foreach ($data AS $series => $dat) { 
  388. $rdata = array(); 
  389. foreach ($data[$series] AS $row) { 
  390. $rdata[] = $row; 
  391. if (count($rdata) < 3) { 
  392. throw new MpdfException("ERROR::Graph::Cannot create a Radar Plot with less than 3 data points."); 
  393. // Create the radar plot 
  394. $bplot = new RadarPlot($rdata); 
  395. $bplot->mark->SetType($markers[$series]); 
  396. $bplot->mark->SetFillColor($colours[$series]); 
  397. $bplot->mark->SetWidth(3 * $k); 
  398. $bplot->SetColor($colours[$series]); 
  399. if ($series == 0) { 
  400. $bplot->SetFillColor('lightred'); 
  401. } else { 
  402. $bplot->SetFill(false); 
  403. $bplot->SetLineWeight(1 * $k); 
  404. $bplot->SetLegend($labels[$series]); 
  405. if ($bandw) { 
  406. $bplot->SetShadow("gray5"); 
  407. $graph->Add($bplot); 
  408. // LINE 
  409. else if ($type == 'line') { 
  410. // Setup the graph. 
  411. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB 
  412. $graph->SetScale($axes); 
  413. $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  414.  
  415. if ($ylabel) { 
  416. $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  417. $graph->yaxis->SetTitle($ylabel, 'middle'); 
  418. $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); 
  419.  
  420. $graph->yaxis->SetLabelMargin(4 * $k); 
  421. if ($percent || $show_percent) { 
  422. $graph->yaxis->SetLabelFormat('%d%%'); 
  423. } // Percent 
  424. // Show 0 label on Y-axis (default is not to show) 
  425. $graph->yscale->ticks->SupressZeroLabel(true); 
  426. if ($hide_y_axis) { 
  427. $graph->yaxis->Hide(); 
  428. if ($hide_grid) { 
  429. $graph->ygrid->Show(false); 
  430.  
  431. // Setup X-axis labels 
  432. $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  433. $graph->xaxis->SetTickLabels($legends); 
  434. $graph->xaxis->SetLabelAngle($xlangle); 
  435. $graph->xaxis->SetLabelMargin(4 * $k); 
  436. // X-axis title 
  437. if ($xlabel) { 
  438. $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  439. $graph->xaxis->SetTitle($xlabel, 'middle'); 
  440. $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); 
  441. foreach ($data AS $series => $rdata) { 
  442. $bplot = new LinePlot($rdata); 
  443. $bplot->mark->SetType($markers[$series]); 
  444. $bplot->mark->SetFillColor($colours[$series]); 
  445. $bplot->mark->SetWidth(4 * $k); 
  446. if ($show_values) { 
  447. $bplot->value->Show(); // Not if scatter 
  448. $bplot->value->SetMargin(6 * $k); 
  449. $bplot->value->SetColor("darkred"); 
  450. $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  451. if ($percent || $show_percent) { 
  452. $bplot->value->SetFormat('%d%%'); 
  453. } else { 
  454. $bplot->value->SetFormat("%s"); 
  455. // Set color for each line 
  456. $bplot->SetColor($colours[$series]); 
  457. $bplot->SetWeight(2 * $k); 
  458. $bplot->SetLegend($labels[$series]); 
  459. if ($bandw) { 
  460. $bplot->SetShadow("gray5"); 
  461. // Indent the X-scale so the first and last point doesn't fall on the edges 
  462. $bplot->SetCenter(); 
  463. $graph->Add($bplot); 
  464. // XY or SCATTER 
  465. else if ($type == 'xy' || $type == 'scatter') { 
  466. // Setup the graph. 
  467. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB 
  468. $graph->SetScale($axes); 
  469. // Setup font for axis 
  470. $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  471. // Y-axis title 
  472. if ($labels[1]) { 
  473. $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  474. $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); 
  475. $graph->yaxis->SetTitle($labels[1], 'middle'); 
  476.  
  477.  
  478. $graph->yaxis->SetLabelMargin(4 * $k); 
  479. if ($percent || $show_percent) { 
  480. $graph->yaxis->SetLabelFormat('%d%%'); 
  481. } // Percent 
  482. // Show 0 label on Y-axis (default is not to show) 
  483. $graph->yscale->ticks->SupressZeroLabel(true); 
  484. // Just let the maximum be autoscaled 
  485. $graph->yaxis->scale->SetAutoMin(0); 
  486. if ($hide_y_axis) { 
  487. $graph->yaxis->Hide(); 
  488. if ($hide_grid) { 
  489. $graph->ygrid->Show(false); 
  490.  
  491. // Setup X-axis labels 
  492. $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  493. // mPDF 2.5 Corrects labelling of x-axis 
  494. // $graph->xaxis->SetTickLabels($legends); 
  495. $graph->xaxis->SetLabelAngle(50); 
  496. $graph->xaxis->SetLabelMargin(4 * $k); 
  497. // X-axis title 
  498. if ($labels[0]) { 
  499. $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  500. $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); 
  501. $graph->xaxis->SetTitle($labels[0], 'middle'); 
  502.  
  503. // Create the bar plot 
  504. // SPLINES 
  505. if ($splines && $type == 'xy') { 
  506. $spline = new Spline($data[0], $data[1]); 
  507. list($newx, $newy) = $spline->Get(100); 
  508. } else { 
  509. $newx = $data[0]; 
  510. $newy = $data[1]; 
  511.  
  512. if ($type == 'xy') { 
  513. // LINE PLOT 
  514. $bplot = new LinePlot($newy, $newx); 
  515. // Set color for each line 
  516. $bplot->SetColor($fills[0]); 
  517. $bplot->SetWeight(4 * $k); 
  518. if ($bandw) { 
  519. $bplot->SetShadow("gray5"); 
  520. $graph->Add($bplot); 
  521.  
  522. // SCATTER PLOT 
  523. $cplot = new ScatterPlot($data[1], $data[0]); 
  524.  
  525. $cplot->mark->SetType($markers[0]); 
  526. $cplot->mark->SetFillColor($fills[0]); 
  527. $cplot->mark->SetWidth(8 * $k); 
  528. if ($show_values) { 
  529. // mPDF 2.5 
  530. if ($type == 'xy') { 
  531. $cplot->value->Show(); 
  532. } // Not if scatter 
  533. $cplot->value->SetMargin(8 * $k); 
  534. $cplot->value->SetColor("darkred"); 
  535. $cplot->value->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k); 
  536.  
  537. if ($percent || $show_percent) { 
  538. $cplot->value->SetFormat('%d%%'); 
  539. } else { 
  540. $cplot->value->SetFormat("%s"); 
  541.  
  542. // Set color for each line 
  543. $cplot->SetColor($fills[0]); 
  544. $cplot->SetWeight(4 * $k); 
  545. if ($bandw) { 
  546. $cplot->SetShadow("gray5"); 
  547. $graph->Add($cplot); 
  548. // BAR 
  549. else if ($type == 'bar') { 
  550. // Setup the graph. 
  551. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB 
  552. $graph->SetScale($axes); 
  553. // Setup y-axis 
  554. $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  555. if ($hide_y_axis) { 
  556. $graph->yaxis->Hide(); 
  557. if ($hide_grid) { 
  558. $graph->ygrid->Show(false); 
  559. $graph->yaxis->SetLabelMargin(4 * $k); 
  560. if ($ylabel) { 
  561. $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  562. $graph->yaxis->SetTitle($ylabel, 'middle'); 
  563. $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); 
  564. // Show 0 label on Y-axis (default is not to show) 
  565. $graph->yscale->ticks->SupressZeroLabel(false); 
  566. // Setup X-axis labels 
  567. $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  568. $graph->xaxis->SetTickLabels($legends); 
  569. $graph->xaxis->SetLabelAngle($xlangle); 
  570. $graph->xaxis->SetLabelMargin(4 * $k); 
  571. // X-axis title 
  572. if ($xlabel) { 
  573. $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  574. $graph->xaxis->SetTitle($xlabel, 'middle'); 
  575. $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); 
  576.  
  577. $group = array(); 
  578. foreach ($data AS $series => $dat) { 
  579. $rdata = array(); 
  580. foreach ($data[$series] AS $row) { 
  581. $rdata[] = $row; 
  582.  
  583. // Create the bar plot 
  584. $bplot = new BarPlot($rdata); 
  585. $bplot->SetWidth(0.6); // for SINGLE?? 
  586. // Setup color for gradient fill style 
  587. if ($bandw) { 
  588. $bplot->SetPattern($patterns[$series]); 
  589. } else { 
  590. $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION); 
  591.  
  592. // Set color for the frame of each bar 
  593. $bplot->SetColor("darkgray"); 
  594. $bplot->SetLegend($labels[$series]); 
  595. if ($bandw) { 
  596. $bplot->SetShadow("gray5"); 
  597. if ($show_values) { 
  598. $bplot->value->Show(); 
  599. $bplot->value->SetMargin(6 * $k); 
  600. $bplot->value->SetColor("darkred"); 
  601. $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  602. if ($percent || $show_percent) { 
  603. $bplot->value->SetFormat('%d%%'); 
  604. } else { 
  605. $bplot->value->SetFormat("%s"); 
  606.  
  607. $group[] = $bplot; 
  608. if (count($data) == 1) { 
  609. $graph->Add($group[0]); 
  610. } else { 
  611. // Create the grouped bar plot 
  612. if ($stacked) { 
  613. $gbplot = new AccBarPlot($group); 
  614. } else { 
  615. $gbplot = new GroupBarPlot($group); 
  616. $graph->Add($gbplot); 
  617. } else if ($type == 'horiz_bar') { 
  618. $graph->SetScale($axes); 
  619. $graph->Set90AndMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB 
  620. // Setup y-axis 
  621. $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  622. $graph->yaxis->SetLabelMargin(4 * $k); 
  623.  
  624. $graph->yaxis->SetPos('max'); // Intersect at top of x-axis i.e. y axis is at bottom 
  625. // First make the labels look right 
  626. $graph->yaxis->SetLabelAlign('center', 'top'); 
  627. if ($percent || $show_percent) { 
  628. $graph->yaxis->SetLabelFormat('%d%%'); 
  629. $graph->yaxis->SetLabelSide(SIDE_RIGHT); 
  630. $graph->yaxis->scale->SetGrace(10); // sets 10% headroom 
  631. if ($hide_y_axis) { 
  632. $graph->yaxis->Hide(); 
  633. if ($hide_grid) { 
  634. $graph->ygrid->Show(false); 
  635.  
  636. // The fix the tick marks 
  637. $graph->yaxis->SetTickSide(SIDE_LEFT); 
  638. if ($ylabel) { 
  639. $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  640. $graph->yaxis->SetTitle($ylabel, 'middle'); 
  641. $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); 
  642. // Finally setup the title 
  643. $graph->yaxis->SetTitleSide(SIDE_RIGHT); 
  644. // To align the title to the right use : 
  645. $graph->yaxis->title->Align('right'); 
  646. $graph->yaxis->title->SetAngle(0); 
  647.  
  648. // Show 0 label on Y-axis (default is not to show) 
  649. $graph->yscale->ticks->SupressZeroLabel(false); 
  650. // Setup X-axis labels 
  651. $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  652. $graph->xaxis->title->SetAngle(90); 
  653. $graph->xaxis->SetTickLabels($legends); 
  654. $graph->xaxis->SetLabelMargin(4 * $k); 
  655. // X-axis title 
  656. if ($xlabel) { 
  657. $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  658. $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); 
  659. $graph->xaxis->SetTitle($xlabel, 'middle'); 
  660. $group = array(); 
  661. foreach ($data AS $series => $dat) { 
  662. $rdata = array(); 
  663. foreach ($data[$series] AS $row) { 
  664. $rdata[] = $row; 
  665. // Create the bar pot 
  666. $bplot = new BarPlot($rdata); 
  667. $bplot->SetWidth(0.6); // for SINGLE?? 
  668. // Setup color for gradient fill style 
  669. if ($bandw) { 
  670. $bplot->SetPattern($patterns[$series]); 
  671. } else { 
  672. $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION); 
  673.  
  674. // Set color for the frame of each bar 
  675. $bplot->SetColor("darkgray"); 
  676. $bplot->SetLegend($labels[$series]); 
  677. if ($bandw) { 
  678. $bplot->SetShadow("gray5"); 
  679. if ($show_values) { 
  680. $bplot->value->Show(); 
  681. $bplot->value->SetMargin(6 * $k); 
  682. $bplot->value->SetColor("darkred"); 
  683. $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); 
  684. if ($percent || $show_percent) { 
  685. $bplot->value->SetFormat('%d%%'); 
  686. } else { 
  687. $bplot->value->SetFormat("%s"); 
  688.  
  689. $group[] = $bplot; 
  690. if (count($data) == 1) { 
  691. $graph->Add($group[0]); 
  692. } else { 
  693. // Create the grouped bar plot 
  694. if ($stacked) { 
  695. $gbplot = new AccBarPlot($group); 
  696. } else { 
  697. $gbplot = new GroupBarPlot($group); 
  698. $graph->Add($gbplot); 
  699. if ($graph) { 
  700. $graph->Stroke(_MPDF_PATH . $figure_file); 
  701. $srcpath = str_replace("\\", "/", dirname(__FILE__)) . "/"; 
  702. $srcpath .= $figure_file; 
  703. return array('file' => $srcpath, 'w' => $w, 'h' => $h); 
  704. return false; 
  705.