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

📄 jpgraph_pie.php

📁 极限网络智能办公系统 - Office Automation 2.8 100% 源码
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php

class pieplot
{

	var $posx = 0.5;
	var $posy = 0.5;
	var $radius = 0.3;
	var $explode_radius = array( );
	var $explode_all = false;
	var $explode_r = 20;
	var $labels = null;
	var $legends = null;
	var $csimtargets = null;
	var $csimareas = "";
	var $csimalts = null;
	var $data = null;
	var $title;
	var $startangle = 0;
	var $weight = 1;
	var $color = "black";
	var $legend_margin = 6;
	var $show_labels = true;
	var $themearr = array
	(
		"earth" => array
		(
			0 => 136,
			1 => 34,
			2 => 40,
			3 => 45,
			4 => 46,
			5 => 62,
			6 => 63,
			7 => 134,
			8 => 74,
			9 => 10,
			10 => 120,
			11 => 136,
			12 => 141,
			13 => 168,
			14 => 180,
			15 => 77,
			16 => 209,
			17 => 218,
			18 => 346,
			19 => 395,
			20 => 89,
			21 => 430
		),
		"td" => array
		(
			0 => 136,
			1 => 22,
			2 => 40,
			3 => 45,
			4 => 49,
			5 => 74,
			6 => 119,
			7 => 149,
			8 => 430,
			9 => 105,
			10 => 333,
			11 => 4,
			12 => 141,
			13 => 168,
			14 => 180,
			15 => 209,
			16 => 218,
			17 => 395,
			18 => 89
		),
		"pastel" => array
		(
			0 => 27,
			1 => 415,
			2 => 128,
			3 => 59,
			4 => 66,
			5 => 79,
			6 => 105,
			7 => 110,
			8 => 42,
			9 => 147,
			10 => 152,
			11 => 230,
			12 => 236,
			13 => 240,
			14 => 331,
			15 => 337,
			16 => 405,
			17 => 38
		),
		"water" => array
		(
			0 => 8,
			1 => 370,
			2 => 24,
			3 => 40,
			4 => 335,
			5 => 56,
			6 => 213,
			7 => 237,
			8 => 268,
			9 => 14,
			10 => 326,
			11 => 387,
			12 => 10,
			13 => 388
		),
		"sand" => array
		(
			0 => 27,
			1 => 168,
			2 => 34,
			3 => 170,
			4 => 19,
			5 => 50,
			6 => 65,
			7 => 72,
			8 => 131,
			9 => 209,
			10 => 46,
			11 => 393
		)
	);
	var $theme = "earth";
	var $setslicecolors = array( );
	var $labeltype = 0;
	var $pie_border = true;
	var $pie_interior_border = true;
	var $value;
	var $ishadowcolor = "";
	var $ishadowdrop = 4;
	var $ilabelposadj = 1;
	var $legendcsimtargets = array( );
	var $legendcsimalts = array( );
	var $adjusted_data = array( );
	var $guideline = null;
	var $guidelinemargin = 10;
	var $iShowGuideLineForSingle = false;
	var $iGuideLineCurve = false;
	var $iGuideVFactor = 1.4;
	var $iGuideLineRFactor = 0.8;

	function pieplot( $data )
	{
		$this->data = array_reverse( $data );
		$this->title = new text( "" );
		$this->title->setfont( FF_FONT1, FS_BOLD );
		$this->value = new displayvalue( );
		$this->value->show( );
		$this->value->setformat( "%.1f%%" );
		$this->guideline = new lineproperty( );
	}

	function setcenter( $x, $y = 0.5 )
	{
		$this->posx = $x;
		$this->posy = $y;
	}

	function setguidelines( $aFlg = true, $aCurved = true, $aAlways = false )
	{
		$this->guideline->show( $aFlg );
		$this->iShowGuideLineForSingle = $aAlways;
		$this->iGuideLineCurve = $aCurved;
	}

	function setguidelinesadjust( $aVFactor, $aRFactor = 0.8 )
	{
		$this->iGuideVFactor = $aVFactor;
		$this->iGuideLineRFactor = $aRFactor;
	}

	function setcolor( $aColor )
	{
		$this->color = $aColor;
	}

	function setslicecolors( $aColors )
	{
		$this->setslicecolors = $aColors;
	}

	function setshadow( $aColor = "darkgray", $aDropWidth = 4 )
	{
		$this->ishadowcolor = $aColor;
		$this->ishadowdrop = $aDropWidth;
	}

	function setcsimtargets( $targets, $alts = null )
	{
		$this->csimtargets = array_reverse( $targets );
		if ( is_array( $alts ) )
		{
			$this->csimalts = array_reverse( $alts );
		}
	}

	function getcsimareas( )
	{
		return $this->csimareas;
	}

	function addslicetocsim( $i, $xc, $yc, $radius, $sa, $ea )
	{
		while ( 2 * M_PI < $sa )
		{
			$sa = $sa - 2 * M_PI;
		}
		while ( 2 * M_PI < $ea )
		{
			$ea = $ea - 2 * M_PI;
		}
		$sa = 2 * M_PI - $sa;
		$ea = 2 * M_PI - $ea;
		if ( abs( $sa - $ea ) < 0.0001 )
		{
			$sa = 2 * M_PI;
			$ea = 0;
		}
		$xc = floor( $xc );
		$yc = floor( $yc );
		$coords = "{$xc}, {$yc}";
		$xp = floor( $radius * cos( $ea ) + $xc );
		$yp = floor( $yc - $radius * sin( $ea ) );
		$coords .= ", {$xp}, {$yp}";
		$a = $ea + 0.2;
		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.2;
			}
			$a -= 2 * M_PI;
		}
		while ( $a < $sa )
		{
			$xp = floor( $radius * cos( $a ) + $xc );
			$yp = floor( $yc - $radius * sin( $a ) );
			$coords .= ", {$xp}, {$yp}";
			$a += 0.2;
		}
		$xp = floor( $radius * cos( $sa ) + $xc );
		$yp = floor( $yc - $radius * sin( $sa ) );
		$coords .= ", {$xp}, {$yp}";
		if ( !empty( $this->csimtargets[$i] ) )
		{
			$this->csimareas .= "<area shape=\"poly\" coords=\"{$coords}\" href=\"".$this->csimtargets[$i]."\"";
			$tmp = "";
			if ( !empty( $this->csimalts[$i] ) )
			{
				$tmp = sprintf( $this->csimalts[$i], $this->data[$i] );
				$this->csimareas .= " title=\"{$tmp}\"";
			}
			$this->csimareas .= " alt=\"{$tmp}\" />\n";
		}
	}

	function settheme( $aTheme )
	{
		if ( in_array( $aTheme, array_keys( $this->themearr ) ) )
		{
			$this->theme = $aTheme;
		}
		else
		{
			jpgrapherror::raise( "PiePLot::SetTheme() Unknown theme: {$aTheme}" );
		}
	}

	function explodeslice( $e, $radius = 20 )
	{
		if ( !is_integer( $e ) )
		{
			jpgrapherror::raise( "Argument to PiePlot::ExplodeSlice() must be an integer" );
		}
		$this->explode_radius[$e] = $radius;
	}

	function explodeall( $radius = 20 )
	{
		$this->explode_all = true;
		$this->explode_r = $radius;
	}

	function explode( $aExplodeArr )
	{
		if ( !is_array( $aExplodeArr ) )
		{
			jpgrapherror::raise( "Argument to PiePlot::Explode() must be an array with integer distances." );
		}
		$this->explode_radius = $aExplodeArr;
	}

	function setstartangle( $aStart )
	{
		if ( $aStart < 0 || 360 < $aStart )
		{
			jpgrapherror::raise( "Slice start angle must be between 0 and 360 degrees." );
		}
		$this->startangle = 360 - $aStart;
		$this->startangle *= M_PI / 180;
	}

	function setfont( $family, $style = FS_NORMAL, $size = 10 )
	{
		jpgrapherror::raise( "PiePlot::SetFont() is deprecated. Use PiePlot->value->SetFont() instead." );
	}

	function setsize( $aSize )
	{
		if ( 0 < $aSize && $aSize <= 0.5 || 10 < $aSize && $aSize < 1000 )
		{
			$this->radius = $aSize;
		}
		else
		{
			jpgrapherror::raise( "PiePlot::SetSize() Radius for pie must either be specified as a fraction\n                                [0, 0.5] of the size of the image or as an absolute size in pixels \n                                in the range [10, 1000]" );
		}
	}

	function setfontcolor( $aColor )
	{
		jpgrapherror::raise( "PiePlot::SetFontColor() is deprecated. Use PiePlot->value->SetColor() instead." );
	}

	function setlegends( $aLegend )
	{
		$this->legends = $aLegend;
	}

	function setlabels( $aLabels, $aLblPosAdj = "auto" )
	{
		$this->labels = array_reverse( $aLabels );
		$this->ilabelposadj = $aLblPosAdj;
	}

	function setlabelpos( $aLblPosAdj )
	{
		$this->ilabelposadj = $aLblPosAdj;
	}

	function setlabeltype( $t )
	{
		if ( $t < 0 || 2 < $t )
		{
			jpgrapherror::raise( "PiePlot::SetLabelType() Type for pie plots must be 0 or 1 (not {$t})." );
		}
		$this->labeltype = $t;
	}

	function setvaluetype( $aType )
	{
		$this->setlabeltype( $aType );
	}

	function showborder( $exterior = true, $interior = true )
	{
		$this->pie_border = $exterior;
		$this->pie_interior_border = $interior;
	}

	function legend( &$graph )
	{
		$colors = array_keys( $graph->img->rgb->rgb_table );
		sort( $colors );
		$ta = $this->themearr[$this->theme];
		$n = count( $this->data );
		if ( $this->setslicecolors == null )
		{
			$numcolors = count( $ta );
			if ( get_class( $this ) === "pieplot3d" )
			{
				$ta = array_reverse( array_slice( $ta, 0, $n ) );
			}
		}
		else
		{
			$this->setslicecolors = array_slice( $this->setslicecolors, 0, $n );
			$numcolors = count( $this->setslicecolors );
			if ( $graph->pieaa && get_class( $this ) === "pieplot" )
			{
				$this->setslicecolors = array_reverse( $this->setslicecolors );
			}
		}
		$sum = 0;
		$i = 0;
		for ( ;	$i < $n;	++$i	)
		{
			$sum += $this->data[$i];
		}
		if ( $sum == 0 )
		{
			jpgrapherror::raise( "Illegal pie plot. Sum of all data is zero for Pie!" );
		}
		$n = min( count( $this->legends ), count( $this->data ) );
		if ( $this->legends != "" )
		{
			$this->legends = array_reverse( array_slice( $this->legends, 0, $n ) );
		}
		$i = $n - 1;
		for ( ;	0 <= $i;	--$i	)
		{
			$l = $this->legends[$i];
			if ( $i < count( $this->csimalts ) )
			{
				$fmt = $this->csimalts[$i];
			}
			else
			{
				$fmt = "%d";
			}
			if ( $this->labeltype == 0 )
			{
				$l = sprintf( $l, 100 * $this->data[$i] / $sum );
				$alt = sprintf( $fmt, $this->data[$i] );
			}
			else if ( $this->labeltype == 1 )
			{
				$l = sprintf( $l, $this->data[$i] );
				$alt = sprintf( $fmt, $this->data[$i] );
			}
			else
			{
				$l = sprintf( $l, $this->adjusted_data[$i] );
				$alt = sprintf( $fmt, $this->adjusted_data[$i] );
			}
			if ( $this->setslicecolors == null )
			{
				$graph->legend->add( $l, $colors[$ta[$i % $numcolors]], "", 0, $this->csimtargets[$i], $alt );
			}
			else
			{
				$graph->legend->add( $l, $this->setslicecolors[$i % $numcolors], "", 0, $this->csimtargets[$i], $alt );
			}
		}
	}

	function adjpercentage( $aData, $aPrec = 0 )
	{
		$mul = 100;
		if ( 0 < $aPrec && $aPrec < 3 )
		{
			if ( $aPrec == 1 )
			{
				$mul = 1000;
			}
			else
			{
				$mul = 10000;
			}
		}
		$tmp = array( );
		$result = array( );
		$quote_sum = 0;
		$n = count( $aData );
		$i = 0;
		$sum = 0;
		for ( ;	$i < $n;	++$i	)
		{
			$sum += $aData[$i];
		}
		foreach ( $aData as $index => $value )
		{
			$tmp_percentage = $value / $sum * $mul;
			$result[$index] = floor( $tmp_percentage );
			$tmp[$index] = $tmp_percentage - $result[$index];
			$quote_sum += $result[$index];
		}
		if ( $quote_sum == $mul )
		{
			if ( 100 < $mul )
			{
				$tmp = $mul / 100;
				$i = 0;
				for ( ;	$i < $n;	++$i	)
				{
					$result[$i] /= $tmp;
				}
			}
			return $result;
		}
		arsort( $tmp, SORT_NUMERIC );
		reset( $tmp );
		$i = 0;
		for ( ;	$i < $mul - $quote_sum;	++$i	)
		{
			++$result[key( $tmp )];
			next( $tmp );
		}
		if ( 100 < $mul )
		{
			$tmp = $mul / 100;
			$i = 0;
			for ( ;	$i < $n;	++$i	)
			{
				$result[$i] /= $tmp;
			}
		}
		return $result;
	}

	function stroke( &$img, $aaoption = 0 )
	{
		$expscale = $aaoption === 1 ? 2 : 1;
		if ( $this->labeltype == 2 )
		{
			$this->adjusted_data = $this->adjpercentage( $this->data );
		}
		$colors = array_keys( $img->rgb->rgb_table );
		sort( $colors );
		$ta = $this->themearr[$this->theme];
		$n = count( $this->data );
		if ( $this->setslicecolors == null )
		{
			$numcolors = count( $ta );
		}
		else
		{
			$this->setslicecolors = array_reverse( array_slice( $this->setslicecolors, 0, $n ) );
			$numcolors = count( $this->setslicecolors );
			$tt = array_slice( $this->setslicecolors, $n % $numcolors );
			$tt2 = array_slice( $this->setslicecolors, 0, $n % $numcolors );
			$tt2 = array_merge( $tt, $tt2 );
			$this->setslicecolors = $tt + $tt2;
		}
		$sum = 0;

⌨️ 快捷键说明

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