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

📄 jpgraph_pie.php

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

class PiePlot
{

	public $posx = 0.5;
	public $posy = 0.5;
	protected $radius = 0.3;
	protected $explode_radius = array( );
	protected $explode_all = false;
	protected $explode_r = 20;
	protected $labels = null;
	protected $legends = null;
	protected $csimtargets = null;
	protected $csimareas = "";
	protected $csimalts = null;
	protected $data = null;
	public $title = NULL;
	protected $startangle = 0;
	protected $weight = 1;
	protected $color = "black";
	protected $legend_margin = 6;
	protected $show_labels = true;
	protected $themearr = array
	(
		"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
		),
		"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
		),
		"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
		)
	);
	protected $theme = "earth";
	protected $setslicecolors = array( );
	protected $labeltype = 0;
	protected $pie_border = true;
	protected $pie_interior_border = true;
	public $value = NULL;
	protected $ishadowcolor = "";
	protected $ishadowdrop = 4;
	protected $ilabelposadj = 1;
	protected $legendcsimtargets = array( );
	protected $legendcsimalts = array( );
	protected $adjusted_data = array( );
	public $guideline = null;
	protected $guidelinemargin = 10;
	protected $iShowGuideLineForSingle = false;
	protected $iGuideLineCurve = false;
	protected $iGuideVFactor = 1.4;
	protected $iGuideLineRFactor = 0.8;

	public 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( );
	}

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

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

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

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

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

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

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

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

	public function AddSliceToCSIM( $i, $xc, $yc, $radius, $sa, $ea )
	{
		while ( 2 * M_PI < $sa )
		{
			$sa -= 2 * M_PI;
		}
		while ( 2 * M_PI < $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";
		}
	}

	public function SetTheme( $aTheme )
	{
		if ( in_array( $aTheme, array_keys( $this->themearr ) ) )
		{
			$this->theme = $aTheme;
		}
		else
		{
			JpGraphError::raisel( 15001, $aTheme );
		}
	}

	public function ExplodeSlice( $e, $radius = 20 )
	{
		if ( !is_integer( $e ) )
		{
			JpGraphError::raisel( 15002 );
		}
		$this->explode_radius[$e] = $radius;
	}

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

	public function Explode( $aExplodeArr )
	{
		if ( !is_array( $aExplodeArr ) )
		{
			JpGraphError::raisel( 15003 );
		}
		$this->explode_radius = $aExplodeArr;
	}

	public function SetStartAngle( $aStart )
	{
		if ( $aStart < 0 || 360 < $aStart )
		{
			JpGraphError::raisel( 15004 );
		}
		$this->startangle = 360 - $aStart;
		$this->startangle *= M_PI / 180;
	}

	public function SetFont( $family, $style = FS_NORMAL, $size = 10 )
	{
		JpGraphError::raisel( 15005 );
	}

	public function SetSize( $aSize )
	{
		if ( !( 0 < $aSize ) && $aSize <= 0.5 || 10 < $aSize && $aSize < 1000 )
		{
			$this->radius = $aSize;
		}
		else
		{
			JpGraphError::raisel( 15006 );
		}
	}

	public function SetFontColor( $aColor )
	{
		JpGraphError::raisel( 15007 );
	}

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

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

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

	public function SetLabelType( $t )
	{
		if ( $t < 0 || 2 < $t )
		{
			JpGraphError::raisel( 15008, $t );
		}
		$this->labeltype = $t;
	}

	public function SetValueType( $aType )
	{
		$this->SetLabelType( $aType );
	}

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

	public 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 ( class_exists( "PiePlot3D", false ) && $this instanceof 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 && $this instanceof PiePlot )
			{
				$this->setslicecolors = array_reverse( $this->setslicecolors );
			}
		}
		$sum = 0;
		$i = 0;
		for ( ;	$i < $n;	++$i	)
		{
			$sum += $this->data[$i];
		}
		if ( $sum == 0 )
		{
			JpGraphError::raisel( 15009 );
		}
		$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 );
			}
		}
	}

	public 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;

⌨️ 快捷键说明

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