PieGraph::GetSlice PHP Method

GetSlice() protected method

Returns a single slice of pie
protected GetSlice ( $angle_start, $angle_end, &$attr )
    protected function GetSlice($angle_start, $angle_end, &$attr)
    {
        $x_start = $y_start = $x_end = $y_end = 0;
        $angle_start += $this->s_angle;
        $angle_end += $this->s_angle;
        $this->CalcSlice($angle_start, $angle_end, $x_start, $y_start, $x_end, $y_end);
        if ((string) $x_start == (string) $x_end && (string) $y_start == (string) $y_end) {
            $attr['cx'] = $this->x_centre;
            $attr['cy'] = $this->y_centre;
            $attr['rx'] = $this->radius_x;
            $attr['ry'] = $this->radius_y;
            return $this->Element('ellipse', $attr);
        } else {
            $outer = $angle_end - $angle_start > M_PI ? 1 : 0;
            $sweep = $this->reverse ? 0 : 1;
            $attr['d'] = "M{$this->x_centre},{$this->y_centre} L{$x_start},{$y_start} " . "A{$this->radius_x} {$this->radius_y} 0 {$outer},{$sweep} {$x_end},{$y_end} z";
            return $this->Element('path', $attr);
        }
    }

Usage Example

 /**
  * Returns a single slice of pie
  */
 protected function GetSlice($item, $angle_start, $angle_end, $radius_x, $radius_y, &$attr, $single_slice)
 {
     if ($single_slice) {
         return parent::GetSlice($item, $angle_start, $angle_end, $radius_x, $radius_y, $attr, $single_slice);
     }
     $x_start = $y_start = $x_end = $y_end = 0;
     $angle_start += $this->s_angle;
     $angle_end += $this->s_angle;
     $this->CalcSlice($angle_start, $angle_end, $radius_x, $radius_y, $x_start, $y_start, $x_end, $y_end);
     $outer = $angle_end - $angle_start > M_PI ? 1 : 0;
     $sweep = $this->reverse ? 0 : 1;
     // find explosiveness
     list($xo, $yo) = $this->GetExplode($item, $angle_start, $angle_end);
     $xc = $this->x_centre + $xo;
     $yc = $this->y_centre + $yo;
     $x_start += $xo;
     $x_end += $xo;
     $y_start += $yo;
     $y_end += $yo;
     $attr['d'] = "M{$xc},{$yc} L{$x_start},{$y_start} " . "A{$radius_x} {$radius_y} 0 {$outer},{$sweep} {$x_end},{$y_end} z";
     return $this->Element('path', $attr);
 }