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

📄 jpgraph_pie.php

📁 极限网络智能办公系统 - Office Automation 2.8 100% 源码
💻 PHP
📖 第 1 页 / 共 3 页
字号:
		$i = 0;
		for ( ;	$i < $n;	++$i	)
		{
			$sum += $this->data[$i];
		}
		if ( $sum == 0 )
		{
			jpgrapherror::raise( "Sum of all data is 0 for Pie." );
		}
		if ( $this->radius <= 1 )
		{
			$radius = floor( $this->radius * min( $img->width, $img->height ) );
		}
		else
		{
			$radius = $aaoption === 1 ? $this->radius * 2 : $this->radius;
		}
		if ( $this->posx <= 1 && 0 < $this->posx )
		{
			$xc = round( $this->posx * $img->width );
		}
		else
		{
			$xc = $this->posx;
		}
		if ( $this->posy <= 1 && 0 < $this->posy )
		{
			$yc = round( $this->posy * $img->height );
		}
		else
		{
			$yc = $this->posy;
		}
		$n = count( $this->data );
		if ( $this->explode_all )
		{
			$i = 0;
			for ( ;	$i < $n;	++$i	)
			{
				$this->explode_radius[$i] = $this->explode_r;
			}
		}
		if ( $this->ishadowcolor != "" && $aaoption !== 2 )
		{
			$accsum = 0;
			$angle2 = $this->startangle;
			$img->setcolor( $this->ishadowcolor );
			$i = 0;
			for ( ;	0 < $sum && $i < $n;	++$i	)
			{
				$j = $n - $i - 1;
				$d = $this->data[$i];
				$angle1 = $angle2;
				$accsum += $d;
				$angle2 = $this->startangle + 2 * M_PI * $accsum / $sum;
				if ( empty( $this->explode_radius[$j] ) )
				{
					$this->explode_radius[$j] = 0;
				}
				$la = 2 * M_PI - ( abs( $angle2 - $angle1 ) / 2 + $angle1 );
				$xcm = $xc + $this->explode_radius[$j] * cos( $la ) * $expscale;
				$ycm = $yc - $this->explode_radius[$j] * sin( $la ) * $expscale;
				$xcm += $this->ishadowdrop * $expscale;
				$ycm += $this->ishadowdrop * $expscale;
				$img->cakeslice( $xcm, $ycm, $radius, $radius, $angle1 * 180 / M_PI, $angle2 * 180 / M_PI, $this->ishadowcolor );
			}
		}
		$accsum = 0;
		$angle2 = $this->startangle;
		$img->setcolor( $this->color );
		$i = 0;
		for ( ;	0 < $sum && $i < $n;	++$i	)
		{
			$j = $n - $i - 1;
			if ( empty( $this->explode_radius[$j] ) )
			{
				$this->explode_radius[$j] = 0;
			}
			$d = $this->data[$i];
			$angle1 = $angle2;
			$accsum += $d;
			$angle2 = $this->startangle + 2 * M_PI * $accsum / $sum;
			$this->la[$i] = 2 * M_PI - ( abs( $angle2 - $angle1 ) / 2 + $angle1 );
			if ( $d == 0 )
			{
			}
			else
			{
				if ( $this->setslicecolors == null )
				{
					$slicecolor = $colors[$ta[$i % $numcolors]];
				}
				else
				{
					$slicecolor = $this->setslicecolors[$i % $numcolors];
				}
				if ( $this->pie_interior_border && $aaoption === 0 )
				{
					$img->setcolor( $this->color );
				}
				else
				{
					$img->setcolor( $slicecolor );
				}
				$arccolor = $this->pie_border && $aaoption === 0 ? $this->color : "";
				$xcm = $xc + $this->explode_radius[$j] * cos( $this->la[$i] ) * $expscale;
				$ycm = $yc - $this->explode_radius[$j] * sin( $this->la[$i] ) * $expscale;
				if ( $aaoption !== 2 )
				{
					$img->cakeslice( $xcm, $ycm, $radius - 1, $radius - 1, $angle1 * 180 / M_PI, $angle2 * 180 / M_PI, $slicecolor, $arccolor );
				}
				if ( $this->csimtargets && $aaoption !== 1 )
				{
					$this->addslicetocsim( $i, $xcm, $ycm, $radius, $angle1, $angle2 );
				}
			}
		}
		if ( $aaoption !== 2 )
		{
			$i = 0;
			for ( ;	$i < $n;	++$i	)
			{
				if ( $this->labeltype == 0 )
				{
					if ( $sum != 0 )
					{
						$l = 100 * $this->data[$i] / $sum;
					}
					else
					{
						$l = 0;
					}
				}
				else if ( $this->labeltype == 1 )
				{
					$l = $this->data[$i] * 1;
				}
				else
				{
					$l = $this->adjusted_data[$i];
				}
				if ( isset( $this->labels[$i] ) && is_string( $this->labels[$i] ) )
				{
					$this->labels[$i] = sprintf( $this->labels[$i], $l );
				}
				else
				{
					$this->labels[$i] = $l;
				}
			}
		}
		if ( $this->value->show && $aaoption !== 1 )
		{
			$this->strokealllabels( $img, $xc, $yc, $radius );
		}
		if ( $aaoption !== 1 )
		{
			$this->title->pos( $xc, $yc - $this->title->getfontheight( $img ) - $radius - $this->title->margin, "center", "bottom" );
			$this->title->stroke( $img );
		}
	}

	function normangle( $a )
	{
		while ( $a < 0 )
		{
			$a += 2 * M_PI;
		}
		while ( 2 * M_PI < $a )
		{
			$a -= 2 * M_PI;
		}
		return $a;
	}

	function quadrant( $a )
	{
		$a = $this->normangle( $a );
		if ( 0 < $a && $a <= M_PI / 2 )
		{
			return 0;
		}
		if ( M_PI / 2 < $a && $a <= M_PI )
		{
			return 1;
		}
		if ( M_PI < $a && $a <= 1.5 * M_PI )
		{
			return 2;
		}
		if ( 1.5 * M_PI < $a )
		{
			return 3;
		}
	}

	function strokeguidelabels( $img, $xc, $yc, $radius )
	{
		$n = count( $this->labels );
		$tresh_hold = 25 * M_PI / 180;
		$incluster = false;
		$clusters = array( );
		$cidx = -1;
		$i = 0;
		for ( ;	$i < $n - 1;	++$i	)
		{
			$a1 = $this->la[$i];
			$a2 = $this->la[$i + 1];
			$q1 = $this->quadrant( $a1 );
			$q2 = $this->quadrant( $a2 );
			$diff = abs( $a1 - $a2 );
			if ( $diff < $tresh_hold )
			{
				if ( $incluster )
				{
					++$clusters[$cidx][1];
					if ( $q1 != $q2 )
					{
						if ( $q1 == 1 && $q2 == 0 && 75 * M_PI / 180 < $a2 )
						{
							if ( $i < $n - 2 )
							{
								$a3 = $this->la[$i + 2];
								if ( $tresh_hold <= abs( $a3 - $a2 ) )
								{
									++$clusters[$cidx][1];
									++$i;
								}
							}
						}
						else if ( $q1 == 3 && $q2 == 2 && 255 * M_PI / 180 < $a2 && $i < $n - 2 )
						{
							$a3 = $this->la[$i + 2];
							if ( $tresh_hold <= abs( $a3 - $a2 ) )
							{
								++$clusters[$cidx][1];
								++$i;
							}
						}
						if ( $q1 == 2 && $q2 == 1 && 165 * M_PI / 180 < $a2 )
						{
							++$clusters[$cidx][1];
							++$i;
						}
						$incluster = false;
					}
				}
				else if ( $q1 == $q2 )
				{
					$incluster = true;
					if ( $q1 == 0 && -1 < $cidx && $clusters[$cidx][1] == 1 && $this->quadrant( $this->la[$clusters[$cidx][0]] ) == 0 )
					{
						++$clusters[$cidx][1];
					}
					else
					{
						++$cidx;
						$clusters[$cidx][0] = $i;
						$clusters[$cidx][1] = 1;
					}
				}
				else
				{
					++$cidx;
					$clusters[$cidx][0] = $i;
					$clusters[$cidx][1] = 1;
				}
			}
			else if ( $incluster )
			{
				++$clusters[$cidx][1];
				$incluster = false;
			}
			else
			{
				++$cidx;
				$clusters[$cidx][0] = $i;
				$clusters[$cidx][1] = 1;
			}
		}
		if ( $incluster )
		{
			++$clusters[$cidx][1];
		}
		else
		{
			++$cidx;
			$clusters[$cidx][0] = $i;
			$clusters[$cidx][1] = 1;
		}
		$img->setfont( $this->value->ff, $this->value->fs, $this->value->fsize );
		$fh = $img->getfontheight( );
		$origvstep = $fh * $this->iGuideVFactor;
		$this->value->setmargin( 0 );
		$nc = count( $clusters );
		$i = 0;
		for ( ;	$i < $nc;	++$i	)
		{
			$csize = $clusters[$i][1];
			$a = $this->la[$clusters[$i][0]];
			$q = $this->quadrant( $a );
			if ( $q == 0 )
			{
				$start = $csize - 1;
				$idx = $start;
				$step = -1;
				$vstep = 0 - $origvstep;
			}
			else if ( $q == 1 )
			{
				$start = 0;
				$idx = $start;
				$step = 1;
				$vstep = 0 - $origvstep;
			}
			else if ( $q == 2 )
			{
				$start = $csize - 1;
				$idx = $start;
				$step = -1;
				$vstep = $origvstep;
			}
			else if ( $q == 3 )
			{
				$start = 0;
				$idx = $start;
				$step = 1;
				$vstep = $origvstep;
			}
			$j = 0;
			for ( ;	$j < $csize;	++$j	)
			{
				$a = $this->la[$clusters[$i][0] + $idx];
				$r = $radius + $this->explode_radius[$n - 1 - ( $clusters[$i][0] + $idx )];
				$x = round( $r * cos( $a ) + $xc );
				$y = round( $yc - $r * sin( $a ) );
				$r += $fh * $this->iGuideLineRFactor;
				if ( $this->iGuideLineCurve )
				{
					$xt = round( $r * cos( $a ) + $xc );
				}
				if ( $idx == $start )
				{
					if ( !$this->iGuideLineCurve )
					{
						$xt = round( $r * cos( $a ) + $xc );
					}
					$yt = round( $yc - $r * sin( $a ) );
					$prevcluster = ( $i + ( $nc - 1 ) ) % $nc;
					$previdx = $clusters[$prevcluster][0] + $clusters[$prevcluster][1] - 1;
					if ( $q == 1 && 160 * M_PI / 180 < $a )
					{
						$diff = abs( $a - $this->la[$previdx] );
						if ( $diff < $tresh_hold )
						{
							$yt -= $fh;
						}
					}
					else if ( $q == 3 && 340 * M_PI / 180 < $a )
					{
						$diff = abs( $a - $this->la[$previdx] - 360 * M_PI / 180 );
						if ( $diff < $tresh_hold )
						{
							$yt += $fh;
						}
					}
				}
				else
				{
					$prev_a = $this->la[$clusters[$i][0] + ( $idx - $step )];
					$dy = abs( $radius * ( sin( $a ) - sin( $prev_a ) ) * 1.2 );
					if ( 0 < $vstep )
					{
						$yt += max( $vstep, $dy );
					}
					else
					{
						$yt += min( $vstep, 0 - $dy );
					}
				}
				$label = $this->labels[$clusters[$i][0] + $idx];
				if ( $csize == 1 )
				{
					$r = $radius + $this->explode_radius[$n - 1 - ( $clusters[$i][0] + $idx )];
					$rr = $r + $img->getfontheight( ) / 2;
					$xt = round( $rr * cos( $a ) + $xc );
					$yt = round( $yc - $rr * sin( $a ) );
					$this->strokelabel( $label, $img, $xc, $yc, $a, $r );
					if ( $this->iShowGuideLineForSingle )
					{
						$this->guideline->stroke( $img, $x, $y, $xt, $yt );
					}
				}
				else
				{
					$this->guideline->stroke( $img, $x, $y, $xt, $yt );
					if ( $q == 1 || $q == 2 )
					{
						$this->guideline->stroke( $img, $xt, $yt, $xt - $this->guidelinemargin, $yt );
						$lbladj = 0 - $this->guidelinemargin - 5;
						$this->value->halign = "right";
						$this->value->valign = "center";
					}
					else
					{
						$this->guideline->stroke( $img, $xt, $yt, $xt + $this->guidelinemargin, $yt );
						$lbladj = $this->guidelinemargin + 5;
						$this->value->halign = "left";
						$this->value->valign = "center";
					}
					$this->value->stroke( $img, $label, $xt + $lbladj, $yt );
				}
				$idx += $step;
			}
		}
	}

	function strokealllabels( $img, $xc, $yc, $radius )
	{
		$n = count( $this->la );
		$i = 0;
		for ( ;	$i < $n;	++$i	)
		{
			$this->la[$i] = $this->normangle( $this->la[$i] );
		}
		if ( $this->guideline->iShow )
		{
			$this->strokeguidelabels( $img, $xc, $yc, $radius );
		}
		else
		{
			$n = count( $this->labels );
			$i = 0;
			for ( ;	$i < $n;	++$i	)
			{
				$this->strokelabel( $this->labels[$i], $img, $xc, $yc, $this->la[$i], $radius + $this->explode_radius[$n - 1 - $i] );
			}
		}
	}

	function strokelabel( $label, $img, $xc, $yc, $a, $radius )
	{
		if ( $this->ilabelposadj === "auto" )
		{
			$this->ilabelposadj = 0.65;
		}
		$r = $radius;
		if ( $this->ilabelposadj < 1 )
		{
			$this->value->setalign( "center", "center" );
			$this->value->margin = 0;
			$xt = round( $this->ilabelposadj * $r * cos( $a ) + $xc );
			$yt = round( $yc - $this->ilabelposadj * $r * sin( $a ) );
			$this->value->stroke( $img, $label, $xt, $yt );
		}
		else
		{
			$this->value->halign = "left";
			$this->value->valign = "top";
			$this->value->margin = 0;
			$img->setfont( $this->value->ff, $this->value->fs, $this->value->fsize );
			$h = $img->gettextheight( $label );
			if ( is_numeric( $label ) )
			{
				if ( 0 < $label )
				{
					$w = $img->gettextwidth( sprintf( $this->value->format, $label ) );
				}
				else
				{
					$w = $img->gettextwidth( sprintf( $this->value->negformat, $label ) );
				}
			}
			else
			{
				$w = $img->gettextwidth( $label );
			}
			if ( 1 < $this->ilabelposadj && $this->ilabelposadj < 5 )
			{
				$r *= $this->ilabelposadj;
			}
			$r += $img->getfontheight( ) / 1.5;
			$xt = round( $r * cos( $a ) + $xc );
			$yt = round( $yc - $r * sin( $a ) );
			while ( $a < 0 )
			{
				$a += 2 * M_PI;
			}
			while ( 2 * M_PI < $a )
			{
				$a -= 2 * M_PI;
			}
			if ( 7 * M_PI / 4 <= $a || $a <= M_PI / 4 )
			{
				$dx = 0;
			}
			if ( M_PI / 4 <= $a && $a <= 3 * M_PI / 4 )
			{
				$dx = ( $a - M_PI / 4 ) * 2 / M_PI;
			}
			if ( 3 * M_PI / 4 <= $a && $a <= 5 * M_PI / 4 )
			{
				$dx = 1;
			}
			if ( 5 * M_PI / 4 <= $a && $a <= 7 * M_PI / 4 )
			{
				$dx = 1 - ( $a - M_PI * 5 / 4 ) * 2 / M_PI;
			}
			if ( 7 * M_PI / 4 <= $a )
			{
				$dy = ( $a - M_PI - 3 * M_PI / 4 ) * 2 / M_PI;
			}
			if ( $a <= M_PI / 4 )
			{
				$dy = 1 - $a * 2 / M_PI;
			}
			if ( M_PI / 4 <= $a && $a <= 3 * M_PI / 4 )
			{
				$dy = 1;
			}
			if ( 3 * M_PI / 4 <= $a && $a <= 5 * M_PI / 4 )
			{
				$dy = 1 - ( $a - 3 * M_PI / 4 ) * 2 / M_PI;
			}
			if ( 5 * M_PI / 4 <= $a && $a <= 7 * M_PI / 4 )
			{
				$dy = 0;
			}
			$this->value->stroke( $img, $label, $xt - $dx * $w, $yt - $dy * $h );
		}
	}

⌨️ 快捷键说明

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