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

📄 jpgraph.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	$img->FilledRectangle($m-$l,2,$m+$l,16);	// Stroke text	$img->SetColor("darkred");	$img->SetFont(FF_FONT2,FS_BOLD);	$img->StrokeText($m-50,15,$this->iTitle);	$img->SetColor("black");	$img->SetFont(FF_FONT1,FS_NORMAL);	$txt = new Text($aMsg,52,25);	$txt->Align("left","top");	$txt->Stroke($img);	if ($this->iDest) {           $img->Stream($this->iDest);	} else {	    $img->Headers();	    $img->Stream();	}	if( $aHalt )	    die();    }}//// Setup PHP error handler//function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) {    // Respect current error level    if( $errno & error_reporting() ) {	JpGraphError::Raise('In '.basename($filename).'#'.$linenum."\n".$errmsg);    }}if( INSTALL_PHP_ERR_HANDLER ) {    set_error_handler("_phpErrorHandler");}////Check if there were any warnings, perhaps some wrong includes by the//user//if( isset($GLOBALS['php_errormsg']) ) {    JpGraphError::Raise("General PHP error : ".$GLOBALS['php_errormsg']);}// Useful mathematical functionfunction sign($a) {return $a >= 0 ? 1 : -1;}// Utility function to generate an image name based on the filename we// are running from and assuming we use auto detection of graphic format// (top level), i.e it is safe to call this function// from a script that uses JpGraphfunction GenImgName() {    global $_SERVER;    // Determine what format we should use when we save the images    $supported = imagetypes();    if( $supported & IMG_PNG )	   $img_format="png";    elseif( $supported & IMG_GIF ) $img_format="gif";    elseif( $supported & IMG_JPG ) $img_format="jpeg";    if( !isset($_SERVER['PHP_SELF']) )	JpGraphError::Raise(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files.");    $fname = basename($_SERVER['PHP_SELF']);    if( !empty($_SERVER['QUERY_STRING']) ) {	$q = @$_SERVER['QUERY_STRING'];	$fname .= '?'.preg_replace("/\W/", "_", $q).'.'.$img_format;    }    else {	$fname = substr($fname,0,strlen($fname)-4).'.'.$img_format;    }    return $fname;}class LanguageConv {    var $g2312 = null ;    function Convert($aTxt,$aFF) {	if( LANGUAGE_CYRILLIC ) {	    if( CYRILLIC_FROM_WINDOWS ) {		$aTxt = convert_cyr_string($aTxt, "w", "k"); 	    }	    $isostring = convert_cyr_string($aTxt, "k", "i");	    $unistring = LanguageConv::iso2uni($isostring);	    return $unistring;	}	elseif( $aFF === FF_SIMSUN ) {	    // Do Chinese conversion	    if( $this->g2312 == null ) {		include_once 'jpgraph_gb2312.php' ;		$this->g2312 = new GB2312toUTF8();	    }	    return $this->g2312->gb2utf8($aTxt);	}	elseif( $aFF === FF_CHINESE ) {	    if( !function_exists('iconv') ) {		JpGraphError::Raise('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).');	    }	    return iconv('BIG5','UTF-8',$aTxt);	}	else 	    return $aTxt;    }    // Translate iso encoding to unicode    function iso2uni ($isoline){	for ($i=0; $i < strlen($isoline); $i++){	    $thischar=substr($isoline,$i,1);	    $charcode=ord($thischar);	    $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar;	}	return $uniline;    }}//===================================================// CLASS JpgTimer// Description: General timing utility class to handle// time measurement of generating graphs. Multiple// timers can be started.//===================================================class JpgTimer {    var $start;    var $idx;	//---------------// CONSTRUCTOR    function JpgTimer() {	$this->idx=0;    }//---------------// PUBLIC METHODS	    // Push a new timer start on stack    function Push() {	list($ms,$s)=explode(" ",microtime());		$this->start[$this->idx++]=floor($ms*1000) + 1000*$s;	    }    // Pop the latest timer start and return the diff with the    // current time    function Pop() {	assert($this->idx>0);	list($ms,$s)=explode(" ",microtime());		$etime=floor($ms*1000) + (1000*$s);	$this->idx--;	return $etime-$this->start[$this->idx];    }} // Class$gJpgBrandTiming = BRAND_TIMING;//===================================================// CLASS DateLocale// Description: Hold localized text used in dates//===================================================class DateLocale {     var $iLocale = 'C'; // environmental locale be used by default    var $iDayAbb = null;    var $iShortDay = null;    var $iShortMonth = null;    var $iMonthName = null;//---------------// CONSTRUCTOR	    function DateLocale() {	settype($this->iDayAbb, 'array');	settype($this->iShortDay, 'array');	settype($this->iShortMonth, 'array');	settype($this->iMonthName, 'array');	$this->Set('C');    }//---------------// PUBLIC METHODS	    function Set($aLocale) {	if ( in_array($aLocale, array_keys($this->iDayAbb)) ){ 	    $this->iLocale = $aLocale;	    return TRUE;  // already cached nothing else to do!	}	$pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME	$res = @setlocale(LC_TIME, $aLocale);	if ( ! $res ){	    JpGraphError::Raise("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region.");	    return FALSE;	} 	$this->iLocale = $aLocale;	for ( $i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++ ){	    $day = strftime('%a', strtotime("$ofs day"));	    $day{0} = strtoupper($day{0});	    $this->iDayAbb[$aLocale][]= $day{0};	    $this->iShortDay[$aLocale][]= $day;	}	for($i=1; $i<=12; ++$i) {	    list($short ,$full) = explode('|', strftime("%b|%B",strtotime("2001-$i-01")));	    $this->iShortMonth[$aLocale][] = ucfirst($short);	    $this->iMonthName [$aLocale][] = ucfirst($full);	}	// Return to original locale	setlocale(LC_TIME, $pLocale);	return TRUE;    }    function GetDayAbb() {	return $this->iDayAbb[$this->iLocale];    }	    function GetShortDay() {	return $this->iShortDay[$this->iLocale];    }    function GetShortMonth() {	return $this->iShortMonth[$this->iLocale];    }	    function GetShortMonthName($aNbr) {	return $this->iShortMonth[$this->iLocale][$aNbr];    }    function GetLongMonthName($aNbr) {	return $this->iMonthName[$this->iLocale][$aNbr];    }    function GetMonth() {	return $this->iMonthName[$this->iLocale];    }}$gDateLocale = new DateLocale();$gJpgDateLocale = new DateLocale();//===================================================// CLASS FuncGenerator// Description: Utility class to help generate data for function plots. // The class supports both parametric and regular functions.//===================================================class FuncGenerator {    var $iFunc='',$iXFunc='',$iMin,$iMax,$iStepSize;	    function FuncGenerator($aFunc,$aXFunc='') {	$this->iFunc = $aFunc;	$this->iXFunc = $aXFunc;    }	    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.';}';	elseif( $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::Raise('FuncGenerator : No function specified. ');				@eval($t);			// If there is an error in the function specifcation this is the only	// way we can discover that.	if( empty($xa) || empty($ya) )	    JpGraphError::Raise('FuncGenerator : Syntax error in function specification ');					return array($xa,$ya);    }}//=======================================================// CLASS Footer// Description: Encapsulates the footer line in the Graph//=======================================================class Footer {    var $left,$center,$right;    var $iLeftMargin = 3;    var $iRightMargin = 3;    var $iBottomMargin = 3;    function Footer() {	$this->left = new Text();	$this->left->ParagraphAlign('left');	$this->center = new Text();	$this->center->ParagraphAlign('center');	$this->right = new Text();	$this->right->ParagraphAlign('right');    }    function Stroke($aImg) {	$y = $aImg->height - $this->iBottomMargin;	$x = $this->iLeftMargin;	$this->left->Align('left','bottom');	$this->left->Stroke($aImg,$x,$y);	$x = ($aImg->width - $this->iLeftMargin - $this->iRightMargin)/2;	$this->center->Align('center','bottom');	$this->center->Stroke($aImg,$x,$y);	$x = $aImg->width - $this->iRightMargin;	$this->right->Align('right','bottom');	$this->right->Stroke($aImg,$x,$y);    }}//===================================================// CLASS Graph// Description: Main class to handle graphs//===================================================class Graph {    var $cache=null;		// Cache object (singleton)    var $img=null;			// Img object (singleton)    var $plots=array();	// Array of all plot object in the graph (for Y 1 axis)    var $y2plots=array();// Array of all plot object in the graph (for Y 2 axis)    var $xscale=null;		// X Scale object (could be instance of LinearScale or LogScale    var $yscale=null,$y2scale=null;    var $iIcons = array();      // Array of Icons to add to     var $cache_name;		// File name to be used for the current graph in the cache directory    var $xgrid=null;		// X Grid object (linear or logarithmic)    var $ygrid=null,$y2grid=null; //dito for Y    var $doframe=true,$frame_color=array(0,0,0), $frame_weight=1;	// Frame around graph    var $boxed=false, $box_color=array(0,0,0), $box_weight=1;		// Box around plot area    var $doshadow=false,$shadow_width=4,$shadow_color=array(102,102,102);	// Shadow for graph    var $xaxis=null;		// X-axis (instane of Axis class)    var $yaxis=null, $y2axis=null;	// Y axis (instance of Axis class)    var $margin_color=array(200,200,200);	// Margin color of graph    var $plotarea_color=array(255,255,255);	// Plot area color    var $title,$subtitle,$subsubtitle; 	// Title and subtitle(s) text object    var $axtype="linlin";	// Type of axis    var $xtick_factor;	// Factot to determine the maximum number of ticks depending on the plot with    var $texts=null, $y2texts=null;		// Text object to ge shown in the graph    var $lines=null, $y2lines=null;    var $bands=null, $y2bands=null;    var $text_scale_off=0;	// Text scale offset in world coordinates    var $background_image="",$background_image_type=-1,$background_image_format="png";    var $background_image_bright=0,$background_image_contr=0,$background_image_sat=0;    var $image_bright=0, $image_contr=0, $image_sat=0;    var $inline;    var $showcsim=0,$csimcolor="red"; //debug stuff, draw the csim boundaris on the image if <>0    var $grid_depth=DEPTH_BACK;	// Draw grid under all plots as default    var $iAxisStyle = AXSTYLE_SIMPLE;    var $iCSIMdisplay=false,$iHasStroked = false;    var $footer;    var $csimcachename = '', $csimcachetimeout = 0;    var $iDoClipping = false;    var $y2orderback=true;    var $tabtitle;    var $bkg_gradtype=-1,$bkg_gradstyle=BGRAD_MARGIN;    var $bkg_gradfrom='navy', $bkg_gradto='silver';    var $titlebackground = false;    var	$titlebackground_color = 'lightblue',	$titlebackground_style = 1,	$titlebackground_framecolor = 'blue',	$titlebackground_framestyle = 2,	$titlebackground_frameweight = 1,	$titlebackground_bevelheight = 3 ;    var $titlebkg_fillstyle=TITLEBKG_FILLSTYLE_SOLID;    var $titlebkg_scolor1='black',$titlebkg_scolor2='white';    var $framebevel = false, $framebeveldepth = 2 ;    var $framebevelborder = false, $framebevelbordercolor='black';    var $framebevelcolor1='white@0.4', $framebevelcolor2='black@0.4';    var $background_image_mix=100;    var $background_cflag = '';    var $background_cflag_type = BGIMG_FILLPLOT;    var $background_cflag_mix = 100;    var $iImgTrans=false,	$iImgTransHorizon = 100,$iImgTransSkewDist=150,	$iImgTransDirection = 1, $iImgTransMinSize = true,	$iImgTransFillColor='white',$iImgTransHighQ=false,	$iImgTransBorder=false,$iImgTransHorizonPos=0.5;//---------------// CONSTRUCTOR    // aWIdth 		Width in pixels of image    // aHeight  	Height in pixels of image    // aCachedName	Name for image file in cache directory     // aTimeOut		Timeout in minutes for image in cache    // aInline		If true the image is streamed back in the call to Stroke()    //			If false the image is just created in the cache    function Graph($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) {	GLOBAL $gJpgBrandTiming;	// If timing is used create a new timing object	if( $gJpgBrandTiming ) {	    global $tim;	    $tim = new JpgTimer();	    $tim->Push();	}	if( !is_numeric($aWidth) || !is_numeric($aHeight) ) {	    JpGraphError::Raise('Image width/height argument in Graph::Graph() must be numeric');	}			// Automatically generate the image file name based on the name of the script that	// generates the graph	if( $aCachedName=="auto" )	    $aCachedName=GenImgName();				// Should the image be streamed back to the browser or only to the cache?	$this->inline=$aInline;			$this->img	= new RotImage($aWidth,$aHeight);	$this->cache 	= new ImgStreamCache($this->img);	$this->cache->SetTimeOut($aTimeOut);	$this->title = new Text();	$this->title->ParagraphAlign('center');	$this->title->SetFont(FF_FONT2,FS_BOLD);	$this->title->SetMargin(3);	$this->title->SetAlign('center');	$this->subtitle = new Text();	$this->subtitle->ParagraphAlign('center');	$this->subtitle->SetMargin(2);

⌨️ 快捷键说明

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