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