📄 phplot.php
字号:
<?php/* $Id: phplot.php,v 1.2 2003/06/20 16:23:08 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License PHPLOT 4.4.6 Copyright (c) 1998-2001 Afan Ottenheimer*/class PHPlot{ 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) // (only if is_inline = 0 also) var $session_set = ''; //Do not change var $scale_is_set = ''; //Do not change var $draw_plot_area_background = ''; var $image_width; //Total Width in Pixels var $image_height; //Total Height in Pixels var $image_border_type = ''; //raised, plain, '' var $x_left_margin; var $y_top_margin; var $x_right_margin; var $y_bot_margin; var $plot_area = array(5,5,600,400); var $x_axis_position = 0; //Where to draw the X_axis (world coordinates) var $y_axis_position = ''; //Leave blank for Y axis at left of plot. (world coord.) var $xscale_type = 'linear'; //linear or log var $yscale_type = 'linear';//Use for multiple plots per image var $print_image = 1; //Used for multiple charts per image. //Fonts var $use_ttf = 0; //Use TTF fonts (1) or not (0) var $font_path = './'; //To be added var $font = './benjamingothic.ttf'; ///////////Fonts: Small/Generic var $small_ttffont_size = 12; // //non-ttf var $small_font = 2; // fonts = 1,2,3,4 or 5 var $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8) var $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12) ////////// Fonts:Title var $title_ttffont = './benjamingothic.ttf'; var $title_ttffont_size = 14; var $title_angle= 0; //non-ttf var $title_font = '4'; // fonts = 1,2,3,4,5 ////////////// Fonts:Axis var $axis_ttffont = './benjamingothic.ttf'; var $axis_ttffont_size = 8; var $x_datalabel_angle = 0; //non-ttf var $axis_font = 2; ////////////////Fonts:Labels of Data var $datalabel_font = '2'; //////////////// Fonts:Labels (Axis Titles) var $x_label_ttffont = './benjamingothic.ttf'; var $x_label_ttffont_size = '12'; var $x_label_angle = '0'; var $y_label_ttffont = './benjamingothic.ttf'; var $y_label_ttffont_size = '12'; var $y_label_angle = 90; var $y_label_width = '';//Formats var $file_format = 'png'; var $file_name = ''; //For output to a file instead of stdout//Plot Colors var $shading = 0; var $color_array = 1; //1 = include small list //2 = include large list //array = define your own color translation. See rgb.inc.php and SetRGBArray var $bg_color; var $plot_bg_color; var $grid_color; var $light_grid_color; var $tick_color; var $title_color; var $label_color; var $text_color; var $i_light = '';//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 $line_width = 2; var $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines var $data_color = ''; //array('blue','green','yellow',array(0,0,0)); var $data_border_color = ''; var $label_scale_position = '.5'; //1 = top, 0 = bottom var $group_frac_width = '.7'; //value from 0 to 1 = width of bar var $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0 var $point_size = 10; var $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline var $error_bar_shape = 'tee'; //tee, line var $error_bar_size = 5; //right left size of tee var $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness var $error_bar_color = ''; var $data_values; var $plot_border_type = 'full'; //left, none, full var $plot_area_width = ''; var $number_x_points; var $plot_min_x; // Max and min of the plot area var $plot_max_x= ''; // Max and min of the plot area var $plot_min_y= ''; // Max and min of the plot area var $plot_max_y = ''; // Max and min of the plot area var $min_y = ''; var $max_y = ''; var $max_x = 10; //Must not be = 0; var $y_precision = '1'; var $x_precision = '1'; var $si_units = '';//Labels var $draw_data_labels = '0'; var $legend = ''; //an array var $legend_x_pos = ''; var $legend_y_pos = ''; var $title_txt = ""; var $y_label_txt = ''; var $x_label_txt = "";//DataAxis Labels (on each axis) var $y_grid_label_type = 'data'; //data, none, time, other var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both var $x_grid_label_type = 'data'; //data, title, none, time, other var $draw_x_data_labels = ''; // 0=false, 1=true, ""=let program decide var $x_time_format = "%H:%m:%s"; //See http://www.php.net/manual/html/function.strftime.html var $x_datalabel_maxlength = 10; //Tick Formatting var $tick_length = '10'; //pixels: tick length from axis left/downward //tick_length2 to be implemented //var $tick_length2 = ''; //pixels: tick length from axis line rightward/upward var $draw_vert_ticks = 1; //1 = draw ticks, 0 = don't draw ticks var $num_vert_ticks = ''; var $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both. var $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) var $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both. var $num_horiz_ticks=''; var $skip_top_tick = '0'; var $skip_bottom_tick = '0';//Grid Formatting var $draw_x_grid = 0; var $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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -