-
Notifications
You must be signed in to change notification settings - Fork 0
/
phplotv4.php
2641 lines (2260 loc) · 81.4 KB
/
phplotv4.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Copyright (C) 1998, 1999, 2000, 2001 Afan Ottenheimer. Released under
the GPL and PHP licenses as stated in the the README file which
should have been included with this document.
World Coordinates are the XY coordinates relative to the
axis origin that can be drawn. Not the device (pixel) coordinates
which in GD is relative to the origin at the upper left
side of the image.
*/
//PHPLOT Version 4.4.6
//Requires PHP 3.0.2 or later
class PHPlot{
private $is_inline = 0; //0 = Sends headers, 1 = sends just raw image data
private $browser_cache = '1'; // 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image)
// (only if is_inline = 0 also)
private $session_set = ''; //Do not change
private $scale_is_set = ''; //Do not change
private $draw_plot_area_background = '';
private $image_width; //Total Width in Pixels
private $image_height; //Total Height in Pixels
private $image_border_type = ''; //raised, plain, ''
private $x_left_margin;
private $y_top_margin;
private $x_right_margin;
private $y_bot_margin;
private $plot_area = array(5,5,600,400);
private $x_axis_position = 0; //Where to draw the X_axis (world coordinates)
private $y_axis_position = ''; //Leave blank for Y axis at left of plot. (world coord.)
private $xscale_type = 'linear'; //linear or log
private $yscale_type = 'linear';
//Use for multiple plots per image
private $print_image = 1; //Used for multiple charts per image.
//Fonts
private $use_ttf = 0; //Use TTF fonts (1) or not (0)
private $font_path = './'; //To be added
private $font = './benjamingothic.ttf';
///////////Fonts: Small/Generic
private $small_ttffont_size = 12; //
//non-ttf
private $small_font = 2; // fonts = 1,2,3,4 or 5
private $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8)
private $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12)
////////// Fonts:Title
private $title_ttffont = './benjamingothic.ttf';
private $title_ttffont_size = 14;
private $title_angle= 0;
//non-ttf
private $title_font = '4'; // fonts = 1,2,3,4,5
////////////// Fonts:Axis
private $axis_ttffont = './benjamingothic.ttf';
private $axis_ttffont_size = 8;
private $x_datalabel_angle = 0;
//non-ttf
private $axis_font = 2;
////////////////Fonts:Labels of Data
private $datalabel_font = '2';
//////////////// Fonts:Labels (Axis Titles)
private $x_label_ttffont = './benjamingothic.ttf';
private $x_label_ttffont_size = '12';
private $x_label_angle = '0';
private $y_label_ttffont = './benjamingothic.ttf';
private $y_label_ttffont_size = '12';
private $y_label_angle = 90;
private $y_label_width = '';
//Formats
private $file_format = 'png';
private $file_name = ''; //For output to a file instead of stdout
//Plot Colors
private $shading = 0;
private $color_array = 1; //1 = include small list
//2 = include large list
//array = define your own color translation. See rgb.inc.php and SetRGBArray
private $bg_color;
private $plot_bg_color;
private $grid_color;
private $light_grid_color;
private $tick_color;
private $title_color;
private $label_color;
private $text_color;
private $i_light = '';
//Data
private $data_type = 'text-data'; //text-data, data-data-error, data-data
private $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline
private $line_width = 2;
private $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines
private $data_color = ''; //array('blue','green','yellow',array(0,0,0));
private $data_border_color = '';
private $label_scale_position = '.5'; //1 = top, 0 = bottom
private $group_frac_width = '.7'; //value from 0 to 1 = width of bar
private $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0
private $point_size = 10;
private $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline
private $error_bar_shape = 'tee'; //tee, line
private $error_bar_size = 5; //right left size of tee
private $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness
private $error_bar_color = '';
private $data_values;
private $plot_border_type = 'full'; //left, none, full
private $plot_area_width = '';
private $number_x_points;
private $plot_min_x; // Max and min of the plot area
private $plot_max_x= ''; // Max and min of the plot area
private $plot_min_y= ''; // Max and min of the plot area
private $plot_max_y = ''; // Max and min of the plot area
private $min_y = '';
private $max_y = '';
private $max_x = 10; //Must not be = 0;
private $y_precision = '1';
private $x_precision = '1';
private $si_units = '';
//Labels
private $draw_data_labels = '0';
private $legend = ''; //an array
private $legend_x_pos = '';
private $legend_y_pos = '';
private $title_txt = "";
private $y_label_txt = '';
private $x_label_txt = "";
//DataAxis Labels (on each axis)
private $y_grid_label_type = 'data'; //data, none, time, other
private $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both
private $x_grid_label_type = 'data'; //data, title, none, time, other
private $draw_x_data_labels = ''; // 0=false, 1=true, ""=let program decide
private $x_time_format = "%H:%m:%s"; //See http://www.php.net/manual/html/function.strftime.html
private $x_datalabel_maxlength = 10;
//Tick Formatting
private $tick_length = '10'; //pixels: tick length from axis left/downward
//tick_length2 to be implemented
//private $tick_length2 = ''; //pixels: tick length from axis line rightward/upward
private $draw_vert_ticks = 1; //1 = draw ticks, 0 = don't draw ticks
private $num_vert_ticks = '';
private $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both.
private $vert_tick_position = 'both'; //plotright=(right of plot only), plotleft=(left of plot only),
//both = (both left and right of plot), yaxis=(crosses y axis)
private $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both.
private $num_horiz_ticks='';
private $skip_top_tick = '0';
private $skip_bottom_tick = '0';
//Grid Formatting
private $draw_x_grid = 0;
private $draw_y_grid = 1;
//BEGIN CODE
//////////////////////////////////////////////////////
//Constructor: Setup Img pointer, Colors and Size of Image
function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") {
$this->SetRGBArray('2');
$this->background_done = 0; //Set to 1 after background image first drawn
if ($which_output_file != "") { $this->SetOutputFile($which_output_file); };
if ($which_input_file != "") {
$this->SetInputFile($which_input_file) ;
} else {
$this->SetImageArea($which_width, $which_height);
$this->InitImage();
}
if ( ($this->session_set == 1) && ($this->img == "") ) { //For sessions
//Do nothing
} else {
$this->SetDefaultColors();
}
$this->SetIndexColors();
}
//Set up the image and colors
function InitImage() {
//if ($this->img) {
// ImageDestroy($this->img);
//}
$this->img = ImageCreate($this->image_width, $this->image_height);
return true;
}
function SetBrowserCache($which_browser_cache) { //Submitted by Thiemo Nagel
$this->browser_cache = $which_browser_cache;
return true;
}
function SetPrintImage($which_pi) {
$this->print_image = $which_pi;
return true;
}
function SetIsInline($which_ii) {
$this->is_inline = $which_ii;
return true;
}
function SetUseTTF($which_ttf) {
$this->use_ttf = $which_ttf;
return true;
}
function SetTitleFontSize($which_tfs) {
//TTF
$this->title_ttffont_size = $which_tfs; //pt size
//Non-TTF settings
if (($which_tfs > 5) && (!$this->use_ttf)) {
$this->DrawError('Non-TTF font size must be 1,2,3,4 or 5');
return false;
} else {
$this->title_font = $which_tfs;
//$this->title_font_height = ImageFontHeight($which_tfs) // height in pixels
//$this->title_font_width = ImageFontWidth($which_tfs); // width in pixels
}
return true;
}
function SetLineStyles($which_sls){
$this->line_style = $which_sls;
return true;
}
function SetLegend($which_leg){
if (is_array($which_leg)) {
$this->legend = $which_leg;
return true;
} else {
$this->DrawError('Error: SetLegend argument must be an array');
return false;
}
}
function SetLegendPixels($which_x,$which_y,$which_type) {
//which_type not yet used
$this->legend_x_pos = $which_x;
$this->legend_y_pos = $which_y;
return true;
}
function SetLegendWorld($which_x,$which_y,$which_type='') {
//which_type not yet used
//Must be called after scales are set up.
if ($this->scale_is_set != 1) { $this->SetTranslation(); };
$this->legend_x_pos = $this->xtr($which_x);
$this->legend_y_pos = $this->ytr($which_y);
return true;
}
/* ***************************************
function SetFileFormat($which_file_format) { //Only works with PHP4
$asked = strtolower($which_file_format);
if( $asked =="jpg" || $asked =="png" || $asked =="gif" || $asked =="wbmp" ) {
if( $asked=="jpg" && !(imagetypes() & IMG_JPG) )
return false;
elseif( $asked=="png" && !(imagetypes() & IMG_PNG) )
return false;
elseif( $asked=="gif" && !(imagetypes() & IMG_GIF) )
return false;
elseif( $asked=="wbmp" && !(imagetypes() & IMG_WBMP) )
return false;
else {
$this->img_format=$asked;
return true;
}
}
else
return false;
}
*************************************** */
function SetFileFormat($which_file_format) {
//eventually test to see if that is supported - if not then return false
$asked = strtolower(trim($which_file_format));
if( ($asked=='jpg') || ($asked=='png') || ($asked=='gif') || ($asked=='wbmp') ) {
$this->file_format = $asked;
return true;
} else {
return false;
}
}
function SetInputFile($which_input_file) {
//$this->SetFileFormat($which_frmt);
$size = GetImageSize($which_input_file);
$input_type = $size[2];
switch($input_type) { //After SetFileFormat is in lower case
case "1":
$im = @ImageCreateFromGIF ($which_input_file);
if (!$im) { // See if it failed
$this->PrintError("Unable to open $which_input_file as a GIF");
return false;
}
break;
case "3":
$im = @ImageCreateFromPNG ($which_input_file);
if (!$im) { // See if it failed
$this->PrintError("Unable to open $which_input_file as a PNG");
return false;
}
break;
case "2":
$im = @ImageCreateFromJPEG ($which_input_file);
if (!$im) { // See if it failed
$this->PrintError("Unable to open $which_input_file as a JPG");
return false;
}
break;
default:
$this->PrintError('Please select wbmp,gif,jpg, or png for image type!');
return false;
break;
}
//Get Width and Height of Image
$this->SetImageArea($size[0],$size[1]);
$this->img = $im;
return true;
}
function SetOutputFile($which_output_file) {
$this->output_file = $which_output_file;
return true;
}
function SetImageArea($which_iw,$which_ih) {
//Note this is now an Internal function - please set w/h via PHPlot()
$this->image_width = $which_iw;
$this->image_height = $which_ih;
return true;
}
function SetYAxisPosition($which_pos) {
$this->y_axis_position = $which_pos;
return true;
}
function SetXAxisPosition($which_pos) {
$this->x_axis_position = $which_pos;
return true;
}
function SetXTimeFormat($which_xtf) {
$this->x_time_format = $which_xtf;
return true;
}
function SetXDataLabelMaxlength($which_xdlm) {
if ($which_xdlm >0 ) {
$this->x_datalabel_maxlength = $which_xdlm;
return true;
} else {
return false;
}
}
function SetXDataLabelAngle($which_xdla) {
$this->x_datalabel_angle = $which_xdla;
return true;
}
function SetXScaleType($which_xst) {
$this->xscale_type = $which_xst;
return true;
}
function SetYScaleType($which_yst) {
$this->yscale_type = $which_yst;
if ($this->x_axis_position <= 0) {
$this->x_axis_position = 1;
}
return true;
}
function SetPrecisionX($which_prec) {
$this->x_precision = $which_prec;
return true;
}
function SetPrecisionY($which_prec) {
$this->y_precision = $which_prec;
return true;
}
function SetIndexColors() { //Internal Method called to set colors and preserve state
//These are the colors of the image that are used. They are initialized
//to work with sessions and PHP.
$this->ndx_i_light = $this->SetIndexColor($this->i_light);
$this->ndx_i_dark = $this->SetIndexColor($this->i_dark);
$this->ndx_bg_color= $this->SetIndexColor($this->bg_color);
$this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color);
$this->ndx_title_color= $this->SetIndexColor($this->title_color);
$this->ndx_tick_color= $this->SetIndexColor($this->tick_color);
$this->ndx_label_color= $this->SetIndexColor($this->label_color);
$this->ndx_text_color= $this->SetIndexColor($this->text_color);
$this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color);
$this->ndx_grid_color= $this->SetIndexColor($this->grid_color);
reset($this->error_bar_color);
unset($ndx_error_bar_color);
$i = 0;
while (list(, $col) = each($this->error_bar_color)) {
$this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
$i++;
}
//reset($this->data_border_color);
unset($ndx_data_border_color);
$i = 0;
while (list(, $col) = each($this->data_border_color)) {
$this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
$i++;
}
//reset($this->data_color);
unset($ndx_data_color);
$i = 0;
while (list(, $col) = each($this->data_color)) {
$this->ndx_data_color[$i] = $this->SetIndexColor($col);
$i++;
}
return true;
}
function SetDefaultColors() {
$this->i_light = array(194,194,194);
$this->i_dark = array(100,100,100);
$this->SetPlotBgColor(array(222,222,222));
$this->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values
$this->SetLabelColor('black');
$this->SetTextColor('black');
$this->SetGridColor('black');
$this->SetLightGridColor(array(175,175,175));
$this->SetTickColor('black');
$this->SetTitleColor(array(0,0,0)); // Can be array or name
$this->data_color = array('blue','green','yellow','red','orange');
$this->error_bar_color = array('blue','green','yellow','red','orange');
$this->data_border_color = array('black');
$this->session_set = 1; //Mark it down for PHP session() usage.
}
function PrintImage() {
if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
header('Cache-Control: no-cache, max-age=1, must-revalidate');
header('Pragma: no-cache');
}
switch($this->file_format) {
case "png":
if ($this->is_inline == 0) {
Header('Content-type: image/png');
}
if ($this->is_inline == 1 && $this->output_file != "") {
ImagePng($this->img,$this->output_file);
} else {
ImagePng($this->img);
}
break;
case "jpg":
if ($this->is_inline == 0) {
Header('Content-type: image/jpeg');
}
if ($this->is_inline == 1 && $this->output_file != "") {
ImageJPEG($this->img,$this->output_file);
} else {
ImageJPEG($this->img);
}
break;
case "gif":
if ($this->is_inline == 0) {
Header('Content-type: image/gif');
}
if ($this->is_inline == 1 && $this->output_file != "") {
ImageGIF($this->img,$this->output_file);
} else {
ImageGIF($this->img);
}
break;
case "wbmp":
if ($this->is_inline == 0) {
Header('Content-type: image/wbmp');
}
if ($this->is_inline == 1 && $this->output_file != "") {
ImageWBMP($this->img,$this->output_file);
} else {
ImageWBMP($this->img);
}
break;
default:
$this->PrintError('Please select an image type!<br>');
break;
}
ImageDestroy($this->img);
return true;
}
function DrawBackground() {
//if ($this->img == "") { $this->InitImage(); };
if ($this->background_done == 0) { //Don't draw it twice if drawing two plots on one image
ImageFilledRectangle($this->img, 0, 0,
$this->image_width, $this->image_height, $this->ndx_bg_color);
$this->background_done = 1;
}
return true;
}
function DrawImageBorder() {
switch ($this->image_border_type) {
case "raised":
ImageLine($this->img,0,0,$this->image_width-1,0,$this->ndx_i_light);
ImageLine($this->img,1,1,$this->image_width-2,1,$this->ndx_i_light);
ImageLine($this->img,0,0,0,$this->image_height-1,$this->ndx_i_light);
ImageLine($this->img,1,1,1,$this->image_height-2,$this->ndx_i_light);
ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
ImageLine($this->img,0,$this->image_height-1,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
ImageLine($this->img,$this->image_width-2,1,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
ImageLine($this->img,1,$this->image_height-2,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
break;
case "plain":
ImageLine($this->img,0,0,$this->image_width,0,$this->ndx_i_dark);
ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height,$this->ndx_i_dark);
ImageLine($this->img,$this->image_width-1,$this->image_height-1,0,$this->image_height-1,$this->ndx_i_dark);
ImageLine($this->img,0,0,0,$this->image_height,$this->ndx_i_dark);
break;
default:
break;
}
return true;
}
function SetPlotBorderType($which_pbt) {
$this->plot_border_type = $which_pbt; //left, none, anything else=full
}
function SetImageBorderType($which_sibt) {
$this->image_border_type = $which_sibt; //raised, plain
}
function SetDrawPlotAreaBackground($which_dpab) {
$this->draw_plot_area_background = $which_dpab; // 1=true or anything else=false
}
function SetDrawDataLabels($which_ddl) { //Draw next to datapoints
$this->draw_data_labels = $which_ddl; // 1=true or anything else=false
}
function SetDrawXDataLabels($which_dxdl) { //Draw on X Axis
$this->draw_x_data_labels = $which_dxdl; // 1=true or anything else=false
}
function SetDrawYGrid($which_dyg) {
$this->draw_y_grid = $which_dyg; // 1=true or anything else=false
}
function SetDrawXGrid($which_dxg) {
$this->draw_x_grid = $which_dxg; // 1=true or anything else=false
}
function SetYGridLabelType($which_yglt) {
$this->y_grid_label_type = $which_yglt;
return true;
}
function SetXGridLabelType($which_xglt) {
$this->x_grid_label_type = $which_xglt;
return true;
}
function SetXLabel($xlbl) {
$this->x_label_txt = $xlbl;
return true;
}
function SetYLabel($ylbl) {
$this->y_label_txt = $ylbl;
return true;
}
function SetTitle($title) {
$this->title_txt = $title;
return true;
}
//function SetLabels($xlbl,$ylbl,$title) {
// $this->title_txt = $title;
// $this->x_label_txt = $xlbl;
// $this->y_label_txt = $ylbl;
//}
function DrawLabels() {
$this->DrawTitle();
$this->DrawXLabel();
$this->DrawYLabel();
return true;
}
function DrawXLabel() {
if ($this->use_ttf == 1) {
$xpos = $this->xtr(($this->plot_max_x + $this->plot_min_x)/2.0) ;
$ypos = $this->ytr($this->plot_min_y) + $this->x_label_height/2.0;
$this->DrawText($this->x_label_ttffont, $this->x_label_angle,
$xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center');
} else {
//$xpos = 0.0 - (ImageFontWidth($this->small_font)*strlen($this->x_label_txt)/2.0) + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
$xpos = 0.0 + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
$ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2);
$this->DrawText($this->small_font, $this->x_label_angle,
$xpos, $ypos, $this->ndx_label_color, "", $this->x_label_txt, 'center');
}
return true;
}
function DrawYLabel() {
if ($this->use_ttf == 1) {
$size = $this->TTFBBoxSize($this->y_label_ttffont_size, 90, $this->y_label_ttffont, $this->y_label_txt);
$xpos = 8 + $size[0];
$ypos = ($size[1])/2 + $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ;
$this->DrawText($this->y_label_ttffont, 90,
$xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
} else {
$xpos = 8;
$ypos = (($this->small_font_width*strlen($this->y_label_txt)/2.0) +
$this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) );
$this->DrawText($this->small_font, 90,
$xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
}
return true;
}
function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left',$which_valign='') {
if ($this->use_ttf == 1 ) {
$size = $this->TTFBBoxSize($which_size, $which_angle, $which_font, $which_text);
if ($which_valign == 'bottom') {
$which_ypos = $which_ypos + ImageFontHeight($which_font);
}
if ($which_halign == 'center') {
$which_xpos = $which_xpos - $size[0]/2;
}
ImageTTFText($this->img, $which_size, $which_angle,
$which_xpos, $which_ypos, $which_color, $which_font, $which_text);
} else {
if ($which_valign == 'top') {
$which_ypos = $which_ypos - ImageFontHeight($which_font);
}
$which_text = ereg_replace("\r","",$which_text);
$str = split("\n",$which_text); //multiple lines submitted by Remi Ricard
$height = ImageFontHeight($which_font);
$width = ImageFontWidth($which_font);
if ($which_angle == 90) { //Vertical Code Submitted by Marlin Viss
for($i=0;$i<count($str);$i++) {
ImageStringUp($this->img, $which_font, ($i*$height + $which_xpos), $which_ypos, $str[$i], $which_color);
}
} else {
for($i=0;$i<count($str);$i++) {
if ($which_halign == 'center') {
$xpos = $which_xpos - strlen($str[$i]) * $width/2;
ImageString($this->img, $which_font, $xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
} else {
ImageString($this->img, $which_font, $which_xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
}
}
}
}
return true;
}
function DrawTitle() {
if ($this->use_ttf == 1 ) {
$xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
$ypos = $this->y_top_margin/2;
$this->DrawText($this->title_ttffont, $this->title_angle,
$xpos, $ypos, $this->ndx_title_color, $this->title_ttffont_size, $this->title_txt,'center');
} else {
$xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
$ypos = ImageFontHeight($this->title_font);
$this->DrawText($this->title_font, $this->title_angle,
$xpos, $ypos, $this->ndx_title_color, '', $this->title_txt,'center');
}
return true;
}
function DrawPlotAreaBackground() {
ImageFilledRectangle($this->img,$this->plot_area[0],
$this->plot_area[1],$this->plot_area[2],$this->plot_area[3],
$this->ndx_plot_bg_color);
}
function SetBackgroundColor($which_color) {
$this->bg_color= $which_color;
$this->ndx_bg_color= $this->SetIndexColor($which_color);
return true;
}
function SetPlotBgColor($which_color) {
$this->plot_bg_color= $which_color;
$this->ndx_plot_bg_color= $this->SetIndexColor($which_color);
return true;
}
function SetShading($which_s) {
$this->shading = $which_s;
return true;
}
function SetTitleColor($which_color) {
$this->title_color= $which_color;
$this->ndx_title_color= $this->SetIndexColor($which_color);
return true;
}
function SetTickColor ($which_color) {
$this->tick_color= $which_color;
$this->ndx_tick_color= $this->SetIndexColor($which_color);
return true;
}
function SetLabelColor ($which_color) {
$this->label_color= $which_color;
$this->ndx_label_color= $this->SetIndexColor($which_color);
return true;
}
function SetTextColor ($which_color) {
$this->text_color= $which_color;
$this->ndx_text_color= $this->SetIndexColor($which_color);
return true;
}
function SetLightGridColor ($which_color) {
$this->light_grid_color= $which_color;
$this->ndx_light_grid_color= $this->SetIndexColor($which_color);
return true;
}
function SetGridColor ($which_color) {
$this->grid_color = $which_color;
$this->ndx_grid_color= $this->SetIndexColor($which_color);
return true;
}
function SetCharacterHeight() {
//to be set
return true;
}
function SetPlotType($which_pt) {
$accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
$asked = trim($which_pt);
if (eregi($asked, $accepted)) {
$this->plot_type = $which_pt;
return true;
} else {
$this->DrawError('$which_pt not an acceptable plot type');
return false;
}
}
function FindDataLimits() {
//Text-Data is different than data-data graphs. For them what
// we have, instead of X values, is # of records equally spaced on data.
//text-data is passed in as $data[] = (title,y1,y2,y3,y4,...)
//data-data is passed in as $data[] = (title,x,y1,y2,y3,y4,...)
$this->number_x_points = count($this->data_values);
switch ($this->data_type) {
case "text-data":
$minx = 0; //valid for BAR TYPE GRAPHS ONLY
$maxx = $this->number_x_points - 1 ; //valid for BAR TYPE GRAPHS ONLY
$miny = (double) $this->data_values[0][1];
$maxy = $miny;
if ($this->draw_x_data_labels == "") {
$this->draw_x_data_labels = 1; //labels_note1: prevent both data labels and x-axis labels being both drawn and overlapping
}
break;
default: //Everything else: data-data, etc.
$maxx = $this->data_values[0][1];
$minx = $maxx;
$miny = $this->data_values[0][2];
$maxy = $miny;
$maxy = $miny;
break;
}
$max_records_per_group = 0;
$total_records = 0;
$mine = 0; //Maximum value for the -error bar (assume error bars always > 0)
$maxe = 0; //Maximum value for the +error bar (assume error bars always > 0)
reset($this->data_values);
while (list($dat_key, $dat) = each($this->data_values)) { //for each X barchart setting
//foreach($this->data_values as $dat) //can use foreach only in php4
$tmp = 0;
$total_records += count($dat) - 1; // -1 for label
switch ($this->data_type) {
case "text-data":
//Find the relative Max and Min
while (list($key, $val) = each($dat)) {
if ($key != 0) { //$dat[0] = label
SetType($val,"double");
if ($val > $maxy) {
$maxy = $val ;
}
if ($val < $miny) {
$miny = (double) $val ;
}
}
$tmp++;
}
break;
case "data-data": //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
while (list($key, $val) = each($dat)) {
if ($key == 1) { //$dat[0] = label
SetType($val,"double");
if ($val > $maxx) {
$maxx = $val;
} elseif ($val < $minx) {
$minx = $val;
}
} elseif ($key > 1) {
SetType($val,"double");
if ($val > $maxy) {
$maxy = $val ;
} elseif ($val < $miny) {
$miny = $val ;
}
}
$tmp++;
}
$tmp = $tmp - 1; //# records per group
break;
case "data-data-error": //Assume 2-D for now, can go higher
//Regular X-Y data is passed in as $data[] = (title,x,y,error+,error-,y2,error2+,error2-)
while (list($key, $val) = each($dat)) {
if ($key == 1) { //$dat[0] = label
SetType($val,'double');
if ($val > $maxx) {
$maxx = $val;
} elseif ($val < $minx) {
$minx = $val;
}
} elseif ($key%3 == 2) {
SetType($val,'double');
if ($val > $maxy) {
$maxy = $val ;
} elseif ($val < $miny) {
$miny = $val ;
}
} elseif ($key%3 == 0) {
SetType($val,'double');
if ($val > $maxe) {
$maxe = $val ;
}
} elseif ($key%3 == 1) {
SetType($val,'double');
if ($val > $mine) {
$mine = $val ;
}
}
$tmp++;
}
$maxy = $maxy + $maxe;
$miny = $miny - $mine; //assume error bars are always > 0
break;
default:
$this->PrintError('ERROR: unknown chart type');
break;
}
if ($tmp > $max_records_per_group) {
$max_records_per_group = $tmp;
}
}
$this->min_x = $minx;
$this->max_x = $maxx;
$this->min_y = $miny;
$this->max_y = $maxy;
if ($max_records_per_group > 1) {
$this->records_per_group = $max_records_per_group - 1;
} else {
$this->records_per_group = 1;
}
//$this->data_count = $total_records ;
} // function FindDataLimits
function SetMargins() {
/////////////////////////////////////////////////////////////////
// When the image is first created - set the margins
// to be the standard viewport.
// The standard viewport is the full area of the view surface (or panel),
// less a margin of 4 character heights all round for labelling.
// It thus depends on the current character size, set by SetCharacterHeight().
/////////////////////////////////////////////////////////////////
$str = split("\n",$this->title_txt);
$nbLines = count($str);
if ($this->use_ttf == 1) {
$title_size = $this->TTFBBoxSize($this->title_ttffont_size, $this->title_angle, $this->title_ttffont, 'X'); //An array
if ($nbLines == 1) {
$this->y_top_margin = $title_size[1] * 4;
} else {
$this->y_top_margin = $title_size[1] * ($nbLines+3);
}
//ajo working here
//$x_label_size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
$this->y_bot_margin = $this->x_label_height ;
$this->x_left_margin = $this->y_label_width * 2 + $this->tick_length;
$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
} else {
$title_size = array(ImageFontWidth($this->title_font) * strlen($this->title_txt),ImageFontHeight($this->title_font));
//$this->y_top_margin = ($title_size[1] * 4);
if ($nbLines == 1) {
$this->y_top_margin = $title_size[1] * 4;
} else {
$this->y_top_margin = $title_size[1] * ($nbLines+3);
}
if ($this->x_datalabel_angle == 90) {
$this->y_bot_margin = 76.0; // Must be integer
} else {
$this->y_bot_margin = 66.0; // Must be integer
}
$this->x_left_margin = 77.0; // distance between left and start of x axis in pixels
$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
}
//exit;
$this->x_tot_margin = $this->x_left_margin + $this->x_right_margin;
$this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin;
if ($this->plot_max_x && $this->plot_max_y && $this->plot_area_width ) { //If data has already been analysed then set translation
$this->SetTranslation();
}
}
function SetMarginsPixels($which_lm,$which_rm,$which_tm,$which_bm) {
//Set the plot area using margins in pixels (left, right, top, bottom)
$this->SetNewPlotAreaPixels($which_lm,$which_tm,($this->image_width - $which_rm),($this->image_height - $which_bm));
return true;
}
function SetNewPlotAreaPixels($x1,$y1,$x2,$y2) {
//Like in GD 0,0 is upper left set via pixel Coordinates
$this->plot_area = array($x1,$y1,$x2,$y2);
$this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
$this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
$this->y_top_margin = $this->plot_area[1];
if ($this->plot_max_x) {
$this->SetTranslation();
}
return true;
}