jpgraph.php
来自「通达OA2007SE源代码 非常好的」· PHP 代码 · 共 2,039 行 · 第 1/5 页
PHP
2,039 行
class JpgTimer { private $start, $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 { public $iLocale = 'C'; // environmental locale be used by default private $iDayAbb = null, $iShortDay = null, $iShortMonth = null, $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::RaiseL(25007,$aLocale);//("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); } 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 Footer// Description: Encapsulates the footer line in the Graph//=======================================================class Footer { public $iLeftMargin = 3, $iRightMargin = 3, $iBottomMargin = 3 ; public $left,$center,$right; 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 SetMargin($aLeft=3,$aRight=3,$aBottom=3) { $this->iLeftMargin = $aLeft; $this->iRightMargin = $aRight; $this->iBottomMargin = $aBottom; } 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 { public $cache=null; // Cache object (singleton) public $img=null; // Img object (singleton) public $plots=array(); // Array of all plot object in the graph (for Y 1 axis) public $y2plots=array();// Array of all plot object in the graph (for Y 2 axis) public $ynplots=array(); public $xscale=null; // X Scale object (could be instance of LinearScale or LogScale public $yscale=null,$y2scale=null, $ynscale=array(); public $iIcons = array(); // Array of Icons to add to public $cache_name; // File name to be used for the current graph in the cache directory public $xgrid=null; // X Grid object (linear or logarithmic) public $ygrid=null,$y2grid=null; //dito for Y public $doframe=true,$frame_color=array(0,0,0), $frame_weight=1; // Frame around graph public $boxed=false, $box_color=array(0,0,0), $box_weight=1; // Box around plot area public $doshadow=false,$shadow_width=4,$shadow_color=array(102,102,102); // Shadow for graph public $xaxis=null; // X-axis (instane of Axis class) public $yaxis=null, $y2axis=null, $ynaxis=array(); // Y axis (instance of Axis class) public $margin_color=array(200,200,200); // Margin color of graph public $plotarea_color=array(255,255,255); // Plot area color public $title,$subtitle,$subsubtitle; // Title and subtitle(s) text object public $axtype="linlin"; // Type of axis public $xtick_factor; // Factot to determine the maximum number of ticks depending on the plot with public $texts=null, $y2texts=null; // Text object to ge shown in the graph public $lines=null, $y2lines=null; public $bands=null, $y2bands=null; public $text_scale_off=0, $text_scale_abscenteroff=-1; // Text scale in fractions and for centering bars public $background_image="",$background_image_type=-1,$background_image_format="png"; public $background_image_bright=0,$background_image_contr=0,$background_image_sat=0; public $image_bright=0, $image_contr=0, $image_sat=0; public $inline; public $showcsim=0,$csimcolor="red"; //debug stuff, draw the csim boundaris on the image if <>0 public $grid_depth=DEPTH_BACK; // Draw grid under all plots as default public $iAxisStyle = AXSTYLE_SIMPLE; public $iCSIMdisplay=false,$iHasStroked = false; public $footer; public $csimcachename = '', $csimcachetimeout = 0; public $iDoClipping = false; public $y2orderback=true; public $tabtitle; public $bkg_gradtype=-1,$bkg_gradstyle=BGRAD_MARGIN; public $bkg_gradfrom='navy', $bkg_gradto='silver'; public $titlebackground = false; public $titlebackground_color = 'lightblue', $titlebackground_style = 1, $titlebackground_framecolor = 'blue', $titlebackground_framestyle = 2, $titlebackground_frameweight = 1, $titlebackground_bevelheight = 3 ; public $titlebkg_fillstyle=TITLEBKG_FILLSTYLE_SOLID; public $titlebkg_scolor1='black',$titlebkg_scolor2='white'; public $framebevel = false, $framebeveldepth = 2 ; public $framebevelborder = false, $framebevelbordercolor='black'; public $framebevelcolor1='white@0.4', $framebevelcolor2='black@0.4'; public $background_image_mix=100; public $background_cflag = ''; public $background_cflag_type = BGIMG_FILLPLOT; public $background_cflag_mix = 100; public $iImgTrans=false, $iImgTransHorizon = 100,$iImgTransSkewDist=150, $iImgTransDirection = 1, $iImgTransMinSize = true, $iImgTransFillColor='white',$iImgTransHighQ=false, $iImgTransBorder=false,$iImgTransHorizonPos=0.5; protected $iYAxisDeltaPos=50; protected $iIconDepth=DEPTH_BACK; protected $iAxisLblBgType = 0, $iXAxisLblBgFillColor = 'lightgray', $iXAxisLblBgColor = 'black', $iYAxisLblBgFillColor = 'lightgray', $iYAxisLblBgColor = 'black'; protected $iTables=NULL;//---------------// 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::RaiseL(25008);//('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); $this->subtitle->SetAlign('center'); $this->subsubtitle = new Text(); $this->subsubtitle->ParagraphAlign('center'); $this->subsubtitle->SetMargin(2); $this->subsubtitle->SetAlign('center'); $this->legend = new Legend(); $this->footer = new Footer(); // Window doesn't like '?' in the file name so replace it with an '_' $aCachedName = str_replace("?","_",$aCachedName); // If the cached version exist just read it directly from the // cache, stream it back to browser and exit if( $aCachedName!="" && READ_CACHE && $aInline ) if( $this->cache->GetAndStream($aCachedName) ) { exit(); } $this->cache_name = $aCachedName; $this->SetTickDensity(); // Normal density $this->tabtitle = new GraphTabTitle(); }//---------------// PUBLIC METHODS // Enable final image perspective transformation function Set3DPerspective($aDir=1,$aHorizon=100,$aSkewDist=120,$aQuality=false,$aFillColor='#FFFFFF',$aBorder=false,$aMinSize=true,$aHorizonPos=0.5) { $this->iImgTrans = true; $this->iImgTransHorizon = $aHorizon; $this->iImgTransSkewDist= $aSkewDist; $this->iImgTransDirection = $aDir; $this->iImgTransMinSize = $aMinSize; $this->iImgTransFillColor=$aFillColor; $this->iImgTransHighQ=$aQuality; $this->iImgTransBorder=$aBorder; $this->iImgTransHorizonPos=$aHorizonPos; } // Set Image format and optional quality function SetImgFormat($aFormat,$aQuality=75) { $this->img->SetImgFormat($aFormat,$aQuality); } // Should the grid be in front or back of the plot? function SetGridDepth($aDepth) { $this->grid_depth=$aDepth; } function SetIconDepth($aDepth) { $this->iIconDepth=$aDepth; } // Specify graph angle 0-360 degrees. function SetAngle($aAngle) { $this->img->SetAngle($aAngle); } function SetAlphaBlending($aFlg=true) { $this->img->SetAlphaBlending($aFlg); } // Shortcut to image margin function SetMargin($lm,$rm,$tm,$bm) { $this->img->SetMargin($lm,$rm,$tm,$bm); } function SetY2OrderBack($aBack=true) { $this->y2orderback = $aBack; } // Rotate the graph 90 degrees and set the margin // when we have done a 90 degree rotation function Set90AndMargin($lm=0,$rm=0,$tm=0,$bm=0) { $lm = $lm ==0 ? floor(0.2 * $this->img->width) : $lm ; $rm = $rm ==0 ? floor(0.1 * $this->img->width) : $rm ; $tm = $tm ==0 ? floor(0.2 * $this->img->height) : $tm ; $bm = $bm ==0 ? floor(0.1 * $this->img->height) : $bm ; $adj = ($this->img->height - $this->img->width)/2; $this->img->SetMargin($tm-$adj,$bm-$adj,$rm+$adj,$lm+$adj); $this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2)); $this->SetAngle(90); if( empty($this->yaxis) || empty($this->xaxis) ) { JpgraphError::RaiseL(25009);//('You must specify what scale to use with a call to Graph::SetScale()'); } $this->xaxis->SetLabelAlign('right','center'); $this->yaxis->SetLabelAlign('center','bottom'); } function SetClipping($aFlg=true) { $this->iDoClipping = $aFlg ; } // Add a plot object to the graph function Add($aPlot) { if( $aPlot == null ) JpGraphError::RaiseL(25010);//("Graph::Add() You tried to add a null plot to the graph."); if( is_array($aPlot) && count($aPlot) > 0 ) $cl = $aPlot[0]; else $cl = $aPlot; if( $cl instanceof Text ) $this->AddText($aPlot); elseif( $cl instanceof PlotLine ) $this->AddLine($aPlot); elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) ) $this->AddBand($aPlot); elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) ) $this->AddIcon($aPlot); elseif( class_exists('GTextTable',false) && ($cl instanceof GTextTable) ) $this->AddTable($aPlot); else $this->plots[] = $aPlot; } function AddTable($aTable) { if( is_array($aTable) ) { for($i=0; $i < count($aTable); ++$i ) $this->iTables[]=$aTable[$i]; } else { $this->iTables[] = $aTable ; } } function AddIcon($aIcon) { if( is_array($aIcon) ) { for($i=0; $i < count($aIcon); ++$i ) $this->iIcons[]=$aIcon[$i]; } else { $this->iIcons[] = $aIcon ; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?