📄 jpgraph_radar.php
字号:
}
$i = 1;
for ( ; $i <= $nbrmin; ++$i )
{
if ( !( $i % $skip == 0 ) )
{
$xt = round( $i * $min_step_abs * cos( $aAxisAngle ) ) + $aScale->scale_abs[0];
$yt = $aPos - round( $i * $min_step_abs * sin( $aAxisAngle ) );
$aImg->Line( $xt + $dx, $yt + $dy, $xt - $dx, $yt - $dy );
}
}
if ( $this->mincolor != "" )
{
$aImg->PopColor( );
}
}
}
}
class RadarAxis extends AxisPrototype
{
private $title_color = "navy";
public $title = null;
public function RadarAxis( $img, $aScale, $color = array
(
0 => 0,
1 => 0,
2 => 0
) )
{
parent::axis( $img, $aScale, $color );
$this->len = $img->plotheight;
$this->title = new Text( );
$this->title->SetFont( FF_FONT1, FS_BOLD );
$this->color = array( 0, 0, 0 );
}
public function SetTickLabels( $aLabelArray, $aLabelColorArray = null )
{
$this->ticks_label = $aLabelArray;
$this->ticks_label_colors = $aLabelColorArray;
}
public function Stroke( $pos, $aAxisAngle, &$grid, $title, $lf )
{
$this->img->SetColor( $this->color );
$x = round( $this->scale->world_abs_size * cos( $aAxisAngle ) + $this->scale->scale_abs[0] );
$y = round( $pos - $this->scale->world_abs_size * sin( $aAxisAngle ) );
$this->img->SetColor( $this->color );
$this->img->SetLineWeight( $this->weight );
if ( !$this->hide )
{
$this->img->Line( $this->scale->scale_abs[0], $pos, $x, $y );
}
$this->scale->ticks->Stroke( $this->img, $grid, $pos, $aAxisAngle, $this->scale, $majpos, $majlabel );
$ncolor = 0;
if ( isset( $this->ticks_label_colors ) )
{
$ncolor = count( $this->ticks_label_colors );
}
if ( $lf && !$this->hide )
{
$this->img->SetFont( $this->font_family, $this->font_style, $this->font_size );
$this->img->SetTextAlign( "left", "top" );
$this->img->SetColor( $this->label_color );
if ( !$this->hide_labels )
{
$n = floor( count( $majpos ) / 2 );
$i = 0;
for ( ; $i < $n; ++$i )
{
if ( 0 < $ncolor )
{
$this->img->SetColor( $this->ticks_label_colors[$i % $ncolor] );
}
if ( $this->ticks_label != null && isset( $this->ticks_label[$i] ) )
{
$this->img->StrokeText( $majpos[$i * 2], $majpos[$i * 2 + 1], $this->ticks_label[$i] );
}
else
{
$this->img->StrokeText( $majpos[$i * 2], $majpos[$i * 2 + 1], $majlabel[$i] );
}
}
}
}
$this->_StrokeAxisTitle( $pos, $aAxisAngle, $title );
}
public function _StrokeAxisTitle( $pos, $aAxisAngle, $title )
{
$this->title->Set( $title );
$marg = 6 + $this->title->margin;
$xt = round( ( $this->scale->world_abs_size + $marg ) * cos( $aAxisAngle ) + $this->scale->scale_abs[0] );
$yt = round( $pos - ( $this->scale->world_abs_size + $marg ) * sin( $aAxisAngle ) );
if ( 0 < $this->title->iWordwrap )
{
$title = wordwrap( $title, $this->title->iWordwrap, "\n" );
}
$h = $this->img->GetTextHeight( $title ) * 1.2;
$w = $this->img->GetTextWidth( $title ) * 1.2;
while ( 2 * M_PI < $aAxisAngle )
{
$aAxisAngle -= 2 * M_PI;
}
if ( 7 * M_PI / 4 <= $aAxisAngle || $aAxisAngle <= M_PI / 4 )
{
$dx = 0;
}
if ( M_PI / 4 <= $aAxisAngle && $aAxisAngle <= 3 * M_PI / 4 )
{
$dx = ( $aAxisAngle - M_PI / 4 ) * 2 / M_PI;
}
if ( 3 * M_PI / 4 <= $aAxisAngle && $aAxisAngle <= 5 * M_PI / 4 )
{
$dx = 1;
}
if ( 5 * M_PI / 4 <= $aAxisAngle && $aAxisAngle <= 7 * M_PI / 4 )
{
$dx = 1 - ( $aAxisAngle - M_PI * 5 / 4 ) * 2 / M_PI;
}
if ( 7 * M_PI / 4 <= $aAxisAngle )
{
$dy = ( $aAxisAngle - M_PI - 3 * M_PI / 4 ) * 2 / M_PI;
}
if ( $aAxisAngle <= M_PI / 4 )
{
$dy = 1 - $aAxisAngle * 2 / M_PI;
}
if ( M_PI / 4 <= $aAxisAngle && $aAxisAngle <= 3 * M_PI / 4 )
{
$dy = 1;
}
if ( 3 * M_PI / 4 <= $aAxisAngle && $aAxisAngle <= 5 * M_PI / 4 )
{
$dy = 1 - ( $aAxisAngle - 3 * M_PI / 4 ) * 2 / M_PI;
}
if ( 5 * M_PI / 4 <= $aAxisAngle && $aAxisAngle <= 7 * M_PI / 4 )
{
$dy = 0;
}
if ( !$this->hide )
{
$this->title->Stroke( $this->img, $xt - $dx * $w, $yt - $dy * $h, $title );
}
}
}
class RadarGraph extends Graph
{
public $grid = NULL;
public $axis = null;
private $posx = NULL;
private $posy = NULL;
private $len = NULL;
private $axis_title = null;
public function RadarGraph( $width = 300, $height = 200, $cachedName = "", $timeout = 0, $inline = 1 )
{
$this->Graph( $width, $height, $cachedName, $timeout, $inline );
$this->posx = $width / 2;
$this->posy = $height / 2;
$this->len = min( $width, $height ) * 0.35;
$this->SetColor( array( 255, 255, 255 ) );
$this->SetTickDensity( TICKD_NORMAL );
$this->SetScale( "lin" );
$this->SetGridDepth( DEPTH_FRONT );
}
public function SupressTickMarks( $f = true )
{
if ( ERR_DEPRECATED )
{
JpGraphError::raisel( 18002 );
}
$this->axis->scale->ticks->SupressTickMarks( $f );
}
public function HideTickMarks( $aFlag = true )
{
$this->axis->scale->ticks->SupressTickMarks( $aFlag );
}
public function ShowMinorTickmarks( $aFlag = true )
{
$this->yscale->ticks->SupressMinorTickMarks( !$aFlag );
}
public function SetScale( $axtype, $ymin = 1, $ymax = 1, $dummy1 = null, $dumy2 = null )
{
if ( $axtype != "lin" && $axtype != "log" )
{
JpGraphError::raisel( 18003, $axtype );
}
if ( $axtype == "lin" )
{
$this->yscale = new LinearScale( $ymin, $ymax );
$this->yscale->ticks = new RadarLinearTicks( );
$this->yscale->ticks->SupressMinorTickMarks( );
}
else if ( $axtype == "log" )
{
$this->yscale = new LogScale( $ymin, $ymax );
$this->yscale->ticks = new RadarLogTicks( );
}
$this->axis = new RadarAxis( $this->img, $this->yscale );
$this->grid = new RadarGrid( );
}
public function SetSize( $aSize )
{
if ( $aSize < 0.1 || 1 < $aSize )
{
JpGraphError::raisel( 18004, $aSize );
}
$this->len = min( $this->img->width, $this->img->height ) * $aSize / 2;
}
public function SetPlotSize( $aSize )
{
$this->SetSize( $aSize );
}
public function SetTickDensity( $densy = TICKD_NORMAL, $dummy1 = null )
{
$this->ytick_factor = 25;
switch ( $densy )
{
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 = 70;
break;
default :
do
{
JpGraphError::raisel( 18005, $densy );
}
}
public function SetPos( $px, $py = 0.5 )
{
$this->SetCenter( $px, $py );
}
public function SetCenter( $px, $py = 0.5 )
{
assert( 0 < $py );
$this->posx = $this->img->width * $px;
$this->posy = $this->img->height * $py;
}
public function SetColor( $c )
{
$this->SetMarginColor( $c );
}
public function SetTitles( $title )
{
$this->axis_title = $title;
}
public function Add( $splot )
{
$this->plots[] = $splot;
}
public function GetPlotsYMinMax( $aPlots )
{
$min = $aPlots[0]->Min( );
$max = $aPlots[0]->Max( );
foreach ( $this->plots as $p )
{
$max = max( $max, $p->Max( ) );
$min = min( $min, $p->Min( ) );
}
if ( $min < 0 )
{
JpGraphError::raisel( 18006, $min );
}
return array(
$min,
$max
);
}
public function Stroke( $aStrokeFileName = "" )
{
$n = count( $this->plots );
if ( !$this->yscale->IsSpecified( ) || 0 < count( $this->plots ) )
{
list( $min, $max ) = $this->GetPlotsYMinMax( $this->plots );
$this->yscale->AutoScale( $this->img, 0, $max, $this->len / $this->ytick_factor );
}
else if ( $this->yscale->IsSpecified( ) && ( $this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified( ) ) )
{
$min = $this->yscale->scale[0];
$max = $this->yscale->scale[1];
$this->yscale->AutoScale( $this->img, $min, $max, $this->len / $this->ytick_factor, $this->yscale->auto_ticks );
}
$this->yscale->SetConstants( $this->posx, $this->len );
$nbrpnts = $this->plots[0]->GetCount( );
if ( $this->axis_title == null )
{
$i = 0;
for ( ; do
{
$i < $nbrpnts; ++$i, )
{
$this->axis_title[$i] = $i + 1;
break;
}
} while ( 1 );
}
else if ( count( $this->axis_title ) < $nbrpnts )
{
JpGraphError::raisel( 18007 );
}
$i = 0;
for ( ; $i < $n; ++$i )
{
if ( $nbrpnts != $this->plots[$i]->GetCount( ) )
{
JpGraphError::raisel( 18008 );
}
}
if ( $this->background_image != "" )
{
$this->StrokeFrameBackground( );
}
else
{
$this->StrokeFrame( );
}
$astep = 2 * M_PI / $nbrpnts;
$i = 0;
for ( ; $i < $n; ++$i )
{
$this->plots[$i]->Legend( $this );
}
$this->legend->Stroke( $this->img );
$this->footer->Stroke( $this->img );
if ( $this->grid_depth == DEPTH_BACK )
{
$i = 0;
$a = M_PI / 2;
for ( ; $i < $nbrpnts; ++$i, $a += $astep )
{
$this->axis->Stroke( $this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0 );
}
}
$a = M_PI / 2;
$i = 0;
for ( ; $i < $n; ++$i )
{
$this->plots[$i]->Stroke( $this->img, $this->posy, $this->yscale, $a );
}
if ( $this->grid_depth != DEPTH_BACK )
{
$i = 0;
$a = M_PI / 2;
for ( ; $i < $nbrpnts; ++$i, $a += $astep )
{
$this->axis->Stroke( $this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0 );
}
}
$this->grid->Stroke( $this->img, $grid );
$this->StrokeTitles( );
if ( $this->texts != null )
{
foreach ( $this->texts as $t )
{
$t->Stroke( $this->img );
}
}
if ( $this->iImgTrans )
{
if ( !class_exists( "ImgTrans", false ) )
{
require_once( "jpgraph_imgtrans.php" );
}
$tform = new ImgTrans( $this->img->img );
$this->img->img = $tform->Skew3D( $this->iImgTransHorizon, $this->iImgTransSkewDist, $this->iImgTransDirection, $this->iImgTransHighQ, $this->iImgTransMinSize, $this->iImgTransFillColor, $this->iImgTransBorder );
}
if ( $aStrokeFileName == _IMG_HANDLER )
{
return $this->img->img;
}
$this->cache->PutAndStream( $this->img, $this->cache_name, $this->inline, $aStrokeFileName );
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -