Retour au code d'origine

This commit is contained in:
Rodolphe Quiedeville 2003-11-07 13:29:04 +00:00
parent 3ae6cb47ee
commit 84b2b0b732

View File

@ -14,8 +14,7 @@ side of the image.
//Requires PHP 3.0.2 or later //Requires PHP 3.0.2 or later
class PHPlot class PHPlot{
{
var $is_inline = 0; //0 = Sends headers, 1 = sends just raw image data var $is_inline = 0; //0 = Sends headers, 1 = sends just raw image data
var $browser_cache = '1'; // 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image) var $browser_cache = '1'; // 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image)
@ -37,10 +36,10 @@ class PHPlot
var $xscale_type = 'linear'; //linear or log var $xscale_type = 'linear'; //linear or log
var $yscale_type = 'linear'; var $yscale_type = 'linear';
//Use for multiple plots per image //Use for multiple plots per image
var $print_image = 1; //Used for multiple charts per image. var $print_image = 1; //Used for multiple charts per image.
//Fonts //Fonts
var $use_ttf = 0; //Use TTF fonts (1) or not (0) var $use_ttf = 0; //Use TTF fonts (1) or not (0)
var $font_path = './'; //To be added var $font_path = './'; //To be added
var $font = './benjamingothic.ttf'; var $font = './benjamingothic.ttf';
@ -79,11 +78,11 @@ class PHPlot
var $y_label_angle = 90; var $y_label_angle = 90;
var $y_label_width = ''; var $y_label_width = '';
//Formats //Formats
var $file_format = 'png'; var $file_format = 'png';
var $file_name = ''; //For output to a file instead of stdout var $file_name = ''; //For output to a file instead of stdout
//Plot Colors //Plot Colors
var $shading = 0; var $shading = 0;
var $color_array = 1; //1 = include small list var $color_array = 1; //1 = include small list
//2 = include large list //2 = include large list
@ -98,7 +97,7 @@ class PHPlot
var $text_color; var $text_color;
var $i_light = ''; var $i_light = '';
//Data //Data
var $data_type = 'text-data'; //text-data, data-data-error, data-data var $data_type = 'text-data'; //text-data, data-data-error, data-data
var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline
var $line_width = 2; var $line_width = 2;
@ -133,7 +132,7 @@ class PHPlot
var $x_precision = '1'; var $x_precision = '1';
var $si_units = ''; var $si_units = '';
//Labels //Labels
var $draw_data_labels = '0'; var $draw_data_labels = '0';
var $legend = ''; //an array var $legend = ''; //an array
var $legend_x_pos = ''; var $legend_x_pos = '';
@ -142,7 +141,7 @@ class PHPlot
var $y_label_txt = ''; var $y_label_txt = '';
var $x_label_txt = ""; var $x_label_txt = "";
//DataAxis Labels (on each axis) //DataAxis Labels (on each axis)
var $y_grid_label_type = 'data'; //data, none, time, other var $y_grid_label_type = 'data'; //data, none, time, other
var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both
var $x_grid_label_type = 'data'; //data, title, none, time, other var $x_grid_label_type = 'data'; //data, title, none, time, other
@ -150,7 +149,7 @@ class PHPlot
var $x_time_format = "%H:%m:%s"; //See http://www.php.net/manual/html/function.strftime.html var $x_time_format = "%H:%m:%s"; //See http://www.php.net/manual/html/function.strftime.html
var $x_datalabel_maxlength = 10; var $x_datalabel_maxlength = 10;
//Tick Formatting //Tick Formatting
var $tick_length = '10'; //pixels: tick length from axis left/downward var $tick_length = '10'; //pixels: tick length from axis left/downward
//tick_length2 to be implemented //tick_length2 to be implemented
//var $tick_length2 = ''; //pixels: tick length from axis line rightward/upward //var $tick_length2 = ''; //pixels: tick length from axis line rightward/upward
@ -164,13 +163,13 @@ class PHPlot
var $skip_top_tick = '0'; var $skip_top_tick = '0';
var $skip_bottom_tick = '0'; var $skip_bottom_tick = '0';
//Grid Formatting //Grid Formatting
var $draw_x_grid = 0; var $draw_x_grid = 0;
var $draw_y_grid = 1; var $draw_y_grid = 1;
//BEGIN CODE //BEGIN CODE
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Constructor: Setup Img pointer, Colors and Size of Image //Constructor: Setup Img pointer, Colors and Size of Image
function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") { function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") {
@ -271,28 +270,7 @@ class PHPlot
$this->legend_y_pos = $this->ytr($which_y); $this->legend_y_pos = $this->ytr($which_y);
return true; 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) { function SetFileFormat($which_file_format) {
//eventually test to see if that is supported - if not then return false //eventually test to see if that is supported - if not then return false
$asked = strtolower(trim($which_file_format)); $asked = strtolower(trim($which_file_format));
@ -346,8 +324,7 @@ class PHPlot
} }
function SetOutputFile($which_output_file) function SetOutputFile($which_output_file) {
{
$this->output_file = $which_output_file; $this->output_file = $which_output_file;
return true; return true;
} }
@ -360,24 +337,19 @@ class PHPlot
return true; return true;
} }
function SetYAxisPosition($which_pos)
{ function SetYAxisPosition($which_pos) {
$this->y_axis_position = $which_pos; $this->y_axis_position = $which_pos;
return true; return true;
} }
function SetXAxisPosition($which_pos) {
function SetXAxisPosition($which_pos)
{
$this->x_axis_position = $which_pos; $this->x_axis_position = $which_pos;
return true; return true;
} }
function SetXTimeFormat($which_xtf) {
function SetXTimeFormat($which_xtf)
{
$this->x_time_format = $which_xtf; $this->x_time_format = $which_xtf;
return true; return true;
} }
function SetXDataLabelMaxlength($which_xdlm) { function SetXDataLabelMaxlength($which_xdlm) {
if ($which_xdlm >0 ) { if ($which_xdlm >0 ) {
$this->x_datalabel_maxlength = $which_xdlm; $this->x_datalabel_maxlength = $which_xdlm;
@ -386,17 +358,14 @@ class PHPlot
return false; return false;
} }
} }
function SetXDataLabelAngle($which_xdla) { function SetXDataLabelAngle($which_xdla) {
$this->x_datalabel_angle = $which_xdla; $this->x_datalabel_angle = $which_xdla;
return true; return true;
} }
function SetXScaleType($which_xst) { function SetXScaleType($which_xst) {
$this->xscale_type = $which_xst; $this->xscale_type = $which_xst;
return true; return true;
} }
function SetYScaleType($which_yst) { function SetYScaleType($which_yst) {
$this->yscale_type = $which_yst; $this->yscale_type = $which_yst;
if ($this->x_axis_position <= 0) { if ($this->x_axis_position <= 0) {
@ -409,9 +378,7 @@ class PHPlot
$this->x_precision = $which_prec; $this->x_precision = $which_prec;
return true; return true;
} }
function SetPrecisionY($which_prec) {
function SetPrecisionY($which_prec)
{
$this->y_precision = $which_prec; $this->y_precision = $which_prec;
return true; return true;
} }
@ -459,8 +426,8 @@ class PHPlot
} }
function SetDefaultColors() function SetDefaultColors() {
{
$this->i_light = array(194,194,194); $this->i_light = array(194,194,194);
$this->i_dark = array(100,100,100); $this->i_dark = array(100,100,100);
$this->SetPlotBgColor(array(222,222,222)); $this->SetPlotBgColor(array(222,222,222));
@ -471,15 +438,14 @@ class PHPlot
$this->SetLightGridColor(array(175,175,175)); $this->SetLightGridColor(array(175,175,175));
$this->SetTickColor('black'); $this->SetTickColor('black');
$this->SetTitleColor(array(0,0,0)); // Can be array or name $this->SetTitleColor(array(0,0,0)); // Can be array or name
$this->data_color = array('green','blue','yellow','red','orange'); $this->data_color = array('blue','green','yellow','red','orange');
$this->error_bar_color = array('blue','green','yellow','red','orange'); $this->error_bar_color = array('blue','green','yellow','red','orange');
$this->data_border_color = array('black'); $this->data_border_color = array('black');
$this->session_set = 1; //Mark it down for PHP session() usage. $this->session_set = 1; //Mark it down for PHP session() usage.
} }
function PrintImage() function PrintImage() {
{
if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@ -624,13 +590,6 @@ class PHPlot
$this->title_txt = $title; $this->title_txt = $title;
return true; return true;
} }
//function SetLabels($xlbl,$ylbl,$title) {
// $this->title_txt = $title;
// $this->x_label_txt = $xlbl;
// $this->y_label_txt = $ylbl;
//}
function DrawLabels() { function DrawLabels() {
$this->DrawTitle(); $this->DrawTitle();
$this->DrawXLabel(); $this->DrawXLabel();
@ -645,7 +604,7 @@ class PHPlot
$this->DrawText($this->x_label_ttffont, $this->x_label_angle, $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'); $xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center');
} else { } 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) ; $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); $ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2);
@ -791,8 +750,7 @@ class PHPlot
return true; return true;
} }
function SetPlotType($which_pt) function SetPlotType($which_pt) {
{
$accepted = "bars,lines,linepoints,area,points,pie,thinbarline"; $accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
$asked = trim($which_pt); $asked = trim($which_pt);
if (eregi($asked, $accepted)) { if (eregi($asked, $accepted)) {
@ -926,11 +884,13 @@ class PHPlot
} }
} }
$this->min_x = $minx; $this->min_x = $minx;
$this->max_x = $maxx; $this->max_x = $maxx;
$this->min_y = $miny; $this->min_y = $miny;
$this->max_y = $maxy; $this->max_y = $maxy;
if ($max_records_per_group > 1) { if ($max_records_per_group > 1) {
$this->records_per_group = $max_records_per_group - 1; $this->records_per_group = $max_records_per_group - 1;
} else { } else {
@ -984,7 +944,7 @@ class PHPlot
$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
} }
//exit; //exit;
$this->x_tot_margin = $this->x_left_margin + $this->x_right_margin; $this->x_tot_margin = $this->x_left_margin + $this->x_right_margin;
$this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin; $this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin;
@ -1031,10 +991,13 @@ class PHPlot
} }
function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax) { function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax)
if (($xmin == "") && ($xmax == "")) { {
if (($xmin == "") && ($xmax == ""))
{
//For automatic setting of data we need $this->max_x //For automatic setting of data we need $this->max_x
if (!$this->max_y) { if (!$this->max_y)
{
$this->FindDataLimits() ; $this->FindDataLimits() ;
} }
if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed. if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed.
@ -1179,8 +1142,8 @@ class PHPlot
} }
$this->y_label_width = $size[0] * 2; $this->y_label_width = $size[0] * 2;
//echo "SYLW: $this->y_label_width<br>"; //echo "SYLW: $this->y_label_width<br>";
//exit; //exit;
$this->SetMargins(); $this->SetMargins();
return true; return true;
@ -1245,14 +1208,13 @@ class PHPlot
return true; return true;
} }
function SetDataValues($which_dv) function SetDataValues($which_dv) {
{
$this->data_values = $which_dv; $this->data_values = $which_dv;
//echo $this->data_values //echo $this->data_values
return true; return true;
} }
//////////////COLORS //////////////COLORS
function SetRGBArray ($which_color_array) { function SetRGBArray ($which_color_array) {
if ( is_array($which_color_array) ) { if ( is_array($which_color_array) ) {
//User Defined Array //User Defined Array
@ -1448,20 +1410,15 @@ class PHPlot
return true; return true;
} }
function SetVertTickIncrement($which_ti) function SetVertTickIncrement($which_ti) {
{
//Use either this or NumVertTicks to set where to place y tick marks //Use either this or NumVertTicks to set where to place y tick marks
if ($which_ti) if ($which_ti) {
{
$this->vert_tick_increment = $which_ti; //world coordinates $this->vert_tick_increment = $which_ti; //world coordinates
} } else {
else if (!$this->max_y) {
{
if (!$this->max_y)
{
$this->FindDataLimits(); //Get maxima and minima for scaling $this->FindDataLimits(); //Get maxima and minima for scaling
} }
//$this->vert_tick_increment = ceil(( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10); //$this->vert_tick_increment = ( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10;
$this->vert_tick_increment = ($this->plot_max_y - $this->plot_min_y )/10; $this->vert_tick_increment = ($this->plot_max_y - $this->plot_min_y )/10;
} }
$this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both $this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
@ -1474,8 +1431,7 @@ class PHPlot
return true; return true;
} }
function SetNumVertTicks($which_nt) function SetNumVertTicks($which_nt) {
{
$this->num_vert_ticks = $which_nt; $this->num_vert_ticks = $which_nt;
$this->vert_tick_increment = ''; //either use num_vert_ticks or vert_tick_increment, not both $this->vert_tick_increment = ''; //either use num_vert_ticks or vert_tick_increment, not both
return true; return true;
@ -1706,7 +1662,7 @@ class PHPlot
} }
//DataLabel //DataLabel
//ajo working //ajo working
//$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2), //$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2),
// $y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab); // $y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab);
ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2), ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2),
@ -1743,17 +1699,12 @@ class PHPlot
} }
// maxy is always > miny so delta_y is always positive // maxy is always > miny so delta_y is always positive
if ($this->vert_tick_increment) if ($this->vert_tick_increment) {
{
$delta_y = $this->vert_tick_increment; $delta_y = $this->vert_tick_increment;
} } elseif ($this->num_vert_ticks) {
elseif($this->num_vert_ticks)
{
$delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks; $delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks;
} } else {
else $delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ;
{
$delta_y = ($this->plot_max_y - $this->plot_min_y) / 10 ;
} }
$y_tmp = $this->plot_min_y; $y_tmp = $this->plot_min_y;
@ -1839,7 +1790,7 @@ class PHPlot
//$x = $this->xtr($x_world) ; //$x = $this->xtr($x_world) ;
//$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left'); //$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left');
if ($this->use_ttf) { if ($this->use_ttf) {
//ajjjo //ajjjo
$lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array $lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array
$y = $this->ytr($y_world) - $lab_size[1] ; //in pixels $y = $this->ytr($y_world) - $lab_size[1] ; //in pixels
$x = $this->xtr($x_world) - $lab_size[0]/2; $x = $this->xtr($x_world) - $lab_size[0]/2;
@ -1933,7 +1884,7 @@ class PHPlot
$slicecol = $this->ndx_data_color[$color_index]; $slicecol = $this->ndx_data_color[$color_index];
//Need this again for FillToBorder //Need this again for FillToBorder
ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color); ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
$out_x = $radius * cos(deg2rad($end_angle)); $out_x = $radius * cos(deg2rad($end_angle));
@ -1975,7 +1926,7 @@ class PHPlot
$i = 0; $i = 0;
while (list($key, $val) = each($row)) { while (list($key, $val) = each($row)) {
//echo "$key, $i, $val<br>"; //echo "$key, $i, $val<br>";
if ($key == 0) { if ($key == 0) {
$lab = $val; $lab = $val;
} elseif ($key == 1) { } elseif ($key == 1) {
@ -1994,7 +1945,7 @@ class PHPlot
$barcol = $this->ndx_data_color[$color_index]; $barcol = $this->ndx_data_color[$color_index];
$error_barcol = $this->ndx_error_bar_color[$color_index]; $error_barcol = $this->ndx_error_bar_color[$color_index];
//echo "start = $start_lines<br>"; //echo "start = $start_lines<br>";
if ($start_lines == 1) { if ($start_lines == 1) {
for ($width = 0; $width < $this->line_width; $width++) { for ($width = 0; $width < $this->line_width; $width++) {
ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width, ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width,
@ -2240,11 +2191,11 @@ class PHPlot
while (list(, $row) = each($posarr)) { while (list(, $row) = each($posarr)) {
if ($color_index >= count($this->ndx_data_color)) $color_index=0; if ($color_index >= count($this->ndx_data_color)) $color_index=0;
$barcol = $this->ndx_data_color[$color_index]; $barcol = $this->ndx_data_color[$color_index];
//echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>"; //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>";
ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol); ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
$color_index++; $color_index++;
} }
//exit; //exit;
} }
@ -2292,7 +2243,7 @@ class PHPlot
while (list(, $row) = each($posarr)) { while (list(, $row) = each($posarr)) {
if ($color_index >= count($this->ndx_data_color)) $color_index=0; if ($color_index >= count($this->ndx_data_color)) $color_index=0;
$barcol = $this->ndx_data_color[$color_index]; $barcol = $this->ndx_data_color[$color_index];
//echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>"; //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>";
ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol); ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
$color_index++; $color_index++;
} }
@ -2575,11 +2526,10 @@ class PHPlot
if ($this->draw_plot_area_background == 1) { if ($this->draw_plot_area_background == 1) {
$this->DrawPlotAreaBackground(); $this->DrawPlotAreaBackground();
} }
//$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height"; //$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height";
//ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color); //ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color);
switch ($this->plot_type) switch ($this->plot_type) {
{
case "bars": case "bars":
$this->DrawPlotBorder(); $this->DrawPlotBorder();
$this->DrawLabels(); $this->DrawLabels();
@ -2652,13 +2602,12 @@ class PHPlot
} }
} }
if ($this->print_image == 1) if ($this->print_image == 1) {
{
$this->PrintImage(); $this->PrintImage();
} }
} //function DrawGraph } //function DrawGraph
} }
// $graph = new PHPlot; // $graph = new PHPlot;