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

📄 jpgraph_utils.inc.php

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

class FuncGenerator
{

	private $iFunc = "";
	private $iXFunc = "";
	private $iMin = NULL;
	private $iMax = NULL;
	private $iStepSize = NULL;

	public function FuncGenerator( $aFunc, $aXFunc = "" )
	{
		$this->iFunc = $aFunc;
		$this->iXFunc = $aXFunc;
	}

	public function E( $aXMin, $aXMax, $aSteps = 50 )
	{
		$this->iMin = $aXMin;
		$this->iMax = $aXMax;
		$this->iStepSize = ( $aXMax - $aXMin ) / $aSteps;
		if ( $this->iXFunc != "" )
		{
			$t = "for(\$i=".$aXMin."; \$i<=".$aXMax."; \$i += ".$this->iStepSize.") {\$ya[]=".$this->iFunc.";\$xa[]=".$this->iXFunc.";}";
		}
		else if ( $this->iFunc != "" )
		{
			$t = "for(\$x=".$aXMin."; \$x<=".$aXMax."; \$x += ".$this->iStepSize.") {\$ya[]=".$this->iFunc.";\$xa[]=\$x;} \$x=".$aXMax.";\$ya[]=".$this->iFunc.";\$xa[]=\$x;";
		}
		else
		{
			JpGraphError::raisel( 24001 );
		}
		@eval( $t );
		if ( empty( $xa ) || empty( $ya ) )
		{
			JpGraphError::raisel( 24002 );
		}
		return array(
			$xa,
			$ya
		);
	}

}

class SymChar
{

	public static function Get( $aSymb, $aCapital = FALSE )
	{
		$iSymbols = array(
			array( "alpha", "03B1", "0391" ),
			array( "beta", "03B2", "0392" ),
			array( "gamma", "03B3", "0393" ),
			array( "delta", "03B4", "0394" ),
			array( "epsilon", "03B5", "0395" ),
			array( "zeta", "03B6", "0396" ),
			array( "ny", "03B7", "0397" ),
			array( "eta", "03B8", "0398" ),
			array( "theta", "03B8", "0398" ),
			array( "iota", "03B9", "0399" ),
			array( "kappa", "03BA", "039A" ),
			array( "lambda", "03BB", "039B" ),
			array( "mu", "03BC", "039C" ),
			array( "nu", "03BD", "039D" ),
			array( "xi", "03BE", "039E" ),
			array( "omicron", "03BF", "039F" ),
			array( "pi", "03C0", "03A0" ),
			array( "rho", "03C1", "03A1" ),
			array( "sigma", "03C3", "03A3" ),
			array( "tau", "03C4", "03A4" ),
			array( "upsilon", "03C5", "03A5" ),
			array( "phi", "03C6", "03A6" ),
			array( "chi", "03C7", "03A7" ),
			array( "psi", "03C8", "03A8" ),
			array( "omega", "03C9", "03A9" ),
			array( "euro", "20AC" ),
			array( "yen", "00A5" ),
			array( "pound", "20A4" ),
			array( "approx", "2248" ),
			array( "neq", "2260" ),
			array( "not", "2310" ),
			array( "def", "2261" ),
			array( "inf", "221E" ),
			array( "sqrt", "221A" ),
			array( "int", "222B" ),
			array( "copy", "00A9" ),
			array( "para", "00A7" )
		);
		$n = count( $iSymbols );
		$i = 0;
		$found = false;
		$aSymb = strtolower( $aSymb );
		while ( $i < $n && !$found )
		{
			$found = $aSymb === $iSymbols[$i++][0];
		}
		if ( $found )
		{
			$ca = $iSymbols[--$i];
			if ( $aCapital && count( $ca ) == 3 )
			{
				$s = $ca[2];
			}
			else
			{
				$s = $ca[1];
			}
			return sprintf( "&#%04d;", hexdec( $s ) );
		}
		return "";
	}

}

class DateScaleUtils
{

	private $starthour = NULL;
	private $startmonth = NULL;
	private $startday = NULL;
	private $startyear = NULL;
	private $endmonth = NULL;
	private $endyear = NULL;
	private $endday = NULL;
	private $tickPositions = array( );
	private $minTickPositions = array( );
	private $iUseWeeks = true;

	public function UseWeekFormat( $aFlg )
	{
		$this->iUseWeeks = $aFlg;
	}

	public function doYearly( $aType, $aMinor = false )
	{
		$i = 0;
		$j = 0;
		$m = $this->startmonth;
		$y = $this->startyear;
		if ( $this->startday == 1 )
		{
			$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, 1, $y );
		}
		++$m;
		switch ( $aType )
		{
		case DSUTILS_YEAR1 :
			do
			{
				$y = $this->startyear;
				for ( ;	$y <= $this->endyear;	++$y,	)
				{
					if ( $aMinor )
					{
						while ( $m <= 12 )
						{
							if ( !( $y == $this->endyear ) && !( $this->endmonth < $m ) )
							{
								$this->minTickPositions[$j++] = mktime( 0, 0, 0, $m, 1, $y );
							}
							++$m;
						}
						$m = 1;
					}
					$this->tickPositions[$i++] = mktime( 0, 0, 0, 1, 1, $y );
					break;
				}
			} while ( 1 );
		case DSUTILS_YEAR2 :
			do
			{
				$y = $this->startyear;
				if ( !( $y <= $this->endyear ) )
				{
					break;
				}
				$this->tickPositions[$i++] = mktime( 0, 0, 0, 1, 1, $y );
				$k = 0;
				for ( ;	$k < 1;	++$k	)
				{
					++$y;
					if ( $aMinor )
					{
						$this->minTickPositions[$j++] = mktime( 0, 0, 0, 1, 1, $y );
					}
				}
				++$y;
			} while ( 1 );
		case DSUTILS_YEAR5 :
			$y = $this->startyear;
			while ( $y <= $this->endyear )
			{
				$this->tickPositions[$i++] = mktime( 0, 0, 0, 1, 1, $y );
				$k = 0;
				for ( ;	$k < 4;	++$k	)
				{
					++$y;
					if ( $aMinor )
					{
						$this->minTickPositions[$j++] = mktime( 0, 0, 0, 1, 1, $y );
					}
				}
				++$y;
			}
		}
	}

	public function doDaily( $aType, $aMinor = false )
	{
		$m = $this->startmonth;
		$y = $this->startyear;
		$d = $this->startday;
		$h = $this->starthour;
		$i = 0;
		$j = 0;
		if ( $h == 0 )
		{
			$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, $d, $y );
			$t = mktime( 0, 0, 0, $m, $d, $y );
		}
		else
		{
			$t = mktime( 0, 0, 0, $m, $d, $y );
		}
		switch ( $aType )
		{
		case DSUTILS_DAY1 :
			do
			{
				if ( !( $t <= $this->iMax ) )
				{
					break;
				}
				$t += 86400;
				$this->tickPositions[$i++] = $t;
			} while ( 1 );
		case DSUTILS_DAY2 :
			do
			{
				if ( !( $t <= $this->iMax ) )
				{
					break;
				}
				$t += 86400;
				if ( $aMinor )
				{
					$this->minTickPositions[$j++] = $t;
				}
				$t += 86400;
				$this->tickPositions[$i++] = $t;
			} while ( 1 );
		case DSUTILS_DAY4 :
			while ( $t <= $this->iMax )
			{
				$k = 0;
				for ( ;	$k < 3;	++$k	)
				{
					$t += 86400;
					if ( $aMinor )
					{
						$this->minTickPositions[$j++] = $t;
					}
				}
				$t += 86400;
				$this->tickPositions[$i++] = $t;
			}
		}
	}

	public function doWeekly( $aType, $aMinor = false )
	{
		$hpd = 86400;
		$hpw = 604800;
		$thursday = $this->iMin + $hpd * ( 3 - ( date( "w", $this->iMin ) + 6 ) % 7 );
		$week = 1 + ( date( "z", $thursday ) - ( 11 - date( "w", mktime( 0, 0, 0, 1, 1, date( "Y", $thursday ) ) ) ) % 7 ) / 7;
		$daynumber = date( "w", $this->iMin );
		if ( $daynumber == 0 )
		{
			$daynumber = 7;
		}
		$m = $this->startmonth;
		$y = $this->startyear;
		$d = $this->startday;
		$i = 0;
		$j = 0;
		if ( $daynumber == 1 )
		{
			$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, $d, $y );
			$t = mktime( 0, 0, 0, $m, $d, $y ) + $hpw;
		}
		else
		{
			$t = mktime( 0, 0, 0, $m, $d, $y ) + $hpd * ( 8 - $daynumber );
		}
		switch ( $aType )
		{
		case DSUTILS_WEEK1 :
			$cnt = 0;
			break;
		case DSUTILS_WEEK2 :
			$cnt = 1;
			break;
		case DSUTILS_WEEK4 :
			$cnt = 3;
		}
		while ( $t <= $this->iMax )
		{
			$this->tickPositions[$i++] = $t;
			$k = 0;
			for ( ;	$k < $cnt;	++$k	)
			{
				$t += $hpw;
				if ( $aMinor )
				{
					$this->minTickPositions[$j++] = $t;
				}
			}
			$t += $hpw;
		}
	}

	public function doMonthly( $aType, $aMinor = false )
	{
		$monthcount = 0;
		$m = $this->startmonth;
		$y = $this->startyear;
		$i = 0;
		$j = 0;
		if ( $this->startday == 1 )
		{
			$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, 1, $y );
			$monthcount = 1;
		}
		if ( $aType == 1 && $this->startday < 15 )
		{
			$this->minTickPositions[$j++] = mktime( 0, 0, 0, $m, 15, $y );
		}
		++$m;
		$y = $this->startyear;
		for ( ;	$y <= $this->endyear;	++$y	)
		{
			$stopmonth = $y == $this->endyear ? $this->endmonth : 12;
			while ( $m <= $stopmonth )
			{
				switch ( $aType )
				{
				case DSUTILS_MONTH1 :
					if ( $aMinor && $m <= $stopmonth && ( !( $y == $this->endyear ) && !( $m == $stopmonth ) && !( $this->endday < 15 ) ) )
					{
						$this->minTickPositions[$j++] = mktime( 0, 0, 0, $m, 15, $y );
					}
					$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, 1, $y );
					break;
				case DSUTILS_MONTH2 :
					if ( $aMinor )
					{
						$this->minTickPositions[$j++] = mktime( 0, 0, 0, $m, 1, $y );
					}
					if ( !( $monthcount % 2 == 0 ) )
					{
						break;
					}
					$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, 1, $y );
					break;
				case DSUTILS_MONTH3 :
					if ( $aMinor )
					{
						$this->minTickPositions[$j++] = mktime( 0, 0, 0, $m, 1, $y );
					}
					if ( !( $monthcount % 3 == 0 ) )
					{
						break;
					}
					$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, 1, $y );
					break;
				case DSUTILS_MONTH6 :
					if ( $aMinor )
					{
						$this->minTickPositions[$j++] = mktime( 0, 0, 0, $m, 1, $y );
					}
					if ( !( $monthcount % 6 == 0 ) )
					{
						break;
					}
					$this->tickPositions[$i++] = mktime( 0, 0, 0, $m, 1, $y );
				}
				++$m;
				++$monthcount;
			}
			$m = 1;
		}
		if ( $this->startmonth == $this->endmonth && $this->startyear == $this->endyear && $aType == 1 )
		{
			$this->tickPositions[$i++] = mktime( 0, 0, 0, $this->startmonth + 1, 1, $this->startyear );
		}
		return array(
			$this->tickPositions,
			$this->minTickPositions
		);
	}

	public function GetTicks( $aData, $aType = 1, $aMinor = false, $aEndPoints = false )
	{
		$n = count( $aData );
		return $this->GetTicksFromMinMax( $aData[0], $aData[$n - 1], $aType, $aMinor, $aEndPoints );
	}

	public function GetAutoTicks( $aMin, $aMax, $aMaxTicks = 10, $aMinor = false )
	{
		$diff = $aMax - $aMin;
		$spd = 86400;
		$spw = $spd * 7;
		$spm = $spd * 30;
		$spy = $spd * 352;
		if ( $this->iUseWeeks )
		{
			$w = "W";
		}
		else
		{
			$w = "d M";
		}
		$tt = array(
			array(
				$spw,
				array(
					1,
					DSUTILS_DAY1,
					"d M",
					2,
					DSUTILS_DAY2,
					"d M",
					-1,
					DSUTILS_DAY4,
					"d M"
				)
			),
			array(
				$spm,
				array(
					1,
					DSUTILS_DAY1,
					"d M",
					2,
					DSUTILS_DAY2,
					"d M",
					4,
					DSUTILS_DAY4,
					"d M",
					7,
					DSUTILS_WEEK1,
					$w,
					-1,
					DSUTILS_WEEK2,
					$w
				)
			),
			array(
				$spy,
				array(
					1,
					DSUTILS_DAY1,
					"d M",
					2,
					DSUTILS_DAY2,
					"d M",
					4,
					DSUTILS_DAY4,
					"d M",
					7,
					DSUTILS_WEEK1,
					$w,
					14,
					DSUTILS_WEEK2,
					$w,
					30,
					DSUTILS_MONTH1,
					"M",
					60,
					DSUTILS_MONTH2,
					"M",
					-1,
					DSUTILS_MONTH3,
					"M"
				)
			),
			array(
				-1,
				array(
					30,
					DSUTILS_MONTH1,
					"M-Y",
					60,
					DSUTILS_MONTH2,
					"M-Y",
					90,
					DSUTILS_MONTH3,
					"M-Y",
					180,
					DSUTILS_MONTH6,
					"M-Y",
					352,
					DSUTILS_YEAR1,
					"Y",
					704,
					DSUTILS_YEAR2,
					"Y",
					-1,
					DSUTILS_YEAR5,
					"Y"
				)
			)
		);
		$ntt = count( $tt );
		$nd = floor( $diff / $spd );
		$i = 0;
		for ( ;	$i < $ntt;	++$i	)
		{
			if ( !( $diff <= $tt[$i][0] ) || !( $i == $ntt - 1 ) )
			{
				continue;
			}
			$t = $tt[$i][1];
			$n = count( $t ) / 3;
			$j = 0;
			for ( ;	$j < $n;	++$j	)
			{
				if ( !( $nd / $t[3 * $j] <= $aMaxTicks ) || !( $j == $n - 1 ) )
				{
					continue;
				}
				$type = $t[3 * $j + 1];
				$fs = $t[3 * $j + 2];
				list( $tickPositions, $minTickPositions ) = $this->GetTicksFromMinMax( $aMin, $aMax, $type, $aMinor );
				return array(
					$fs,
					$tickPositions,
					$minTickPositions,
					$type
				);
			}
		}
	}

	public function GetTicksFromMinMax( $aMin, $aMax, $aType, $aMinor = false, $aEndPoints = false )
	{
		$this->starthour = date( "G", $aMin );
		$this->startmonth = date( "n", $aMin );
		$this->startday = date( "j", $aMin );
		$this->startyear = date( "Y", $aMin );
		$this->endmonth = date( "n", $aMax );
		$this->endyear = date( "Y", $aMax );
		$this->endday = date( "j", $aMax );
		$this->iMin = $aMin;
		$this->iMax = $aMax;
		if ( $aType <= DSUTILS_MONTH6 )
		{
			$this->doMonthly( $aType, $aMinor );
		}
		else if ( $aType <= DSUTILS_WEEK4 )
		{
			$this->doWeekly( $aType, $aMinor );
		}
		else if ( $aType <= DSUTILS_DAY4 )
		{
			$this->doDaily( $aType, $aMinor );
		}
		else if ( $aType <= DSUTILS_YEAR5 )
		{
			$this->doYearly( $aType, $aMinor );
		}
		else
		{
			JpGraphError::raisel( 24003 );
		}
		if ( $aEndPoints )
		{
			$tickPositions[$i++] = $aData[0];
			if ( $aEndPoints )
			{
				$tickPositions[$i] = $aData[$n - 1];
			}
		}
		return array(
			$this->tickPositions,
			$this->minTickPositions
		);
	}

}

class ReadFileData
{

	public static function FromCSV( $aFile, &$aData, $aSepChar = ",", $aMaxLineLength = 1024 )
	{
		$rh = fopen( $aFile, "r" );
		if ( $rh === false )
		{
			return false;
		}
		$tmp = array( );
		$lineofdata = fgetcsv( $rh, 1000, "," );
		while ( $lineofdata !== FALSE )
		{
			$tmp = array_merge( $tmp, $lineofdata );
			$lineofdata = fgetcsv( $rh, $aMaxLineLength, $aSepChar );
		}
		fclose( $rh );
		$n = count( $tmp );
		$aData = array( );
		$cnt = 0;
		$i = 0;
		for ( ;	$i < $n;	++$i	)
		{
			if ( $tmp[$i] !== "" )
			{
				$aData[$cnt++] = floatval( $tmp[$i] );
			}
		}
		return $cnt;
	}

}

define( "DSUTILS_MONTH", 1 );
define( "DSUTILS_MONTH1", 1 );
define( "DSUTILS_MONTH2", 2 );
define( "DSUTILS_MONTH3", 3 );
define( "DSUTILS_MONTH6", 4 );
define( "DSUTILS_WEEK1", 5 );
define( "DSUTILS_WEEK2", 6 );
define( "DSUTILS_WEEK4", 7 );
define( "DSUTILS_DAY1", 8 );
define( "DSUTILS_DAY2", 9 );
define( "DSUTILS_DAY4", 10 );
define( "DSUTILS_YEAR1", 11 );
define( "DSUTILS_YEAR2", 12 );
define( "DSUTILS_YEAR5", 13 );
?>

⌨️ 快捷键说明

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