?? jpgraph_pie3d.php
字號:
<?php
class pieplot3d extends pieplot
{
var $labelhintcolor = "red";
var $showlabelhint = true;
var $angle = 50;
var $edgecolor = "";
var $edgeweight = 1;
var $iThickness = false;
function pieplot3d( &$data )
{
$this->radius = 0.5;
$this->data = $data;
$this->title = new text( "" );
$this->title->setfont( FF_FONT1, FS_BOLD );
$this->value = new displayvalue( );
$this->value->show( );
$this->value->setformat( "%.0f%%" );
}
function setlegends( $aLegend )
{
$this->legends = array_reverse( $aLegend );
}
function setslicecolors( $aColors )
{
$this->setslicecolors = $aColors;
}
function legend( &$aGraph )
{
pieplot::legend( $aGraph );
$aGraph->legend->txtcol = array_reverse( $aGraph->legend->txtcol );
}
function setcsimtargets( $targets, $alts = null )
{
$this->csimtargets = $targets;
$this->csimalts = $alts;
}
function setedge( $aColor, $aWeight = 1 )
{
$this->edgecolor = $aColor;
$this->edgeweight = $aWeight;
}
function setangle( $a )
{
if ( $a < 5 || 90 < $a )
{
jpgrapherror::raise( "PiePlot3D::SetAngle() 3D Pie projection angle must be between 5 and 85 degrees." );
}
else
{
$this->angle = $a;
}
}
function addslicetocsim( $i, $xc, $yc, $height, $width, $thick, $sa, $ea )
{
$sa *= M_PI / 180;
$ea *= M_PI / 180;
$coords = "{$xc}, {$yc}";
$xp = floor( $width * cos( $sa ) / 2 + $xc );
$yp = floor( $yc - $height * sin( $sa ) / 2 );
$coords .= ", {$xp}, {$yp}";
if ( M_PI <= $sa && $sa <= 2 * M_PI * 1.01 )
{
$yp = floor( $yp + $thick );
$coords .= ", {$xp}, {$yp}";
}
$a = $sa + 0.2;
while ( $a < $ea )
{
$xp = floor( $width * cos( $a ) / 2 + $xc );
if ( M_PI <= $a && $a <= 2 * M_PI * 1.01 )
{
$yp = floor( $yc - $height * sin( $a ) / 2 + $thick );
}
else
{
$yp = floor( $yc - $height * sin( $a ) / 2 );
}
$coords .= ", {$xp}, {$yp}";
$a += 0.2;
}
$xp = floor( $width * cos( $ea ) / 2 + $xc );
$yp = floor( $yc - $height * sin( $ea ) / 2 );
if ( M_PI <= $ea && $ea <= 2 * M_PI * 1.01 )
{
$coords .= ", {$xp}, ".floor( $yp + $thick );
}
$coords .= ", {$xp}, {$yp}";
$alt = "";
if ( !empty( $this->csimalts[$i] ) )
{
$tmp = sprintf( $this->csimalts[$i], $this->data[$i] );
$alt = "alt=\"{$tmp}\" title=\"{$tmp}\"";
}
if ( !empty( $this->csimtargets[$i] ) )
{
$this->csimareas .= "<area shape=\"poly\" coords=\"{$coords}\" href=\"".$this->csimtargets[$i]."\" {$alt} />\n";
}
}
function setlabels( $aLabels, $aLblPosAdj = "auto" )
{
$this->labels = $aLabels;
$this->ilabelposadj = $aLblPosAdj;
}
function setlabelmargin( $m )
{
$this->value->setmargin( $m );
}
function showlabelhint( $f = true )
{
$this->showlabelhint = $f;
}
function setlabelhintcolor( $c )
{
$this->labelhintcolor = $c;
}
function setheight( $aHeight )
{
$this->iThickness = $aHeight;
}
function normangle( $a )
{
if ( 0 < $a )
{
while ( 360 < $a )
{
$a -= 360;
}
}
else
{
while ( $a < 0 )
{
$a += 360;
}
}
if ( $a < 0 )
{
$a = 360 + $a;
}
if ( $a == 360 )
{
$a = 0;
}
return $a;
}
function pie3dslice( $img, $xc, $yc, $w, $h, $sa, $ea, $z, $fillcolor, $shadow = 0.65 )
{
if ( $sa < 90 && 90 < $ea || 90 < $sa && $sa < 270 && 270 < $ea )
{
jpgrapherror::raise( "Internal assertion failed. Pie3D::Pie3DSlice" );
exit( 1 );
}
$p[] = array( );
$rsa = $sa / 180 * M_PI;
$rea = $ea / 180 * M_PI;
$sinsa = sin( $rsa );
$cossa = cos( $rsa );
$sinea = sin( $rea );
$cosea = cos( $rea );
$step = 0.05;
if ( 270 <= $sa )
{
if ( 360 < $ea || 0 < $ea && $ea <= 90 )
{
if ( 0 < $ea && $ea <= 90 )
{
$rea += 2 * M_PI;
}
$p = array(
$xc,
$yc,
$xc,
$yc + $z,
$xc + $w * $cossa,
$z + $yc - $h * $sinsa
);
$pt = array(
$xc,
$yc,
$xc + $w * $cossa,
$yc - $h * $sinsa
);
$a = $rsa;
for ( ; $a < 2 * M_PI; $a += $step )
{
$tca = cos( $a );
$tsa = sin( $a );
$p[] = $xc + $w * $tca;
$p[] = $z + $yc - $h * $tsa;
$pt[] = $xc + $w * $tca;
$pt[] = $yc - $h * $tsa;
}
$pt[] = $xc + $w;
$pt[] = $yc;
$p[] = $xc + $w;
$p[] = $z + $yc;
$p[] = $xc + $w;
$p[] = $yc;
$p[] = $xc;
$p[] = $yc;
$a = 2 * M_PI + $step;
for ( ; $a < $rea; $a += $step )
{
$pt[] = $xc + $w * cos( $a );
$pt[] = $yc - $h * sin( $a );
}
$pt[] = $xc + $w * $cosea;
$pt[] = $yc - $h * $sinea;
$pt[] = $xc;
$pt[] = $yc;
}
else
{
$p = array(
$xc,
$yc,
$xc,
$yc + $z,
$xc + $w * $cossa,
$z + $yc - $h * $sinsa
);
$pt = array(
$xc,
$yc,
$xc + $w * $cossa,
$yc - $h * $sinsa
);
$rea = $rea == 0 ? 2 * M_PI : $rea;
$a = $rsa;
for ( ; $a < $rea; $a += $step )
{
$tca = cos( $a );
$tsa = sin( $a );
$p[] = $xc + $w * $tca;
$p[] = $z + $yc - $h * $tsa;
$pt[] = $xc + $w * $tca;
$pt[] = $yc - $h * $tsa;
}
$pt[] = $xc + $w * $cosea;
$pt[] = $yc - $h * $sinea;
$pt[] = $xc;
$pt[] = $yc;
$p[] = $xc + $w * $cosea;
$p[] = $z + $yc - $h * $sinea;
$p[] = $xc + $w * $cosea;
$p[] = $yc - $h * $sinea;
$p[] = $xc;
$p[] = $yc;
}
}
else if ( 180 <= $sa )
{
$p = array(
$xc,
$yc,
$xc,
$yc + $z,
$xc + $w * $cosea,
$z + $yc - $h * $sinea
);
$pt = array(
$xc,
$yc,
$xc + $w * $cosea,
$yc - $h * $sinea
);
$a = $rea;
for ( ; $rsa < $a; $a -= $step )
{
$tca = cos( $a );
$tsa = sin( $a );
$p[] = $xc + $w * $tca;
$p[] = $z + $yc - $h * $tsa;
$pt[] = $xc + $w * $tca;
$pt[] = $yc - $h * $tsa;
}
$pt[] = $xc + $w * $cossa;
$pt[] = $yc - $h * $sinsa;
$pt[] = $xc;
$pt[] = $yc;
$p[] = $xc + $w * $cossa;
$p[] = $z + $yc - $h * $sinsa;
$p[] = $xc + $w * $cossa;
$p[] = $yc - $h * $sinsa;
$p[] = $xc;
$p[] = $yc;
}
else if ( 90 <= $sa )
{
if ( 180 < $ea )
{
$p = array(
$xc,
$yc,
$xc,
$yc + $z,
$xc + $w * $cosea,
$z + $yc - $h * $sinea
);
$pt = array(
$xc,
$yc,
$xc + $w * $cosea,
$yc - $h * $sinea
);
$a = $rea;
for ( ; M_PI < $a; $a -= $step )
{
$tca = cos( $a );
$tsa = sin( $a );
$p[] = $xc + $w * $tca;
$p[] = $z + $yc - $h * $tsa;
$pt[] = $xc + $w * $tca;
$pt[] = $yc - $h * $tsa;
}
$p[] = $xc - $w;
$p[] = $z + $yc;
$p[] = $xc - $w;
$p[] = $yc;
$p[] = $xc;
$p[] = $yc;
$pt[] = $xc - $w;
$pt[] = $z + $yc;
$pt[] = $xc - $w;
$pt[] = $yc;
$a = M_PI - $step;
for ( ; $rsa < $a; $a -= $step )
{
$pt[] = $xc + $w * cos( $a );
$pt[] = $yc - $h * sin( $a );
}
$pt[] = $xc + $w * $cossa;
$pt[] = $yc - $h * $sinsa;
$pt[] = $xc;
$pt[] = $yc;
}
else
{
$p = array(
$xc,
$yc,
$xc,
$yc + $z,
$xc + $w * $cosea,
$z + $yc - $h * $sinea,
$xc + $w * $cosea,
$yc - $h * $sinea,
$xc,
$yc
);
$pt = array(
$xc,
$yc,
$xc + $w * $cosea,
$yc - $h * $sinea
);
$a = $rea;
for ( ; $rsa < $a; $a -= $step )
{
$pt[] = $xc + $w * cos( $a );
$pt[] = $yc - $h * sin( $a );
}
$pt[] = $xc + $w * $cossa;
$pt[] = $yc - $h * $sinsa;
$pt[] = $xc;
$pt[] = $yc;
}
}
else
{
$p = array(
$xc,
$yc,
$xc,
$yc + $z,
$xc + $w * $cossa,
$z + $yc - $h * $sinsa,
$xc + $w * $cossa,
$yc - $h * $sinsa,
$xc,
$yc
);
$pt = array(
$xc,
$yc,
$xc + $w * $cossa,
$yc - $h * $sinsa
);
$a = $rsa;
for ( ; $a < $rea; $a += $step )
{
$pt[] = $xc + $w * cos( $a );
$pt[] = $yc - $h * sin( $a );
}
$pt[] = $xc + $w * $cosea;
$pt[] = $yc - $h * $sinea;
$pt[] = $xc;
$pt[] = $yc;
}
$img->pushcolor( $fillcolor.":".$shadow );
$img->filledpolygon( $p );
$img->popcolor( );
$img->pushcolor( $fillcolor );
$img->filledpolygon( $pt );
$img->popcolor( );
}
function setstartangle( $aStart )
{
if ( $aStart < 0 || 360 < $aStart )
{
jpgrapherror::raise( "Slice start angle must be between 0 and 360 degrees." );
}
$this->startangle = $aStart;
}
function pie3d( $aaoption, $img, $data, $colors, $xc, $yc, $d, $angle, $z, $shadow = 0.65, $startangle = 0, $edgecolor = "", $edgeweight = 1 )
{
$h = $angle / 90 * $d;
$sum = 0;
$i = 0;
for ( ; $i < count( $data ); ++$i )
{
$sum += $data[$i];
}
if ( $sum == 0 )
{
return;
}
if ( $this->labeltype == 2 )
{
$this->adjusted_data = $this->adjpercentage( $data );
}
$accsum = 0;
$a = $startangle;
$a = $this->normangle( $a );
$idx = 0;
$adjexplode = array( );
$numcolors = count( $colors );
$i = 0;
for ( ; $i < count( $data ); ++$i, ++$idx )
{
$da = $data[$i] / $sum * 360;
if ( empty( $this->explode_radius[$i] ) )
{
$this->explode_radius[$i] = 0;
}
$expscale = 1;
if ( $aaoption == 1 )
{
$expscale = 2;
}
$la = $a + $da / 2;
$explode = array(
$xc + $this->explode_radius[$i] * cos( $la * M_PI / 180 ) * $expscale,
$yc - $this->explode_radius[$i] * sin( $la * M_PI / 180 ) * ( $h / $d ) * $expscale
);
$adjexplode[$idx] = $explode;
$labeldata[$i] = array(
$la,
$explode[0],
$explode[1]
);
$originalangles[$i] = array(
$a,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -