📄 phplot.php
字号:
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
//Ticks and datalables can be left of plot only, right of plot only,
// both on the left and right of plot, or crossing a user defined Y-axis
//
//Its faster to draw both left and right ticks at same time
// than first left and then right.
if ($this->y_axis_position != "") {
//Ticks and lables are drawn on the left border of yaxis
$yaxis_x = $this->xtr($this->y_axis_position);
} else {
//Ticks and lables are drawn on the left border of PlotArea.
$yaxis_x = $this->plot_area[0];
}
$y_pixels = $this->ytr($which_ypos);
//Lines Across the Plot Area
if ($this->draw_y_grid == 1) {
ImageLine($this->img,$this->plot_area[0]+1,$y_pixels,
$this->plot_area[2]-1,$y_pixels,$this->ndx_light_grid_color);
}
//Ticks to the Left of the Plot Area
if (($this->vert_tick_position == "plotleft") || ($this->vert_tick_position == "both") ) {
ImageLine($this->img,(-$this->tick_length+$yaxis_x),
$y_pixels,$yaxis_x,
$y_pixels, $this->ndx_tick_color);
}
//Ticks to the Right of the Plot Area
if (($this->vert_tick_position == "plotright") || ($this->vert_tick_position == "both") ) {
ImageLine($this->img,($this->plot_area[2]+$this->tick_length),
$y_pixels,$this->plot_area[2],
$y_pixels,$this->ndx_tick_color);
}
//Ticks on the Y Axis
if (($this->vert_tick_position == "yaxis") ) {
ImageLine($this->img,($yaxis_x - $this->tick_length),
$y_pixels,$yaxis_x,$y_pixels,$this->ndx_tick_color);
}
//DataLabel
//ajo working
//$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);
ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2),
( -($this->small_font_height/2.0) + $y_pixels),$which_ylab, $this->ndx_text_color);
}
function DrawVerticalTicks() {
if ($this->skip_top_tick != 1) { //If tick increment doesn't hit the top
//Left Top
//ImageLine($this->img,(-$this->tick_length+$this->xtr($this->plot_min_x)),
// $this->ytr($this->plot_max_y),$this->xtr($this->plot_min_x),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
//$ylab = $this->FormatYTickLabel($plot_max_y);
//Right Top
//ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
// $this->ytr($this->plot_max_y),$this->xtr($this->plot_max_x-1),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
//Draw Grid Line at Top
ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->plot_max_y),
$this->plot_area[2]-1,$this->ytr($this->plot_max_y),$this->ndx_light_grid_color);
}
if ($this->skip_bottom_tick != 1) {
//Right Bottom
//ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
// $this->ytr($this->plot_min_y),$this->xtr($this->plot_max_x),
// $this->ytr($this->plot_min_y),$this->ndx_tick_color);
//Draw Grid Line at Bottom of Plot
ImageLine($this->img,$this->xtr($this->plot_min_x)+1,$this->ytr($this->plot_min_y),
$this->xtr($this->plot_max_x),$this->ytr($this->plot_min_y),$this->ndx_light_grid_color);
}
// maxy is always > miny so delta_y is always positive
if ($this->vert_tick_increment) {
$delta_y = $this->vert_tick_increment;
} elseif ($this->num_vert_ticks) {
$delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks;
} else {
$delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ;
}
$y_tmp = $this->plot_min_y;
SetType($y_tmp,'double');
if ($this->skip_bottom_tick == 1) {
$y_tmp += $delta_y;
}
while ($y_tmp <= $this->plot_max_y){
//For log plots:
if (($this->yscale_type == "log") && ($this->plot_min_y == 1) &&
($delta_y%10 == 0) && ($y_tmp == $this->plot_min_y)) {
$y_tmp = $y_tmp - 1; //Set first increment to 9 to get: 1,10,20,30,...
}
$ylab = $this->FormatYTickLabel($y_tmp);
$this->DrawVerticalTick($ylab,$y_tmp);
$y_tmp += $delta_y;
}
return true;
} // function DrawVerticalTicks
function SetTranslation() {
if ($this->xscale_type == "log") {
$this->xscale = ($this->plot_area_width)/(log10($this->plot_max_x) - log10($this->plot_min_x));
} else {
$this->xscale = ($this->plot_area_width)/($this->plot_max_x - $this->plot_min_x);
}
if ($this->yscale_type == "log") {
$this->yscale = ($this->plot_area_height)/(log10($this->plot_max_y) - log10($this->plot_min_y));
} else {
$this->yscale = ($this->plot_area_height)/($this->plot_max_y - $this->plot_min_y);
}
// GD defines x=0 at left and y=0 at TOP so -/+ respectively
if ($this->xscale_type == "log") {
$this->plot_origin_x = $this->plot_area[0] - ($this->xscale * log10($this->plot_min_x) );
} else {
$this->plot_origin_x = $this->plot_area[0] - ($this->xscale * $this->plot_min_x);
}
if ($this->yscale_type == "log") {
$this->plot_origin_y = $this->plot_area[3] + ($this->yscale * log10($this->plot_min_y));
} else {
$this->plot_origin_y = $this->plot_area[3] + ($this->yscale * $this->plot_min_y);
}
$this->scale_is_set = 1;
} // function SetTranslation
function xtr($x_world) {
//Translate world coordinates into pixel coordinates
//The pixel coordinates are those of the ENTIRE image, not just the plot_area
//$x_pixels = $this->x_left_margin + ($this->image_width - $this->x_tot_margin)*(($x_world - $this->plot_min_x) / ($this->plot_max_x - $this->plot_min_x)) ;
//which with a little bit of math reduces to ...
if ($this->xscale_type == "log") {
$x_pixels = $this->plot_origin_x + log10($x_world) * $this->xscale ;
} else {
$x_pixels = $this->plot_origin_x + $x_world * $this->xscale ;
}
return($x_pixels);
}
function ytr($y_world) {
// translate y world coord into pixel coord
if ($this->yscale_type == "log") {
$y_pixels = $this->plot_origin_y - log10($y_world) * $this->yscale ; //minus because GD defines y=0 at top. doh!
} else {
$y_pixels = $this->plot_origin_y - $y_world * $this->yscale ;
}
return ($y_pixels);
}
function DrawDataLabel($lab,$x_world,$y_world) {
//Depreciated. Use DrawText Instead.
//Data comes in in WORLD coordinates
//Draw data label near actual data point
//$y = $this->ytr($y_world) ; //in pixels
//$x = $this->xtr($x_world) ;
//$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left');
if ($this->use_ttf) {
//ajjjo
$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
$x = $this->xtr($x_world) - $lab_size[0]/2;
ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $lab);
} else {
$lab_size = array($this->small_font_width*StrLen($lab), $this->small_font_height*3);
if ($this->x_datalabel_angle == 90) {
$y = $this->ytr($y_world) - $this->small_font_width*StrLen($lab); //in pixels
$x = $this->xtr($x_world) - $this->small_font_height;
ImageStringUp($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
} else {
$y = $this->ytr($y_world) - $this->small_font_height; //in pixels
$x = $this->xtr($x_world) - ($this->small_font_width*StrLen($lab))/2;
ImageString($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
}
}
}
function DrawXDataLabel($xlab,$xpos) {
//xpos comes in in PIXELS not in world coordinates.
//Draw an x data label centered at xlab
if ($this->use_ttf) {
$xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size,
$this->x_datalabel_angle, $this->axis_ttffont, $xlab); //An array
$y = $this->plot_area[3] + $xlab_size[1] + 4; //in pixels
$x = $xpos - $xlab_size[0]/2;
ImageTTFText($this->img, $this->axis_ttffont_size,
$this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
} else {
$xlab_size = array(ImageFontWidth($this->axis_font)*StrLen($xlab), $this->small_font_height*3);
if ($this->x_datalabel_angle == 90) {
$y = $this->plot_area[3] + ImageFontWidth($this->axis_font)*StrLen($xlab); //in pixels
$x = $xpos - ($this->small_font_height);
ImageStringUp($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
} else {
$y = $this->plot_area[3] + ImageFontHeight($this->axis_font); //in pixels
$x = $xpos - (ImageFontWidth($this->axis_font)*StrLen($xlab))/2;
ImageString($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
}
}
}
function DrawPieChart() {
//$pi = '3.14159265358979323846';
$xpos = $this->plot_area[0] + $this->plot_area_width/2;
$ypos = $this->plot_area[1] + $this->plot_area_height/2;
$diameter = (min($this->plot_area_width, $this->plot_area_height)) ;
$radius = $diameter/2;
ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
$total = 0;
reset($this->data_values);
$tmp = $this->number_x_points - 1;
while (list($j, $row) = each($this->data_values)) {
//Get sum of each type
$color_index = 0;
$i = 0;
//foreach ($row as $v)
while (list($k, $v) = each($row)) {
if ($k != 0) {
if ($j == 0) {
$sumarr[$i] = $v;
} elseif ($j < $tmp) {
$sumarr[$i] += $v;
} else {
$sumarr[$i] += $v;
// NOTE! sum > 0 to make pie charts
$sumarr[$i] = abs($sumarr[$i]);
$total += $sumarr[$i];
}
}
$i++;
}
}
$color_index = 0;
$start_angle = 0;
reset($sumarr);
$end_angle = 0;
while (list(, $val) = each($sumarr)) {
if ($color_index >= count($this->ndx_data_color)) $color_index=0; //data_color = array
$label_txt = number_format(($val / $total * 100), $this->y_precision, ".", ",") . "%";
$val = 360 * ($val / $total);
$end_angle += $val;
$mid_angle = $end_angle - ($val / 2);
$slicecol = $this->ndx_data_color[$color_index];
//Need this again for FillToBorder
ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
$out_x = $radius * cos(deg2rad($end_angle));
$out_y = - $radius * sin(deg2rad($end_angle));
$mid_x = $xpos + ($radius/2 * cos(deg2rad($mid_angle))) ;
$mid_y = $ypos + (- $radius/2 * sin(deg2rad($mid_angle)));
$label_x = $xpos + ($radius * cos(deg2rad($mid_angle))) * $this->label_scale_position;
$label_y = $ypos + (- $radius * sin(deg2rad($mid_angle))) * $this->label_scale_position;
$out_x = $xpos + $out_x;
$out_y = $ypos + $out_y;
ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $this->ndx_grid_color);
//ImageLine($this->img, $xpos, $ypos, $label_x, $label_y, $this->ndx_grid_color);
ImageFillToBorder($this->img, $mid_x, $mid_y, $this->ndx_grid_color, $slicecol);
if ($this->use_ttf) {
ImageTTFText($this->img, $this->axis_ttffont_size, 0, $label_x, $label_y, $this->ndx_grid_color, $this->axis_ttffont, $label_txt);
} else {
ImageString($this->img, $this->small_font, $label_x, $label_y, $label_txt, $this->ndx_grid_color);
}
$start_angle = $val;
$color_index++;
}
}
function DrawLinesError() {
//Draw Lines with Error Bars - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
$start_lines = 0;
reset($this->data_values);
while (list(, $row) = each($this->data_values)) {
$color_index = 0;
$i = 0;
while (list($key, $val) = each($row)) {
//echo "$key, $i, $val<br>";
if ($key == 0) {
$lab = $val;
} elseif ($key == 1) {
$x_now = $val;
$x_now_pixels = $this->xtr($x_now); //Use a bit more memory to save 2N operations.
} elseif ($key%3 == 2) {
$y_now = $val;
$y_now_pixels = $this->ytr($y_now);
//Draw Data Label
if ( $this->draw_data_labels == 1) {
$this->DrawDataLabel($lab,$x_now,$y_now);
}
if ($color_index >= count($this->ndx_data_color)) { $color_index=0;};
$barcol = $this->ndx_data_color[$color_index];
$error_barcol = $this->ndx_error_bar_color[$color_index];
//echo "start = $start_lines<br>";
if ($start_lines == 1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -