$pt[] = $yc; for( $a=M_PI-$step; $a > $rsa; $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 { // $sa >= 90 && $ea <= 180 $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); for( $a=$rea; $a>$rsa; $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 { // sa > 0 && ea < 90 $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); for( $a=$rsa; $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 || $aStart > 360 ) { JpGraphError::RaiseL(14004);//('Slice start angle must be between 0 and 360 degrees.'); } $this->startangle = $aStart; } // Draw a 3D Pie function Pie3D($aaoption,$img,$data,$colors,$xc,$yc,$d,$angle,$z, $shadow=0.65,$startangle=0,$edgecolor="",$edgeweight=1) { //--------------------------------------------------------------------------- // As usual the algorithm get more complicated than I originally // envisioned. I believe that this is as simple as it is possible // to do it with the features I want. It's a good exercise to start // thinking on how to do this to convince your self that all this // is really needed for the general case. // // The algorithm two draw 3D pies without "real 3D" is done in // two steps. // First imagine the pie cut in half through a thought line between // 12'a clock and 6'a clock. It now easy to imagine that we can plot // the individual slices for each half by starting with the topmost // pie slice and continue down to 6'a clock. // // In the algortithm this is done in three principal steps // Step 1. Do the knife cut to ensure by splitting slices that extends // over the cut line. This is done by splitting the original slices into // upto 3 subslices. // Step 2. Find the top slice for each half // Step 3. Draw the slices from top to bottom // // The thing that slightly complicates this scheme with all the // angle comparisons below is that we can have an arbitrary start // angle so we must take into account the different equivalence classes. // For the same reason we must walk through the angle array in a // modulo fashion. // // Limitations of algorithm: // * A small exploded slice which crosses the 270 degree point // will get slightly nagged close to the center due to the fact that // we print the slices in Z-order and that the slice left part // get printed first and might get slightly nagged by a larger // slice on the right side just before the right part of the small // slice. Not a major problem though. //--------------------------------------------------------------------------- // Determine the height of the ellippse which gives an // indication of the inclination angle $h = ($angle/90.0)*$d; $sum = 0; for($i=0; $ilabeltype == 2 ) { $this->adjusted_data = $this->AdjPercentage($data); } // Setup the start $accsum = 0; $a = $startangle; $a = $this->NormAngle($a); // // Step 1 . Split all slices that crosses 90 or 270 // $idx=0; $adjexplode=array(); $numcolors = count($colors); for($i=0; $iexplode_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,$a+$da); $ne = $this->NormAngle($a+$da); if( $da <= 180 ) { // If the slice size is <= 90 it can at maximum cut across // one boundary (either 90 or 270) where it needs to be split $split=-1; // no split if( ($da<=90 && ($a <= 90 && $ne > 90)) || (($da <= 180 && $da >90) && (($a < 90 || $a >= 270) && $ne > 90)) ) { $split = 90; } elseif( ($da<=90 && ($a <= 270 && $ne > 270)) || (($da<=180 && $da>90) && ($a >= 90 && $a < 270 && ($a+$da) > 270 )) ) { $split = 270; } if( $split > 0 ) { // split in two $angles[$idx] = array($a,$split); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; $angles[++$idx] = array($split,$ne); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; } else { // no split $angles[$idx] = array($a,$ne); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; } } else { // da>180 // Slice may, depending on position, cross one or two // bonudaries if( $a < 90 ) $split = 90; elseif( $a <= 270 ) $split = 270; else $split = 90; $angles[$idx] = array($a,$split); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; //if( $a+$da > 360-$split ) { // For slices larger than 270 degrees we might cross // another boundary as well. This means that we must // split the slice further. The comparison gets a little // bit complicated since we must take into accound that // a pie might have a startangle >0 and hence a slice might // wrap around the 0 angle. // Three cases: // a) Slice starts before 90 and hence gets a split=90, but // we must also check if we need to split at 270 // b) Slice starts after 90 but before 270 and slices // crosses 90 (after a wrap around of 0) // c) If start is > 270 (hence the firstr split is at 90) // and the slice is so large that it goes all the way // around 270. if( ($a < 90 && ($a+$da > 270)) || ($a > 90 && $a<=270 && ($a+$da>360+90) ) || ($a > 270 && $this->NormAngle($a+$da)>270) ) { $angles[++$idx] = array($split,360-$split); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; $angles[++$idx] = array(360-$split,$ne); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; } else { // Just a simple split to the previous decided // angle. $angles[++$idx] = array($split,$ne); $adjcolors[$idx] = $colors[$i % $numcolors]; $adjexplode[$idx] = $explode; } } $a += $da; $a = $this->NormAngle($a); } // Total number of slices $n = count($angles); for($i=0; $i<$n; ++$i) { list($dbgs,$dbge) = $angles[$i]; } // // Step 2. Find start index (first pie that starts in upper left quadrant) // $minval = $angles[0][0]; $min = 0; for( $i=0; $i<$n; ++$i ) { if( $angles[$i][0] < $minval ) { $minval = $angles[$i][0]; $min = $i; } } $j = $min; $cnt = 0; while( $angles[$j][1] <= 90 ) { $j++; if( $j>=$n) { $j=0; } if( $cnt > $n ) { JpGraphError::RaiseL(14005); //("Pie3D Internal error (#1). Trying to wrap twice when looking for start index"); } ++$cnt; } $start = $j; // // Step 3. Print slices in z-order // $cnt = 0; // First stroke all the slices between 90 and 270 (left half circle) // counterclockwise while( $angles[$j][0] < 270 && $aaoption !== 2 ) { list($x,$y) = $adjexplode[$j]; $this->Pie3DSlice($img,$x,$y,$d,$h,$angles[$j][0],$angles[$j][1], $z,$adjcolors[$j],$shadow); $last = array($x,$y,$j); $j++; if( $j >= $n ) $j=0; if( $cnt > $n ) { JpGraphError::RaiseL(14006); //("Pie3D Internal Error: Z-Sorting algorithm for 3D Pies is not working properly (2). Trying to wrap twice while stroking."); } ++$cnt; } $slice_left = $n-$cnt; $j=$start-1; if($j<0) $j=$n-1; $cnt = 0; // The stroke all slices from 90 to -90 (right half circle) // clockwise while( $cnt < $slice_left && $aaoption !== 2 ) { list($x,$y) = $adjexplode[$j]; $this->Pie3DSlice($img,$x,$y,$d,$h,$angles[$j][0],$angles[$j][1], $z,$adjcolors[$j],$shadow); $j--; if( $cnt > $n ) { JpGraphError::RaiseL(14006); //("Pie3D Internal Error: Z-Sorting algorithm for 3D Pies is not working properly (2). Trying to wrap twice while stroking."); } if($j<0) $j=$n-1; $cnt++; } // Now do a special thing. Stroke the last slice on the left // halfcircle one more time. This is needed in the case where // the slice close to 270 have been exploded. In that case the // part of the slice close to the center of the pie might be // slightly nagged. if( $aaoption !== 2 ) $this->Pie3DSlice($img,$last[0],$last[1],$d,$h,$angles[$last[2]][0], $angles[$last[2]][1],$z,$adjcolors[$last[2]],$shadow); if( $aaoption !== 1 ) { // Now print possible labels and add csim $img->SetFont($this->value->ff,$this->value->fs); $margin = $img->GetFontHeight()/2 + $this->value->margin ; for($i=0; $i < count($data); ++$i ) { $la = $labeldata[$i][0]; $x = $labeldata[$i][1] + cos($la*M_PI/180)*($d+$margin); $y = $labeldata[$i][2] - sin($la*M_PI/180)*($h+$margin); if( $la > 180 && $la < 360 ) $y += $z; if( $this->labeltype == 0 ) { if( $sum > 0 ) $l = 100*$data[$i]/$sum; else $l = 0; } elseif( $this->labeltype == 1 ) { $l = $data[$i]; } else { $l = $this->adjusted_data[$i]; } if( isset($this->labels[$i]) && is_string($this->labels[$i]) ) $l=sprintf($this->labels[$i],$l); $this->StrokeLabels($l,$img,$labeldata[$i][0]*M_PI/180,$x,$y,$z); $this->AddSliceToCSIM($i,$labeldata[$i][1],$labeldata[$i][2],$h*2,$d*2,$z, $originalangles[$i][0],$originalangles[$i][1]); } } // // Finally add potential lines in pie // if( $edgecolor=="" || $aaoption !== 0 ) re