⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpgraph_pie.php

📁 通达OA2007SE源代码 非常好的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
	    $r += $img->GetFontHeight()/1.5;	    $xt=round($r*cos($a)+$xc);	    $yt=round($yc-$r*sin($a));	    // Normalize angle	    while( $a < 0 ) $a += 2*M_PI;	    while( $a > 2*M_PI ) $a -= 2*M_PI;	    if( $a>=7*M_PI/4 || $a <= M_PI/4 ) $dx=0;	    if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dx=($a-M_PI/4)*2/M_PI; 	    if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dx=1;	    if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dx=(1-($a-M_PI*5/4)*2/M_PI);	    	    if( $a>=7*M_PI/4 ) $dy=(($a-M_PI)-3*M_PI/4)*2/M_PI;	    if( $a<=M_PI/4 ) $dy=(1-$a*2/M_PI);	    if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dy=1;	    if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dy=(1-($a-3*M_PI/4)*2/M_PI);	    if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dy=0;	    	    $this->value->Stroke($img,$label,$xt-$dx*$w,$yt-$dy*$h);	}    }	} // Class//===================================================// CLASS PiePlotC// Description: Same as a normal pie plot but with a // filled circle in the center//===================================================class PiePlotC extends PiePlot {    private $imidsize=0.5;		// Fraction of total width    private $imidcolor='white';    public $midtitle='';    private $middlecsimtarget="",$middlecsimalt="";    function PiePlotC($data,$aCenterTitle='') {	parent::PiePlot($data);	$this->midtitle = new Text();	$this->midtitle->ParagraphAlign('center');    }    function SetMid($aTitle,$aColor='white',$aSize=0.5) {	$this->midtitle->Set($aTitle);	$this->imidsize = $aSize ; 	$this->imidcolor = $aColor ;     }    function SetMidTitle($aTitle) {	$this->midtitle->Set($aTitle);    }    function SetMidSize($aSize) {	$this->imidsize = $aSize ;     }    function SetMidColor($aColor) {	$this->imidcolor = $aColor ;     }    function SetMidCSIM($aTarget,$aAlt) {	$this->middlecsimtarget = $aTarget;	$this->middlecsimalt = $aAlt;    }    function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) {          //Slice number, ellipse centre (x,y), radius, start angle, end angle	while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI;	while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI;	$sa = 2*M_PI - $sa;	$ea = 2*M_PI - $ea;	// Special case when we have only one slice since then both start and end	// angle will be == 0	if( abs($sa - $ea) < 0.0001 ) {	    $sa=2*M_PI; $ea=0;	}	// Add inner circle first point	$xp = floor(($this->imidsize*$radius*cos($ea))+$xc);	$yp = floor($yc-($this->imidsize*$radius*sin($ea)));	$coords = "$xp, $yp";		//add coordinates every 0.25 radians	$a=$ea+0.25;	// If we cross the 360-limit with a slice we need to handle	// the fact that end angle is smaller than start	if( $sa < $ea ) {	    while ($a <= 2*M_PI) {		$xp = floor($radius*cos($a)+$xc);		$yp = floor($yc-$radius*sin($a));		$coords.= ", $xp, $yp";		$a += 0.25;	    }	    $a -= 2*M_PI;	}	while ($a < $sa) {	    $xp = floor(($this->imidsize*$radius*cos($a)+$xc));	    $yp = floor($yc-($this->imidsize*$radius*sin($a)));	    $coords.= ", $xp, $yp";	    $a += 0.25;	}	// Make sure we end at the last point	$xp = floor(($this->imidsize*$radius*cos($sa)+$xc));	$yp = floor($yc-($this->imidsize*$radius*sin($sa)));	$coords.= ", $xp, $yp";	// Straight line to outer circle	$xp = floor($radius*cos($sa)+$xc);	$yp = floor($yc-$radius*sin($sa));	$coords.= ", $xp, $yp";		//add coordinates every 0.25 radians	$a=$sa - 0.25;	while ($a > $ea) {	    $xp = floor($radius*cos($a)+$xc);	    $yp = floor($yc-$radius*sin($a));	    $coords.= ", $xp, $yp";	    $a -= 0.25;	}			//Add the last point on the arc	$xp = floor($radius*cos($ea)+$xc);	$yp = floor($yc-$radius*sin($ea));	$coords.= ", $xp, $yp";	// Close the arc	$xp = floor(($this->imidsize*$radius*cos($ea))+$xc);	$yp = floor($yc-($this->imidsize*$radius*sin($ea)));	$coords .= ", $xp, $yp";	if( !empty($this->csimtargets[$i]) ) {	    $this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".		$this->csimtargets[$i]."\"";	    if( !empty($this->csimalts[$i]) ) {		$tmp=sprintf($this->csimalts[$i],$this->data[$i]);		$this->csimareas .= " title=\"$tmp\"";	    }	    $this->csimareas .= " alt=\"$tmp\" />\n";	}    }    function Stroke($img,$aaoption=0) {	// Stroke the pie but don't stroke values	$tmp =  $this->value->show;	$this->value->show = false;	parent::Stroke($img,$aaoption);	$this->value->show = $tmp; 	$xc = round($this->posx*$img->width);	$yc = round($this->posy*$img->height);	$radius = floor($this->radius * min($img->width,$img->height)) ;	if( $this->imidsize > 0 && $aaoption !== 2 ) {	    if( $this->ishadowcolor != "" ) {		$img->SetColor($this->ishadowcolor);		$img->FilledCircle($xc+$this->ishadowdrop,$yc+$this->ishadowdrop,				   round($radius*$this->imidsize));	    }	    $img->SetColor($this->imidcolor);	    $img->FilledCircle($xc,$yc,round($radius*$this->imidsize));	    if(  $this->pie_border && $aaoption === 0 ) {		$img->SetColor($this->color);		$img->Circle($xc,$yc,round($radius*$this->imidsize));	    }	    if( !empty($this->middlecsimtarget) )		$this->AddMiddleCSIM($xc,$yc,round($radius*$this->imidsize));	}	if( $this->value->show && $aaoption !== 1) {	    $this->StrokeAllLabels($img,$xc,$yc,$radius);	    $this->midtitle->SetPos($xc,$yc,'center','center');	    $this->midtitle->Stroke($img);	}    }    function AddMiddleCSIM($xc,$yc,$r) {	$xc=round($xc);$yc=round($yc);$r=round($r);	$this->csimareas .= "<area shape=\"circle\" coords=\"$xc,$yc,$r\" href=\"".	    $this->middlecsimtarget."\"";	if( !empty($this->middlecsimalt) ) {	    $tmp = $this->middlecsimalt;	    $this->csimareas .= " title=\"$tmp\"";	}	$this->csimareas .= " alt=\"$tmp\" />\n";    }    function StrokeLabel($label,$img,$xc,$yc,$a,$r) {	if( $this->ilabelposadj === 'auto' )	    $this->ilabelposadj = (1-$this->imidsize)/2+$this->imidsize;	parent::StrokeLabel($label,$img,$xc,$yc,$a,$r);    }}//===================================================// CLASS PieGraph// Description: //===================================================class PieGraph extends Graph {    private $posx, $posy, $radius;		    private $legends=array();	    public $plots=array();    public $pieaa = false ;//---------------// CONSTRUCTOR    function PieGraph($width=300,$height=200,$cachedName="",$timeout=0,$inline=1) {	$this->Graph($width,$height,$cachedName,$timeout,$inline);	$this->posx=$width/2;	$this->posy=$height/2;	$this->SetColor(array(255,255,255));		    }//---------------// PUBLIC METHODS	    function Add($aObj) {	if( is_array($aObj) && count($aObj) > 0 )	    $cl = $aObj[0];	else	    $cl = $aObj;	if( $cl instanceof Text ) 	    $this->AddText($aObj);	elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) ) 	    $this->AddIcon($aObj);	else {	    if( is_array($aObj) ) {		$n = count($aObj);		for($i=0; $i < $n; ++$i ) {		    $this->plots[] = $aObj[$i];		}	    }	    else {		$this->plots[] = $aObj;	    }	}    }    function SetAntiAliasing($aFlg=true) {	$this->pieaa = $aFlg;    }	    function SetColor($c) {	$this->SetMarginColor($c);    }    function DisplayCSIMAreas() {	    $csim="";	    foreach($this->plots as $p ) {		$csim .= $p->GetCSIMareas();	    }	    //$csim.= $this->legend->GetCSIMareas();	    if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) {		$this->img->SetColor($this->csimcolor);		$n = count($coords[0]);		for ($i=0; $i < $n; $i++) {		    if ($coords[1][$i]=="poly") {			preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts);			$this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]);			$m = count($pts[0]);			for ($j=0; $j < $m; $j++) {			    $this->img->LineTo($pts[1][$j],$pts[2][$j]);			}		    } else if ($coords[1][$i]=="rect") {			$pts = preg_split('/,/', $coords[2][$i]);			$this->img->SetStartPoint($pts[0],$pts[1]);			$this->img->LineTo($pts[2],$pts[1]);			$this->img->LineTo($pts[2],$pts[3]);			$this->img->LineTo($pts[0],$pts[3]);			$this->img->LineTo($pts[0],$pts[1]);								    }		}	    }    }    // Method description    function Stroke($aStrokeFileName="") {	// If the filename is the predefined value = '_csim_special_'	// we assume that the call to stroke only needs to do enough	// to correctly generate the CSIM maps.	// We use this variable to skip things we don't strictly need	// to do to generate the image map to improve performance	// a best we can. Therefor you will see a lot of tests !$_csim in the	// code below.	$_csim = ($aStrokeFileName===_CSIM_SPECIALFILE);	// We need to know if we have stroked the plot in the	// GetCSIMareas. Otherwise the CSIM hasn't been generated	// and in the case of GetCSIM called before stroke to generate	// CSIM without storing an image to disk GetCSIM must call Stroke.	$this->iHasStroked = true;	$n = count($this->plots);	if( $this->pieaa ) {	    if( !$_csim ) {		if( $this->background_image != "" ) {		    $this->StrokeFrameBackground();				}		else {		    $this->StrokeFrame();				    $this->StrokeBackgroundGrad();		}	    }	    $w = $this->img->width;	    $h = $this->img->height;	    $oldimg = $this->img->img;	    $this->img->CreateImgCanvas(2*$w,2*$h);	    	    $this->img->SetColor( $this->margin_color );	    $this->img->FilledRectangle(0,0,2*$w-1,2*$h-1);	    // Make all icons *2 i size since we will be scaling down the	    // imahe to do the anti aliasing	    $ni = count($this->iIcons);	    for($i=0; $i < $ni; ++$i) {		$this->iIcons[$i]->iScale *= 2 ;		if( $this->iIcons[$i]->iX > 1 ) 		    $this->iIcons[$i]->iX *= 2 ;		if( $this->iIcons[$i]->iY > 1 ) 		    $this->iIcons[$i]->iY *= 2 ;	    }	    $this->StrokeIcons();	    for($i=0; $i < $n; ++$i) {		if( $this->plots[$i]->posx > 1 ) 		    $this->plots[$i]->posx *= 2 ;		if( $this->plots[$i]->posy > 1 ) 		    $this->plots[$i]->posy *= 2 ;		$this->plots[$i]->Stroke($this->img,1);		if( $this->plots[$i]->posx > 1 ) 		    $this->plots[$i]->posx /= 2 ;		if( $this->plots[$i]->posy > 1 ) 		    $this->plots[$i]->posy /= 2 ;	    }	    $indent = $this->doframe ? ($this->frame_weight + ($this->doshadow ? $this->shadow_width : 0 )) : 0 ;	    $indent += $this->framebevel ? $this->framebeveldepth + 1 : 0 ;	    $this->img->CopyCanvasH($oldimg,$this->img->img,$indent,$indent,$indent,$indent,				    $w-2*$indent,$h-2*$indent,2*($w-$indent),2*($h-$indent));	    $this->img->img = $oldimg ;	    $this->img->width = $w ;	    $this->img->height = $h ;	    for($i=0; $i < $n; ++$i) {		$this->plots[$i]->Stroke($this->img,2); // Stroke labels		$this->plots[$i]->Legend($this);	    }	}	else {	    if( !$_csim ) {		if( $this->background_image != "" ) {		    $this->StrokeFrameBackground();				}		else {		    $this->StrokeFrame();				}	    }	    $this->StrokeIcons();	    for($i=0; $i < $n; ++$i) {		$this->plots[$i]->Stroke($this->img);		$this->plots[$i]->Legend($this);	    }	}	$this->legend->Stroke($this->img);	$this->footer->Stroke($this->img);	$this->StrokeTitles();	if( !$_csim ) {		    // Stroke texts	    if( $this->texts != null ) {		$n = count($this->texts);		for($i=0; $i < $n; ++$i ) {		    $this->texts[$i]->Stroke($this->img);		}	    }	    if( _JPG_DEBUG ) {		$this->DisplayCSIMAreas();	    }	    // Should we do any final image transformation	    if( $this->iImgTrans ) {		if( !class_exists('ImgTrans',false) ) {		    require_once('jpgraph_imgtrans.php');		    //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.');		}	       		$tform = new ImgTrans($this->img->img);		$this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist,						 $this->iImgTransDirection,$this->iImgTransHighQ,						 $this->iImgTransMinSize,$this->iImgTransFillColor,						 $this->iImgTransBorder);	    }	    // If the filename is given as the special "__handle"	    // then the image handler is returned and the image is NOT	    // streamed back	    if( $aStrokeFileName == _IMG_HANDLER ) {		return $this->img->img;	    }	    else {		// Finally stream the generated picture							$this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,					   $aStrokeFileName);			    }	}    }} // Class/* EOF */?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -