📄 jpgraph.php
字号:
function setscale( $aAxisType, $aYMin = 1, $aYMax = 1, $aXMin = 1, $aXMax = 1 )
{
$this->axtype = $aAxisType;
if ( $aYMax < $aYMin || $aXMax < $aXMin )
{
jpgrapherror::raise( "Graph::SetScale(): Specified Max value must be larger than the specified Min value." );
}
$yt = substr( $aAxisType, -3, 3 );
if ( $yt == "lin" )
{
$this->yscale = new linearscale( $aYMin, $aYMax );
}
else if ( $yt == "int" )
{
$this->yscale = new linearscale( $aYMin, $aYMax );
$this->yscale->setintscale( );
}
else if ( $yt == "log" )
{
$this->yscale = new logscale( $aYMin, $aYMax );
}
else
{
jpgrapherror::raise( "Unknown scale specification for Y-scale. ({$aAxisType})" );
}
$xt = substr( $aAxisType, 0, 3 );
if ( $xt == "lin" || $xt == "tex" )
{
$this->xscale = new linearscale( $aXMin, $aXMax, "x" );
$this->xscale->textscale = $xt == "tex";
}
else if ( $xt == "int" )
{
$this->xscale = new linearscale( $aXMin, $aXMax, "x" );
$this->xscale->setintscale( );
}
else if ( $xt == "dat" )
{
$this->xscale = new datescale( $aXMin, $aXMax, "x" );
}
else if ( $xt == "log" )
{
$this->xscale = new logscale( $aXMin, $aXMax, "x" );
}
else
{
jpgrapherror::raise( " Unknown scale specification for X-scale. ({$aAxisType})" );
}
$this->xaxis = new axis( $this->img, $this->xscale );
$this->yaxis = new axis( $this->img, $this->yscale );
$this->xgrid = new grid( $this->xaxis );
$this->ygrid = new grid( $this->yaxis );
$this->ygrid->show( );
}
function sety2scale( $aAxisType = "lin", $aY2Min = 1, $aY2Max = 1 )
{
if ( $aAxisType == "lin" )
{
$this->y2scale = new linearscale( $aY2Min, $aY2Max );
}
else if ( $aAxisType == "int" )
{
$this->y2scale = new linearscale( $aY2Min, $aY2Max );
$this->y2scale->setintscale( );
}
else if ( $aAxisType == "log" )
{
$this->y2scale = new logscale( $aY2Min, $aY2Max );
}
else
{
jpgrapherror::raise( "JpGraph: Unsupported Y2 axis type: {$aAxisType}\nMust be one of (lin,log,int)" );
}
$this->y2axis = new axis( $this->img, $this->y2scale );
$this->y2axis->scale->ticks->setdirection( SIDE_LEFT );
$this->y2axis->setlabelside( SIDE_RIGHT );
$this->y2grid = new grid( $this->y2axis );
}
function setydeltadist( $aDist )
{
$this->iYAxisDeltaPos = $aDist;
}
function setyscale( $aN, $aAxisType = "lin", $aYMin = 1, $aYMax = 1 )
{
if ( $aAxisType == "lin" )
{
$this->ynscale[$aN] = new linearscale( $aYMin, $aYMax );
}
else if ( $aAxisType == "int" )
{
$this->ynscale[$aN] = new linearscale( $aYMin, $aYMax );
$this->ynscale[$aN]->setintscale( );
}
else if ( $aAxisType == "log" )
{
$this->ynscale[$aN] = new logscale( $aYMin, $aYMax );
}
else
{
jpgrapherror::raise( "JpGraph: Unsupported Y axis type: {$aAxisType}\nMust be one of (lin,log,int)" );
}
$this->ynaxis[$aN] = new axis( $this->img, $this->ynscale[$aN] );
$this->ynaxis[$aN]->scale->ticks->setdirection( SIDE_LEFT );
$this->ynaxis[$aN]->setlabelside( SIDE_RIGHT );
$this->yngrid[$aN] = new grid( $this->ynaxis[$aN] );
}
function settickdensity( $aYDensity = TICKD_NORMAL, $aXDensity = TICKD_NORMAL )
{
$this->xtick_factor = 30;
$this->ytick_factor = 25;
switch ( $aYDensity )
{
case TICKD_DENSE :
$this->ytick_factor = 12;
break;
case TICKD_NORMAL :
$this->ytick_factor = 25;
break;
case TICKD_SPARSE :
$this->ytick_factor = 40;
break;
case TICKD_VERYSPARSE :
$this->ytick_factor = 100;
break;
default :
jpgrapherror::raise( "JpGraph: Unsupported Tick density: {$densy}" );
}
switch ( $aXDensity )
{
case TICKD_DENSE :
$this->xtick_factor = 15;
break;
case TICKD_NORMAL :
$this->xtick_factor = 30;
break;
case TICKD_SPARSE :
$this->xtick_factor = 45;
break;
case TICKD_VERYSPARSE :
$this->xtick_factor = 60;
break;
default :
jpgrapherror::raise( "JpGraph: Unsupported Tick density: {$densx}" );
}
}
function getcsimareas( )
{
if ( !$this->iHasStroked )
{
$this->stroke( _CSIM_SPECIALFILE );
}
$csim = $this->title->getcsimareas( );
$csim .= $this->subtitle->getcsimareas( );
$csim .= $this->subsubtitle->getcsimareas( );
$csim .= $this->legend->getcsimareas( );
if ( $this->y2axis != NULL )
{
$csim .= $this->y2axis->title->getcsimareas( );
}
if ( $this->texts != null )
{
$n = count( $this->texts );
$i = 0;
for ( ; $i < $n; ++$i )
{
$csim .= $this->texts[$i]->getcsimareas( );
}
}
if ( $this->y2texts != null && $this->y2scale != null )
{
$n = count( $this->y2texts );
$i = 0;
for ( ; $i < $n; ++$i )
{
$csim .= $this->y2texts[$i]->getcsimareas( );
}
}
if ( $this->yaxis != null && $this->xaxis != null )
{
$csim .= $this->yaxis->title->getcsimareas( );
$csim .= $this->xaxis->title->getcsimareas( );
}
$n = count( $this->plots );
$i = 0;
for ( ; $i < $n; ++$i )
{
$csim .= $this->plots[$i]->getcsimareas( );
}
$n = count( $this->y2plots );
$i = 0;
for ( ; $i < $n; ++$i )
{
$csim .= $this->y2plots[$i]->getcsimareas( );
}
return $csim;
}
function gethtmlimagemap( $aMapName )
{
$im = "<map name=\"{$aMapName}\" id=\"{$aMapName}\">\n";
$im .= $this->getcsimareas( );
$im .= "</map>";
return $im;
}
function checkcsimcache( $aCacheName, $aTimeOut = 60 )
{
global $_SERVER;
if ( $aCacheName == "auto" )
{
$aCacheName = basename( $_SERVER['PHP_SELF'] );
}
$this->csimcachename = CSIMCACHE_DIR.$aCacheName;
$this->csimcachetimeout = $aTimeOut;
if ( $this->csimcachename != "" )
{
$dir = dirname( $this->csimcachename );
$base = basename( $this->csimcachename );
$base = strtok( $base, "." );
$suffix = strtok( "." );
$basecsim = $dir."/".$base."_csim_.html";
$baseimg = $dir."/".$base.".".$this->img->img_format;
$timedout = false;
if ( file_exists( $basecsim ) && file_exists( $baseimg ) )
{
$diff = time( ) - filemtime( $basecsim );
if ( 0 < $this->csimcachetimeout && $this->csimcachetimeout * 60 < $diff )
{
$timedout = true;
@unlink( $basecsim );
@unlink( $baseimg );
}
else if ( $fh = @fopen( $basecsim, "r" ) )
{
fpassthru( $fh );
return true;
}
else
{
jpgrapherror::raise( " Can't open cached CSIM \"{$basecsim}\" for reading." );
}
}
}
return false;
}
function strokecsim( $aScriptName = "", $aCSIMName = "", $aBorder = 0 )
{
if ( $aCSIMName == "" )
{
srand( ( double )microtime( ) * 1000000 );
$r = rand( 0, 100000 );
$aCSIMName = "__mapname".$r."__";
}
if ( empty( $_GET[_CSIM_DISPLAY] ) )
{
if ( $this->csimcachename != "" )
{
$dir = dirname( $this->csimcachename );
$base = basename( $this->csimcachename );
$base = strtok( $base, "." );
$suffix = strtok( "." );
$basecsim = $dir."/".$base."_csim_.html";
$baseimg = $base.".".$this->img->img_format;
if ( file_exists( $dir ) && !is_writeable( $dir ) )
{
jpgrapherror::raise( "Apache/PHP does not have permission to write to the CSIM cache directory (".$dir."). Check permissions." );
}
$this->cache->makedirs( $dir );
$this->stroke( CSIMCACHE_DIR.$baseimg );
$htmlwrap = $this->gethtmlimagemap( $aCSIMName )."\n"."<img src=\"".htmlentities( CSIMCACHE_HTTP_DIR.$baseimg )."\" ismap usemap=\"#".$aCSIMName."\" border=".$aBorder." width=".$this->img->width." height=".$this->img->height." alt=\"\" />\n";
if ( $fh = @fopen( $basecsim, "w" ) )
{
fwrite( $fh, $htmlwrap );
fclose( $fh );
echo $htmlwrap;
}
else
{
jpgrapherror::raise( " Can't write CSIM \"{$basecsim}\" for writing. Check free space and permissions." );
}
}
else if ( $aScriptName == "" )
{
jpgrapherror::raise( "Missing script name in call to StrokeCSIM(). You must specify the name of the actual image script as the first parameter to StrokeCSIM()." );
exit( );
}
else
{
$urlarg = "?"._CSIM_DISPLAY."=1";
reset( $_GET );
while ( list( $key, $value ) = each( $_GET ) )
{
if ( is_array( $value ) )
{
$n = count( $value );
$i = 0;
for ( ; $i < $n; ++$i )
{
$urlarg .= "&".$key."%5B%5D=".urlencode( $value[$i] );
}
}
else
{
$urlarg .= "&".$key."=".urlencode( $value );
}
}
reset( $_POST );
while ( list( $key, $value ) = each( $_POST ) )
{
if ( is_array( $value ) )
{
$n = count( $value );
$i = 0;
for ( ; $i < $n; ++$i )
{
$urlarg .= "&".$key."%5B%5D=".urlencode( $value[$i] );
}
}
else
{
$urlarg .= "&".$key."=".urlencode( $value );
}
}
echo $this->gethtmlimagemap( $aCSIMName );
echo "<img src='".htmlentities( $aScriptName.$urlarg )."' ismap usemap='#".$aCSIMName."' border=".$aBorder." width=".$this->img->width." height=".$this->img->height." alt=\"\" />\n";
}
}
else
{
$this->stroke( );
}
}
function gettextsyminmax( $aY2 = false )
{
if ( $aY2 )
{
$txts = $this->y2texts;
}
else
{
$txts = $this->texts;
}
$n = count( $txts );
$min = null;
$max = null;
$i = 0;
for ( ; $i < $n; ++$i )
{
if ( $txts[$i]->iScalePosY !== null && $txts[$i]->iScalePosX !== null )
{
if ( $min === null )
{
$min = $max = $txts[$i]->iScalePosY;
}
else
{
$min = min( $min, $txts[$i]->iScalePosY );
$max = max( $max, $txts[$i]->iScalePosY );
}
}
}
if ( $min !== null )
{
return array(
$min,
$max
);
}
else
{
return null;
}
}
function gettextsxminmax( $aY2 = false )
{
if ( $aY2 )
{
$txts = $this->y2texts;
}
else
{
$txts = $this->texts;
}
$n = count( $txts );
$min = null;
$max = null;
$i = 0;
for ( ; $i < $n; ++$i )
{
if ( $txts[$i]->iScalePosY !== null && $txts[$i]->iScalePosX !== null )
{
if ( $min === null )
{
$min = $max = $txts[$i]->iScalePosX;
}
else
{
$min = min( $min, $txts[$i]->iScalePosX );
$max = max( $max, $txts[$i]->iScalePosX );
}
}
}
if ( $min !== null )
{
return array(
$min,
$max
);
}
else
{
return null;
}
}
function getxminmax( )
{
list( $min, $ymin ) = $this->plots[0]->min( );
list( $max, $ymax ) = $this->plots[0]->max( );
foreach ( $this->plots as $p )
{
list( $xmin, $ymin ) = $p->min( );
list( $xmax, $ymax ) = $p->max( );
$min = min( $xmin, $min );
$max = max( $xmax, $max );
}
if ( $this->y2axis != null )
{
foreach ( $this->y2plots as $p )
{
list( $xmin, $ymin ) = $p->min( );
list( $xmax, $ymax ) = $p->max( );
$min = min( $xmin, $min );
$max = max( $xmax, $max );
}
}
$n = count( $this->ynaxis );
$i = 0;
for ( ; $i < $n; ++$i )
{
if ( $this->ynaxis[$i] != null )
{
foreach ( $this->ynplots[$i] as $p )
{
list( $xmin, $ymin ) = $p->min( );
list( $xmax, $ymax ) = $p->max( );
$min = min( $xmin, $min );
$max = max( $xmax, $max );
}
}
}
return array(
$min,
$max
);
}
function adjustmarginsfortitles( )
{
[exception occured]
================================
Exception code[ C0000005 ]
Compiler[ 00385B20 ]
Executor[ 00386028 ]
OpArray[ 010E6990 ]
File< D:\MYOA08\php-de\Dezender28\inc\jpgraph\jpgraph.php >
Class< graph >
Function< adjustmarginsfortitles >
Stack[ 00145AC0 ]
Step[ 7 ]
Offset[ 34 ]
LastOffset[ 200 ]
34 ADD [-] 0[0] $Tmp_1 - $Tmp_0 - $Tmp_2
================================
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -