📄 phplot.php
字号:
function SetDataValues($which_dv) { $this->data_values = $which_dv;//echo $this->data_values return true; }//////////////COLORS function SetRGBArray ($which_color_array) { if ( is_array($which_color_array) ) { //User Defined Array $this->rgb_array = $which_color_array; return true; } elseif ($which_color_array == 2) { //Use the small predefined color array $this->rgb_array = array( "white" => array(255, 255, 255), "snow" => array(255, 250, 250), "PeachPuff" => array(255, 218, 185), "ivory" => array(255, 255, 240), "lavender" => array(230, 230, 250), "black" => array( 0, 0, 0), "DimGrey" => array(105, 105, 105), "gray" => array(190, 190, 190), "grey" => array(190, 190, 190), "navy" => array( 0, 0, 128), "SlateBlue" => array(106, 90, 205), "blue" => array( 0, 0, 255), "SkyBlue" => array(135, 206, 235), "cyan" => array( 0, 255, 255), "DarkGreen" => array( 0, 100, 0), "green" => array( 0, 255, 0), "YellowGreen" => array(154, 205, 50), "yellow" => array(255, 255, 0), "orange" => array(255, 165, 0), "gold" => array(255, 215, 0), "peru" => array(205, 133, 63), "beige" => array(245, 245, 220), "wheat" => array(245, 222, 179), "tan" => array(210, 180, 140), "brown" => array(165, 42, 42), "salmon" => array(250, 128, 114), "red" => array(255, 0, 0), "pink" => array(255, 192, 203), "maroon" => array(176, 48, 96), "magenta" => array(255, 0, 255), "violet" => array(238, 130, 238), "plum" => array(221, 160, 221), "orchid" => array(218, 112, 214), "purple" => array(160, 32, 240), "azure1" => array(240, 255, 255), "aquamarine1" => array(127, 255, 212) ); return true; } elseif ($which_color_array == 1) { include("./rgb.inc.php"); //Get large $ColorArray $this->rgb_array = $RGBArray; } else { $this->rgb_array = array("white" =>array(255,255,255), "black" => array(0,0,0)); exit; } return true; } function SetColor($which_color) { //obsoleted by SetRGBColor SetRgbColor($which_color); return true; } function SetIndexColor($which_color) { //Color is passed in as anything list ($r, $g, $b) = $this->SetRgbColor($which_color); //Translate to RGB $index = ImageColorExact($this->img, $r, $g, $b); if ($index == -1) { //return ImageColorAllocate($this->img, $r, $g, $b); //return ImageColorClosest($this->img, $r, $g, $b); return ImageColorResolve($this->img, $r, $g, $b); //requires PHP 3.0.2 and later } else { return $index; } } function SetTransparentColor($which_color) { ImageColorTransparent($this->img,$this->SetIndexColor($which_color)); return true; } function SetRgbColor($color_asked) { //Returns an array in R,G,B format 0-255 if ($color_asked == "") { $color_asked = array(0,0,0); }; if ( count($color_asked) == 3 ) { //already array of 3 rgb $ret_val = $color_asked; } else { // is asking for a color by string if(substr($color_asked,0,1) == "#") { //asking in #FFFFFF format. $ret_val = array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2))); } else { $ret_val = $this->rgb_array[$color_asked]; } } return $ret_val; } function SetDataColors($which_data,$which_border) { //Set the data to be displayed in a particular color if (!$which_data) { $which_data = array(array(0,255,0),array(0,0,248),'yellow',array(255,0,0),'orange'); $which_border = array('black'); } $this->data_color = $which_data; //an array $this->data_border_color = $which_border; //an array unset($this->ndx_data_color); reset($this->data_color); //data_color can be an array of colors, one for each thing plotted //while (list(, $col) = each($this->data_color)) $i = 0; while (list(, $col) = each($which_data)) { $this->ndx_data_color[$i] = $this->SetIndexColor($col); $i++; } // border_color //If we are also going to put a border on the data (bars, dots, area, ...) // then lets also set a border color as well. //foreach($this->data_border_color as $col) unset($this->ndx_data_border_color); reset($this->data_border_color); $i = 0; while (list(, $col) = each($this->data_border_color)) { $this->ndx_data_border_color[$i] = $this->SetIndexColor($col); $i++; } //Set color of the error bars to be that of data if not already set. if (!$this->error_bar_color) { reset($which_data); $this->SetErrorBarColors($which_data); } return true; } //function SetDataColors function SetErrorBarColors($which_data) { //Set the data to be displayed in a particular color if ($which_data) { $this->error_bar_color = $which_data; //an array unset($this->ndx_error_bar_color); reset($this->error_bar_color); //data_color can be an array of colors, one for each thing plotted $i = 0; while (list(, $col) = each($this->error_bar_color)) { $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col); $i++; } return true; } return false; } //function SetErrorBarColors function DrawPlotBorder() { switch ($this->plot_border_type) { case "left" : ImageLine($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y), $this->plot_area[0],$this->ytr($this->plot_max_y),$this->ndx_grid_color); break; case "none": //Draw No Border break; default: ImageRectangle($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y), $this->plot_area[2],$this->ytr($this->plot_max_y),$this->ndx_grid_color); break; } $this->DrawYAxis(); $this->DrawXAxis(); return true; } function SetHorizTickIncrement($which_ti) { //Use either this or NumHorizTicks to set where to place x tick marks if ($which_ti) { $this->horiz_tick_increment = $which_ti; //world coordinates } else { if (!$this->max_x) { $this->FindDataLimits(); //Get maxima and minima for scaling } //$this->horiz_tick_increment = ( ceil($this->max_x * 1.2) - floor($this->min_x * 1.2) )/10; $this->horiz_tick_increment = ($this->plot_max_x - $this->plot_min_x )/10; } $this->num_horiz_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both return true; } function SetDrawVertTicks($which_dvt) { $this->draw_vert_ticks = $which_dvt; return true; } function SetVertTickIncrement($which_ti) { //Use either this or NumVertTicks to set where to place y tick marks if ($which_ti) { $this->vert_tick_increment = $which_ti; //world coordinates } else { if (!$this->max_y) { $this->FindDataLimits(); //Get maxima and minima for scaling } //$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->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both return true; } function SetNumHorizTicks($which_nt) { $this->num_horiz_ticks = $which_nt; $this->horiz_tick_increment = ''; //either use num_horiz_ticks or horiz_tick_increment, not both return true; } function SetNumVertTicks($which_nt) { $this->num_vert_ticks = $which_nt; $this->vert_tick_increment = ''; //either use num_vert_ticks or vert_tick_increment, not both return true; } function SetVertTickPosition($which_tp) { $this->vert_tick_position = $which_tp; //plotleft, plotright, both, yaxis return true; } function SetSkipBottomTick($which_sbt) { $this->skip_bottom_tick = $which_sbt; return true; } function SetTickLength($which_tl) { $this->tick_length = $which_tl; return true; } function DrawYAxis() { //Draw Line at left side or at this->y_axis_position if ($this->y_axis_position != "") { $yaxis_x = $this->xtr($this->y_axis_position); } else { $yaxis_x = $this->plot_area[0]; } ImageLine($this->img, $yaxis_x, $this->plot_area[1], $yaxis_x, $this->plot_area[3], $this->ndx_grid_color); //$yaxis_x, $this->plot_area[3], 9); if ($this->draw_vert_ticks == 1) { $this->DrawVerticalTicks(); } } //function DrawYAxis function DrawXAxis() { //Draw Tick and Label for Y axis $ylab =$this->FormatYTickLabel($this->x_axis_position); if ($this->skip_bottom_tick != 1) { $this->DrawVerticalTick($ylab,$this->x_axis_position); } //Draw X Axis at Y=$x_axis_postion ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->x_axis_position), $this->xtr($this->plot_max_x)-1,$this->ytr($this->x_axis_position),$this->ndx_tick_color); //X Ticks and Labels if ($this->data_type != 'text-data') { //labels for text-data done at data drawing time for speed. $this->DrawHorizontalTicks(); } return true; } function DrawHorizontalTicks() { //Ticks and lables are drawn on the left border of PlotArea. //Left Bottom ImageLine($this->img,$this->plot_area[0], $this->plot_area[3]+$this->tick_length, $this->plot_area[0],$this->plot_area[3],$this->ndx_tick_color); switch ($this->x_grid_label_type) { case "title": $xlab = $this->data_values[0][0]; break; case "data": $xlab = number_format($this->plot_min_x,$this->x_precision,".",",") . "$this->si_units"; break; case "none": $xlab = ''; break; case "time": //Time formatting suggested by Marlin Viss $xlab = strftime($this->x_time_format,$this->plot_min_x); break; default: //Unchanged from whatever format is passed in $xlab = $this->plot_min_x; break; } if ($this->x_datalabel_angle == 90) { $xpos = $this->plot_area[0] - $this->small_font_height/2; $ypos = ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height); ImageStringUp($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color); } else { $xpos = $this->plot_area[0] - $this->small_font_width*strlen($xlab)/2 ; $ypos = $this->plot_area[3] + $this->small_font_height; ImageString($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color); } //Will be changed to allow for TTF fonts in data as well. //$this->DrawText($this->small_font, $this->x_datalabel_angle, $xpos, $ypos, $this->ndx_title_color, '', $xlab); //Top if ($this->horiz_tick_increment) { $delta_x = $this->horiz_tick_increment; } elseif ($this->num_horiz_ticks) { $delta_x = ($this->plot_max_x - $this->plot_min_x) / $this->num_horiz_ticks; } else { $delta_x =($this->plot_max_x - $this->plot_min_x) / 10 ; } $i = 0; $x_tmp = $this->plot_min_x; SetType($x_tmp,'double'); while ($x_tmp <= $this->plot_max_x){ //$xlab = sprintf("%6.1f %s",$min_x,$si_units[0]); //PHP2 past compatibility switch ($this->x_grid_label_type) { case "title": $xlab = $this->data_values[$x_tmp][0]; break; case "data": $xlab = number_format($x_tmp,$this->x_precision,".",",") . "$this->si_units"; break; case "none": $xlab = ''; break; case "time": //Time formatting suggested by Marlin Viss $xlab = strftime($this->x_time_format,$x_tmp); break; default: //Unchanged from whatever format is passed in $xlab = $x_tmp; break; } $x_pixels = $this->xtr($x_tmp); //Bottom Tick ImageLine($this->img,$x_pixels,$this->plot_area[3] + $this->tick_length, $x_pixels,$this->plot_area[3], $this->ndx_tick_color); //Top Tick //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length), // $y_pixels,$this->xtr($this->plot_max_x)-1,$y_pixels,$this->ndx_tick_color); if ($this->draw_x_grid == 1) { ImageLine($this->img,$x_pixels,$this->plot_area[1], $x_pixels,$this->plot_area[3], $this->ndx_light_grid_color); } if ($this->x_datalabel_angle == 90) { //Vertical Code Submitted by Marlin Viss ImageStringUp($this->img, $this->small_font, ( $x_pixels - $this->small_font_height/2), ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height),$xlab, $this->ndx_text_color); } else { ImageString($this->img, $this->small_font, ( $x_pixels - $this->small_font_width*strlen($xlab)/2) , ( $this->small_font_height + $this->plot_area[3]),$xlab, $this->ndx_text_color); } $i++; $x_tmp += $delta_x; } } // function DrawHorizontalTicks function FormatYTickLabel($which_ylab) { switch ($this->y_grid_label_type) { case "data": $ylab = number_format($which_ylab,$this->y_precision,".",",") . "$this->si_units"; break; case "none": $ylab = ''; break; case "time": $ylab = strftime($this->y_time_format,$which_ylab); break; case "right": //Make it right aligned //$ylab = str_pad($which_ylab,$this->y_label_width," ",STR_PAD_LEFT); //PHP4 only $sstr = "%".strlen($this->plot_max_y)."s"; $ylab = sprintf($sstr,$which_ylab); break; default: //Unchanged from whatever format is passed in $ylab = $which_ylab; break; } return($ylab); } //function FormatYTickLabel function DrawVerticalTick($which_ylab,$which_ypos) { //ylab in world coord. //Draw Just one Tick, called from DrawVerticalTicks
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -