]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/graph.php
5 define ( "FF_USERFONT" , 15 ); // See jpgraph_ttf.inc.php for font IDs
6 global $JpgUseSVGFormat ;
7 $JpgUseSVGFormat = true ;
9 //======================================================================================================
10 // DELETE OLD GRAPH FILES FIRST - Housekeeping
11 // First clear any files in directory that are >1 hrs old
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
21 //==============================================================================================================
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' );
35 //======================================================================================================
36 //*****************************************************************************************************
37 //*****************************************************************************************************
38 //*****************************************************************************************************
39 //*****************************************************************************************************
40 //*****************************************************************************************************
41 //*****************************************************************************************************
42 //======================================================================================================
43 //======================================================================================================
45 //======================================================================================================
46 //======================================================================================================
48 //======================================================================================================
49 function print_graph ( $g , $pgwidth ) {
53 $show_percent = false ;
60 if ( isset ( $g [ 'attr' ][ 'TYPE' ]) && $g [ 'attr' ][ 'TYPE' ]) { $type
= strtolower ( $g
[ 'attr' ][ 'TYPE' ]); }
61 if (! in_array ( $type , array ( 'bar' , 'horiz_bar' , 'line' , 'radar' , 'pie' , 'pie3d' , 'xy' , 'scatter' ))) { $type
= 'bar' ; } // Default=bar
63 if ( isset ( $g [ 'attr' ][ 'STACKED' ]) && $g [ 'attr' ][ 'STACKED' ]) { $stacked
= true ; } // stacked for bar or horiz_bar
64 if ( isset ( $g [ 'attr' ][ 'SPLINES' ]) && $g [ 'attr' ][ 'SPLINES' ] && $type == 'xy' ) { $splines
= true ; } // splines for XY line graphs
65 if ( isset ( $g [ 'attr' ][ 'BANDW' ]) && $g [ 'attr' ][ 'BANDW' ]) { $bandw
= true ; } // black and white
66 if ( isset ( $g [ 'attr' ][ 'LEGEND-OVERLAP' ]) && $g [ 'attr' ][ 'LEGEND-OVERLAP' ]) { $overlap
= true ; } // avoid overlap of Legends over graph (line, bar, horiz_bar only)
67 if ( isset ( $g [ 'attr' ][ 'PERCENT' ]) && $g [ 'attr' ][ 'PERCENT' ] && $type != 'xy' && $type != 'scatter' ) { $percent
= true ; } // Show data series as percent of total in series
68 if ( isset ( $g [ 'attr' ][ 'SHOW-VALUES' ]) && $g [ 'attr' ][ 'SHOW-VALUES' ]) { $show_values
= true ; } // Show the individual data values
69 if ( isset ( $g [ 'attr' ][ 'HIDE-GRID' ]) && $g [ 'attr' ][ 'HIDE-GRID' ]) { $hide_grid
= true ; } // Hide the y-axis gridlines
70 if ( isset ( $g [ 'attr' ][ 'HIDE-Y-AXIS' ]) && $g [ 'attr' ][ 'HIDE-Y-AXIS' ]) { $hide_y_axis
= true ; } // Hide the y-axis
73 // Antialias: If true - better quality curves, but graph line will only be 1px even in PDF 300dpi
74 // default=true for most except line and radar
75 if ( isset ( $g [ 'attr' ][ 'ANTIALIAS' ]) && ( $g [ 'attr' ][ 'ANTIALIAS' ]== '' || $g [ 'attr' ][ 'ANTIALIAS' ]== 0 )) { $antialias
= false ; }
76 else if ( isset ( $g [ 'attr' ][ 'ANTIALIAS' ]) && $g [ 'attr' ][ 'ANTIALIAS' ] > 0 ) { $antialias
= true ; }
77 else if ( $type == 'line' || $type == 'radar' ) { $antialias
= false ; }
78 else { $antialias
= true ; }
80 if ( $g [ 'attr' ][ 'DPI' ]) { $dpi
= intval ( $g
[ 'attr' ][ 'DPI' ]); }
81 if (! $dpi || $dpi < 50 || $dpi > 2400 ) { $dpi
= 150 ; } // Default dpi 150
82 $k = ( 0.2645 / 25.4 * $dpi );
85 global $JpgUseSVGFormat ;
86 if ( isset ( $JpgUseSVGFormat ) && $JpgUseSVGFormat ) {
88 $k = 1 ; // Overrides as Vector scale does not need DPI
94 if ( isset ( $g [ 'attr' ][ 'TITLE' ]) && $g [ 'attr' ][ 'TITLE' ]) { $title
= $g
[ 'attr' ][ 'TITLE' ]; }
96 if ( isset ( $g [ 'attr' ][ 'LABEL-X' ]) && $g [ 'attr' ][ 'LABEL-X' ]) { $xlabel
= $g
[ 'attr' ][ 'LABEL-X' ]; } // NOT IMPLEMENTED??????
97 if ( isset ( $g [ 'attr' ][ 'LABEL-Y' ]) && $g [ 'attr' ][ 'LABEL-Y' ]) { $ylabel
= $g
[ 'attr' ][ 'LABEL-Y' ]; }
99 if ( isset ( $g [ 'attr' ][ 'AXIS-X' ]) && $g [ 'attr' ][ 'AXIS-X' ]) { $xaxis
= strtolower ( $g
[ 'attr' ][ 'AXIS-X' ]); }
100 if (! in_array ( $xaxis , array ( 'text' , 'lin' , 'linear' , 'log' ))) { $xaxis
= 'text' ; } // Default=text
101 if ( $xaxis == 'linear' ) { $xaxis
= 'lin' ; }
103 if ( isset ( $g [ 'attr' ][ 'AXIS-Y' ]) && $g [ 'attr' ][ 'AXIS-Y' ]) { $yaxis
= strtolower ( $g
[ 'attr' ][ 'AXIS-Y' ]); }
104 if (! in_array ( $yaxis , array ( 'lin' , 'linear' , 'log' , 'percent' ))) { $yaxis
= 'lin' ; } // Default=lin
105 if ( $yaxis == 'percent' ) { $show_percent
= true ; $yaxis
= 'lin' ; } // Show percent sign on scales
106 if ( $yaxis == 'linear' ) { $yaxis
= 'lin' ; }
108 if ( $splines ) { $xaxis
= 'lin' ; }
109 $axes = $xaxis . $yaxis ; // e.g.textlin, textlog, loglog, loglin, linlog (XY)
112 if ( isset ( $g [ 'attr' ][ 'cWIDTH' ]) && $g [ 'attr' ][ 'cWIDTH' ]) { $w
=( $g
[ 'attr' ][ 'cWIDTH' ] / 0.2645 ); } // pixels
113 if ( isset ( $g [ 'attr' ][ 'cHEIGHT' ]) && $g [ 'attr' ][ 'cHEIGHT' ]) { $h
=( $g
[ 'attr' ][ 'cHEIGHT' ] / 0.2645 ); }
116 if ( isset ( $g [ 'attr' ][ 'SERIES' ]) && strtolower ( $g [ 'attr' ][ 'SERIES' ]) == 'rows' ) { $dataseries
= 'rows' ; }
117 else { $dataseries
= 'cols' ; }
119 // Defaults - define data
122 if ( $type == 'scatter' || $type == 'xy' ) {
123 if ( $dataseries == 'rows' ) { $rowbegin
= 1 ; }
124 else { $colbegin
= 1 ; }
129 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' ]; }
131 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' ]; }
133 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' ]; }
134 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' ]; }
136 $nr = count ( $g [ 'data' ]);
138 foreach ( $g [ 'data' ] AS $r ) {
140 foreach ( $r AS $c ) { $cc++
; }
143 if ( $colend == 0 ) { $colend
= $nc
; }
144 else if ( $colend < 0 ) { $colend
= $nc+$colend
; }
146 if ( $rowend == 0 ) { $rowend
= $nr
; }
147 else if ( $rowend < 0 ) { $rowend
= $nr+$rowend
; }
149 if ( $colend < $colbegin ) { $colend
= $colbegin
; }
150 if ( $rowend < $rowbegin ) { $rowend
= $rowbegin
; }
152 // if ($type == 'xy' || $type=='scatter') { $colstart=0; }
157 for ( $r =( $rowbegin-1 ); $r < $rowend ; $r ++
) {
158 for ( $c =( $colbegin-1 ); $c < $colend ; $c ++
) {
159 if ( isset ( $g [ 'data' ][ $r ][ $c ])) { $g
[ 'data' ][ $r
][ $c
] = floatval ( $g
[ 'data' ][ $r
][ $c
] ); }
160 else { $g
[ 'data' ][ $r
][ $c
] = 0 ; }
161 if ( $dataseries == 'rows' ) {
162 $data [( $r +
1 - $rowbegin )][( $c +
1 - $colbegin )] = $g [ 'data' ][ $r ][ $c ] ;
163 $totals [( $r +
1 - $rowbegin )] +
= $g [ 'data' ][ $r ][ $c ] ;
166 $data [( $c +
1 - $colbegin )][( $r +
1 - $rowbegin )] = $g [ 'data' ][ $r ][ $c ] ;
167 if ( isset ( $totals [( $c +
1 - $colbegin )])) { $totals
[( $c+
1 - $colbegin
)] +
= $g
[ 'data' ][ $r
][ $c
] ; }
168 else { $totals
[( $c+
1 - $colbegin
)] = $g
[ 'data' ][ $r
][ $c
] ; }
173 if ( $percent && $type != 'pie' && $type != 'pie3d' ) {
174 for ( $r = 0 ; $r < count ( $data ); $r ++
) {
175 for ( $c = 0 ; $c < count ( $data [ $r ]); $c ++
) {
176 $data [ $r ][ $c ] = $data [ $r ][ $c ]/ $totals [ $r ] * 100 ;
180 // Get Legends and labels
185 if ( $dataseries == 'cols' ) {
187 for ( $r =( $rowbegin-1 ); $r < $rowend ; $r ++
) {
188 $legends [( $r +
1 - $rowbegin )] = $g [ 'data' ][ $r ][ 0 ] ;
189 $longestlegend = max ( $longestlegend , strlen ( $g [ 'data' ][ $r ][ 0 ] ));
193 for ( $c =( $colbegin-1 ); $c < $colend ; $c ++
) {
194 $labels [( $c +
1 - $colbegin )] = $g [ 'data' ][ 0 ][ $c ] ;
195 $longestlabel = max ( $longestlabel , strlen ( $g [ 'data' ][ 0 ][ $c ] ));
199 else if ( $dataseries == 'rows' ) {
201 for ( $r =( $rowbegin-1 ); $r < $rowend ; $r ++
) {
202 $labels [( $r +
1 - $rowbegin )] = $g [ 'data' ][ $r ][ 0 ] ;
203 $longestlabel = max ( $longestlabel , strlen ( $g [ 'data' ][ $r ][ 0 ] ));
207 for ( $c =( $colbegin-1 ); $c < $colend ; $c ++
) {
208 $legends [( $c +
1 - $colbegin )] = $g [ 'data' ][ 0 ][ $c ] ;
209 $longestlegend = max ( $longestlegend , strlen ( $g [ 'data' ][ 0 ][ $c ] ));
215 $defsize [ 'pie' ] = array ( 'w' => 600 , 'h' => 300 );
216 $defsize [ 'pie3d' ] = array ( 'w' => 600 , 'h' => 300 );
217 $defsize [ 'radar' ] = array ( 'w' => 600 , 'h' => 300 );
218 $defsize [ 'line' ] = array ( 'w' => 600 , 'h' => 400 );
219 $defsize [ 'xy' ] = array ( 'w' => 600 , 'h' => 400 );
220 $defsize [ 'scatter' ] = array ( 'w' => 600 , 'h' => 400 );
221 $defsize [ 'bar' ] = array ( 'w' => 600 , 'h' => 400 );
222 $defsize [ 'horiz_bar' ] = array ( 'w' => 600 , 'h' => 500 );
225 // Use default ratios
226 if ( $w && ! $h ) { $h
= $w
* $defsize
[ $type
][ 'h' ]/ $defsize
[ $type
][ 'w' ]; }
227 if ( $h && ! $w ) { $w
= $h
* $defsize
[ $type
][ 'w' ]/ $defsize
[ $type
][ 'h' ]; }
228 if (! $h && ! $w ) { $w
= $defsize
[ $type
][ 'w' ]; $h
= $defsize
[ $type
][ 'h' ]; }
231 if ( count ( $data )> 0 && $type ) {
232 $figure_file = "graph_cache/" . rand ( 11111 , 999999999 ). "." . $img_type ;
233 if ( $bandw ) { $colours
= array ( 'snow1' , 'black' , 'snow4' , 'snow3' , 'snow2' , 'cadetblue4' , 'cadetblue3' , 'cadetblue1' , 'bisque4' , 'bisque2' , 'beige' ); }
234 else { $colours
= array ( 'cyan' , 'darkorchid4' , 'cadetblue3' , 'khaki1' , 'darkolivegreen2' , 'cadetblue4' , 'coral' , 'cyan4' , 'rosybrown3' , 'wheat1' ); }
235 $fills = array ( 'navy' , 'orange' , 'red' , 'yellow' , 'purple' , 'navy' , 'orange' , 'red' , 'yellow' , 'purple' );
236 $patterns = array ( PATTERN_DIAG1
, PATTERN_CROSS1
, PATTERN_STRIPE1
, PATTERN_DIAG3
, PATTERN_CROSS2
, PATTERN_DIAG2
, PATTERN_DIAG4
, PATTERN_CROSS3
, PATTERN_CROSS4
, PATTERN_STRIPE1
);
237 $markers = array ( MARK_DIAMOND
, MARK_SQUARE
, MARK_CIRCLE
, MARK_UTRIANGLE
, MARK_DTRIANGLE
, MARK_FILLEDCIRCLE
, MARK_CROSS
, MARK_STAR
, MARK_X
);
240 if ( $type == 'pie' || $type == 'pie3d' ) {
241 $graph = new PieGraph (( $w * $k ),( $h * $k ));
243 else if ( $type == 'radar' ) {
244 $graph = new RadarGraph (( $w * $k ),( $h * $k ));
247 $graph = new Graph (( $w * $k ),( $h * $k ));
251 // $graph->img->SetImgFormat($img_type) ;
252 // if (strtoupper($img_type)=='JPEG') { $graph->img->SetQuality(90); }
253 if ( $antialias ) { $graph
-> img
-> SetAntiAliasing (); }
254 $graph- > SetShadow ( true , 2 * $k );
255 $graph- > SetMarginColor ( "white" );
257 $graph- > title
-> Set ( $title );
258 $graph- > title
-> SetMargin ( 10 * $k );
259 $graph- > title
-> SetFont ( FF_USERFONT
, FS_BOLD
, 11 * $k );
260 $graph- > title
-> SetColor ( "black" );
261 $graph- > legend
-> SetLineSpacing ( 3 * $k );
262 $graph- > legend
-> SetMarkAbsSize ( 6 * $k );
263 $graph- > legend
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
265 // Set GRAPH IMAGE MARGINS
266 if ( $type == 'pie' || $type == 'pie3d' ) {
270 if ( $longestlegend ) { // if legend showing
271 $pposxabs -= ((( $longestlegend * 5 ) +
20 ) / 2 );
273 $pposx = ( $pposxabs / $w );
274 $graph- > legend
-> Pos ( 0.02 , 0.5 , 'right' , 'center' );
276 else if ( $type == 'radar' ) {
280 if ( $longestlabel ) { // if legend showing
281 $pposxabs -= ((( $longestlabel * 5 ) +
20 ) / 2 );
283 $pposx = ( $pposxabs / $w );
284 $graph- > legend
-> Pos ( 0.02 , 0.5 , 'right' , 'center' );
286 else if ( $type == 'xy' || $type == 'scatter' ) {
291 $xaxislblmargin = $pmb - 30 ;
292 $yaxislblmargin = $pml - 15 ;
293 $graph- > legend
-> Pos ( 0.02 , 0.1 , 'right' , 'top' );
295 else if ( $type == 'line' || $type == 'bar' ) {
301 $ll = ( $longestlegend * 5 ); // 45 degrees 8pt fontsize
302 if ( $ll > 5 || ( $ll > 3 && count ( $data )> 10 )) {
303 $pmb = max ( $pmb , $ll +
30 );
306 $xaxislblmargin = $pmb - 30 ;
307 $yaxislblmargin = $pml - 15 ;
308 if ( $longestlabel && ! $overlap ) { // if legend showing
309 $pmr = ((( $longestlabel * 5 ) +
40 ));
311 $graph- > legend
-> Pos ( 0.02 , 0.1 , 'right' , 'top' );
313 else if ( $type == 'horiz_bar' ) {
318 $ll = ( $longestlegend * 6.5 ); // 8pt fontsize
319 $pml = max ( $pml , $ll +
20 );
320 $xaxislblmargin = $pml - 20 ;
321 $yaxislblmargin = $pmb - 15 ;
322 if ( $longestlabel && ! $overlap ) { // if legend showing
323 $pmr = ((( $longestlabel * 5 ) +
40 ));
325 $graph- > legend
-> Pos ( 0.02 , 0.1 , 'right' , 'top' );
330 if ( $type == 'pie' ) {
331 $p1 = new PiePlot ( $data [ 0 ]);
332 $p1- > SetSliceColors ( $colours );
335 $p1- > value
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
336 if ( $percent ) { $p1
-> SetLabelType ( PIE_VALUE_PERADJ
); } //PIE_VAL_PER = default
337 else { $p1
-> SetLabelType ( PIE_VALUE_ABS
); }
338 if ( $percent || $show_percent ) { $p1
-> value
-> SetFormat ( "%d%%" ); }
339 else { $p1
-> value
-> SetFormat ( "%s" ); }
340 // Enable and set policy for guide-lines. Make labels line up vertically
341 $p1- > SetGuideLines ( true );
342 $p1- > SetGuideLinesAdjust ( 1.5 );
344 else { $p1
-> value
-> Show ( false ); }
345 $p1- > SetLegends ( $legends );
346 $p1- > SetSize ( $psize );
347 $p1- > SetCenter ( $pposx , $pposy );
349 $graph- > subtitle
-> Set ( $labels [ 0 ]);
350 $graph- > subtitle
-> SetMargin ( 10 * $k );
351 $graph- > subtitle
-> SetFont ( FF_USERFONT
, FS_BOLD
, 11 * $k );
352 $graph- > subtitle
-> SetColor ( "black" );
356 else if ( $type == 'pie3d' ) {
357 $p1 = new PiePlot3d ( $data [ 0 ]);
358 $p1- > SetSliceColors ( $colours );
360 $p1- > value
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
361 if ( $percent ) { $p1
-> SetLabelType ( PIE_VALUE_PERADJ
); } //PIE_VAL_PER = default
362 else { $p1
-> SetLabelType ( PIE_VALUE_ABS
); }
363 if ( $percent || $show_percent ) { $p1
-> value
-> SetFormat ( "%d%%" ); }
364 else { $p1
-> value
-> SetFormat ( "%s" ); }
366 else { $p1
-> value
-> Show ( false ); }
367 $p1- > SetLegends ( $legends );
369 $p1- > SetSize ( $psize );
370 $p1- > SetCenter ( $pposx , $pposy );
373 $graph- > subtitle
-> Set ( $labels [ 0 ]);
374 $graph- > subtitle
-> SetMargin ( 10 * $k );
375 $graph- > subtitle
-> SetFont ( FF_USERFONT
, FS_BOLD
, 11 * $k );
376 $graph- > subtitle
-> SetColor ( "black" );
382 else if ( $type == 'radar' ) {
383 $graph- > SetSize ( $psize );
384 $graph- > SetPos ( $pposx , $pposy );
386 $graph- > SetTitles ( $legends ); // labels each axis
388 $graph- > axis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
389 $graph- > axis
-> title
-> SetMargin ( 5 * $k );
390 $graph- > axis
-> SetWeight ( 1 * $k );
391 $graph- > axis
-> HideLabels ();
392 $graph- > axis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 6 * $k );
393 $graph- > HideTickMarks ();
396 foreach ( $data AS $series => $dat ) {
398 foreach ( $data [ $series ] AS $row ) { $rdata
[] = $row
; }
399 if ( count ( $rdata )< 3 ) { die ( "ERROR::Graph::Cannot create a Radar Plot with less than 3 data points." ); }
400 // Create the radar plot
401 $bplot = new RadarPlot ( $rdata );
402 $bplot- > mark
-> SetType ( $markers [ $series ]);
403 $bplot- > mark
-> SetFillColor ( $colours [ $series ]);
404 $bplot- > mark
-> SetWidth ( 3 * $k );
405 $bplot- > SetColor ( $colours [ $series ]);
406 if ( $series == 0 ) { $bplot
-> SetFillColor ( 'lightred' ); }
407 else { $bplot
-> SetFill ( false ); }
408 $bplot- > SetLineWeight ( 1 * $k );
409 $bplot- > SetLegend ( $labels [ $series ]);
410 if ( $bandw ) { $bplot
-> SetShadow ( "gray5" ); }
415 else if ( $type == 'line' ) {
417 $graph- > img
-> SetMargin ( $pml * $k , $pmr * $k , $pmt * $k , $pmb * $k ); // LRTB
418 $graph- > SetScale ( $axes );
419 $graph- > yaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
422 $graph- > yaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
423 $graph- > yaxis
-> SetTitle ( $ylabel , 'middle' );
424 $graph- > yaxis
-> SetTitleMargin ( $yaxislblmargin * $k );
427 $graph- > yaxis
-> SetLabelMargin ( 4 * $k );
428 if ( $percent || $show_percent ) { $graph
-> yaxis
-> SetLabelFormat ( '%d%%' ); } // Percent
430 // Show 0 label on Y-axis (default is not to show)
431 $graph- > yscale
-> ticks
-> SupressZeroLabel ( true );
432 if ( $hide_y_axis ) { $graph
-> yaxis
-> Hide (); }
433 if ( $hide_grid ) { $graph
-> ygrid
-> Show ( false ); }
435 // Setup X-axis labels
436 $graph- > xaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
437 $graph- > xaxis
-> SetTickLabels ( $legends );
438 $graph- > xaxis
-> SetLabelAngle ( $xlangle );
439 $graph- > xaxis
-> SetLabelMargin ( 4 * $k );
442 $graph- > xaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
443 $graph- > xaxis
-> SetTitle ( $xlabel , 'middle' );
444 $graph- > xaxis
-> SetTitleMargin ( $xaxislblmargin * $k );
446 foreach ( $data AS $series => $rdata ) {
447 $bplot = new LinePlot ( $rdata );
448 $bplot- > mark
-> SetType ( $markers [ $series ]);
449 $bplot- > mark
-> SetFillColor ( $colours [ $series ]);
450 $bplot- > mark
-> SetWidth ( 4 * $k );
452 $bplot- > value
-> Show (); // Not if scatter
453 $bplot- > value
-> SetMargin ( 6 * $k );
454 $bplot- > value
-> SetColor ( "darkred" );
455 $bplot- > value
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
456 if ( $percent || $show_percent ) { $bplot
-> value
-> SetFormat ( '%d%%' ); }
457 else { $bplot
-> value
-> SetFormat ( "%s" ); }
459 // Set color for each line
460 $bplot- > SetColor ( $colours [ $series ]);
461 $bplot- > SetWeight ( 2 * $k );
462 $bplot- > SetLegend ( $labels [ $series ]);
463 if ( $bandw ) { $bplot
-> SetShadow ( "gray5" ); }
464 // Indent the X-scale so the first and last point doesn't fall on the edges
471 else if ( $type == 'xy' || $type == 'scatter' ) {
473 $graph- > img
-> SetMargin ( $pml * $k , $pmr * $k , $pmt * $k , $pmb * $k ); // LRTB
474 $graph- > SetScale ( $axes );
475 // Setup font for axis
476 $graph- > yaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
479 $graph- > yaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
480 $graph- > yaxis
-> SetTitleMargin ( $yaxislblmargin * $k );
481 $graph- > yaxis
-> SetTitle ( $labels [ 1 ], 'middle' );
485 $graph- > yaxis
-> SetLabelMargin ( 4 * $k );
486 if ( $percent || $show_percent ) { $graph
-> yaxis
-> SetLabelFormat ( '%d%%' ); } // Percent
488 // Show 0 label on Y-axis (default is not to show)
489 $graph- > yscale
-> ticks
-> SupressZeroLabel ( true );
490 // Just let the maximum be autoscaled
491 $graph- > yaxis
-> scale
-> SetAutoMin ( 0 );
492 if ( $hide_y_axis ) { $graph
-> yaxis
-> Hide (); }
493 if ( $hide_grid ) { $graph
-> ygrid
-> Show ( false ); }
495 // Setup X-axis labels
496 $graph- > xaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
497 // mPDF 2.5 Corrects labelling of x-axis
498 // $graph->xaxis->SetTickLabels($legends);
499 $graph- > xaxis
-> SetLabelAngle ( 50 );
500 $graph- > xaxis
-> SetLabelMargin ( 4 * $k );
503 $graph- > xaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
504 $graph- > xaxis
-> SetTitleMargin ( $xaxislblmargin * $k );
505 $graph- > xaxis
-> SetTitle ( $labels [ 0 ], 'middle' );
508 // Create the bar plot
510 if ( $splines && $type == 'xy' ) {
511 $spline = new Spline ( $data [ 0 ], $data [ 1 ]);
512 list ( $newx , $newy ) = $spline- > Get ( 100 );
521 $bplot = new LinePlot ( $newy , $newx );
522 // Set color for each line
523 $bplot- > SetColor ( $fills [ 0 ]);
524 $bplot- > SetWeight ( 4 * $k );
525 if ( $bandw ) { $bplot
-> SetShadow ( "gray5" ); }
530 $cplot = new ScatterPlot ( $data [ 1 ], $data [ 0 ]);
532 $cplot- > mark
-> SetType ( $markers [ 0 ]);
533 $cplot- > mark
-> SetFillColor ( $fills [ 0 ]);
534 $cplot- > mark
-> SetWidth ( 8 * $k );
537 if ( $type == 'xy' ) { $cplot
-> value
-> Show (); } // Not if scatter
538 $cplot- > value
-> SetMargin ( 8 * $k );
539 $cplot- > value
-> SetColor ( "darkred" );
540 $cplot- > value
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 6 * $k );
542 if ( $percent || $show_percent ) { $cplot
-> value
-> SetFormat ( '%d%%' ); }
543 else { $cplot
-> value
-> SetFormat ( "%s" ); }
546 // Set color for each line
547 $cplot- > SetColor ( $fills [ 0 ]);
548 $cplot- > SetWeight ( 4 * $k );
549 if ( $bandw ) { $cplot
-> SetShadow ( "gray5" ); }
554 else if ( $type == 'bar' ) {
556 $graph- > img
-> SetMargin ( $pml * $k , $pmr * $k , $pmt * $k , $pmb * $k ); // LRTB
557 $graph- > SetScale ( $axes );
559 $graph- > yaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
560 if ( $hide_y_axis ) { $graph
-> yaxis
-> Hide (); }
561 if ( $hide_grid ) { $graph
-> ygrid
-> Show ( false ); }
562 $graph- > yaxis
-> SetLabelMargin ( 4 * $k );
564 $graph- > yaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
565 $graph- > yaxis
-> SetTitle ( $ylabel , 'middle' );
566 $graph- > yaxis
-> SetTitleMargin ( $yaxislblmargin * $k );
568 // Show 0 label on Y-axis (default is not to show)
569 $graph- > yscale
-> ticks
-> SupressZeroLabel ( false );
570 // Setup X-axis labels
571 $graph- > xaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
572 $graph- > xaxis
-> SetTickLabels ( $legends );
573 $graph- > xaxis
-> SetLabelAngle ( $xlangle );
574 $graph- > xaxis
-> SetLabelMargin ( 4 * $k );
577 $graph- > xaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
578 $graph- > xaxis
-> SetTitle ( $xlabel , 'middle' );
579 $graph- > xaxis
-> SetTitleMargin ( $xaxislblmargin * $k );
583 foreach ( $data AS $series => $dat ) {
585 foreach ( $data [ $series ] AS $row ) { $rdata
[] = $row
; }
587 // Create the bar plot
588 $bplot = new BarPlot ( $rdata );
589 $bplot- > SetWidth ( 0.6 ); // for SINGLE??
590 // Setup color for gradient fill style
591 if ( $bandw ) { $bplot
-> SetPattern ( $patterns
[ $series
]); }
592 else { $bplot
-> SetFillGradient ( $fills
[ $series
], "#EEEEEE" , GRAD_LEFT_REFLECTION
); }
594 // Set color for the frame of each bar
595 $bplot- > SetColor ( "darkgray" );
596 $bplot- > SetLegend ( $labels [ $series ]);
597 if ( $bandw ) { $bplot
-> SetShadow ( "gray5" ); }
599 $bplot- > value
-> Show ();
600 $bplot- > value
-> SetMargin ( 6 * $k );
601 $bplot- > value
-> SetColor ( "darkred" );
602 $bplot- > value
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
603 if ( $percent || $show_percent ) { $bplot
-> value
-> SetFormat ( '%d%%' ); }
604 else { $bplot
-> value
-> SetFormat ( "%s" ); }
609 if ( count ( $data )== 1 ) {
610 $graph- > Add ( $group [ 0 ]);
613 // Create the grouped bar plot
615 $gbplot = new AccBarPlot ( $group );
618 $gbplot = new GroupBarPlot ( $group );
620 $graph- > Add ( $gbplot );
623 else if ( $type == 'horiz_bar' ) {
624 $graph- > SetScale ( $axes );
625 $graph- > Set90AndMargin ( $pml * $k , $pmr * $k , $pmt * $k , $pmb * $k ); // LRTB
628 $graph- > yaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
629 $graph- > yaxis
-> SetLabelMargin ( 4 * $k );
631 $graph- > yaxis
-> SetPos ( 'max' ); // Intersect at top of x-axis i.e. y axis is at bottom
632 // First make the labels look right
633 $graph- > yaxis
-> SetLabelAlign ( 'center' , 'top' );
634 if ( $percent || $show_percent ) { $graph
-> yaxis
-> SetLabelFormat ( '%d%%' ); }
635 $graph- > yaxis
-> SetLabelSide ( SIDE_RIGHT
);
636 $graph- > yaxis
-> scale
-> SetGrace ( 10 ); // sets 10% headroom
637 if ( $hide_y_axis ) { $graph
-> yaxis
-> Hide (); }
638 if ( $hide_grid ) { $graph
-> ygrid
-> Show ( false ); }
640 // The fix the tick marks
641 $graph- > yaxis
-> SetTickSide ( SIDE_LEFT
);
643 $graph- > yaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
644 $graph- > yaxis
-> SetTitle ( $ylabel , 'middle' );
645 $graph- > yaxis
-> SetTitleMargin ( $yaxislblmargin * $k );
646 // Finally setup the title
647 $graph- > yaxis
-> SetTitleSide ( SIDE_RIGHT
);
648 // To align the title to the right use :
649 $graph- > yaxis
-> title
-> Align ( 'right' );
650 $graph- > yaxis
-> title
-> SetAngle ( 0 );
654 // Show 0 label on Y-axis (default is not to show)
655 $graph- > yscale
-> ticks
-> SupressZeroLabel ( false );
656 // Setup X-axis labels
657 $graph- > xaxis
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
658 $graph- > xaxis
-> title
-> SetAngle ( 90 );
659 $graph- > xaxis
-> SetTickLabels ( $legends );
660 $graph- > xaxis
-> SetLabelMargin ( 4 * $k );
663 $graph- > xaxis
-> title
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
664 $graph- > xaxis
-> SetTitleMargin ( $xaxislblmargin * $k );
665 $graph- > xaxis
-> SetTitle ( $xlabel , 'middle' );
668 foreach ( $data AS $series => $dat ) {
670 foreach ( $data [ $series ] AS $row ) { $rdata
[] = $row
; }
671 // Create the bar pot
672 $bplot = new BarPlot ( $rdata );
673 $bplot- > SetWidth ( 0.6 ); // for SINGLE??
674 // Setup color for gradient fill style
675 if ( $bandw ) { $bplot
-> SetPattern ( $patterns
[ $series
]); }
676 else { $bplot
-> SetFillGradient ( $fills
[ $series
], "#EEEEEE" , GRAD_LEFT_REFLECTION
); }
678 // Set color for the frame of each bar
679 $bplot- > SetColor ( "darkgray" );
680 $bplot- > SetLegend ( $labels [ $series ]);
681 if ( $bandw ) { $bplot
-> SetShadow ( "gray5" ); }
683 $bplot- > value
-> Show ();
684 $bplot- > value
-> SetMargin ( 6 * $k );
685 $bplot- > value
-> SetColor ( "darkred" );
686 $bplot- > value
-> SetFont ( FF_USERFONT
, FS_NORMAL
, 8 * $k );
687 if ( $percent || $show_percent ) { $bplot
-> value
-> SetFormat ( '%d%%' ); }
688 else { $bplot
-> value
-> SetFormat ( "%s" ); }
693 if ( count ( $data )== 1 ) {
694 $graph- > Add ( $group [ 0 ]);
697 // Create the grouped bar plot
699 $gbplot = new AccBarPlot ( $group );
702 $gbplot = new GroupBarPlot ( $group );
704 $graph- > Add ( $gbplot );
708 $graph- > Stroke ( _MPDF_PATH
. $figure_file );
709 $srcpath = str_replace ( " \\ " , "/" , dirname ( __FILE__
)) . "/" ;
710 $srcpath .= $figure_file ;
711 return array ( 'file' => $srcpath , 'w' => $w , 'h' => $h );
716 //======================================================================================================
717 //======================================================================================================
718 //======================================================================================================
719 //======================================================================================================