public function Draw()
{
if (!$this->calc_done) {
$this->Calc();
}
$speed_in = $this->show_labels && $this->label_fade_in_speed ? $this->label_fade_in_speed / 100.0 : 0;
$speed_out = $this->show_labels && $this->label_fade_out_speed ? $this->label_fade_out_speed / 100.0 : 0;
// take a copy for sorting
$values = $this->GetValues();
$total = array_sum($values);
$unit_slice = 2.0 * M_PI / $total;
$ccount = count($this->colours);
$vcount = count($values);
$sub_total = 0.0;
// need to store the original position of each value, because the
// sorted list must still refer to the relevant legend entries
$position = 0;
foreach ($values as $key => $value) {
$values[$key] = array($position++, $value);
}
if ($this->sort) {
uasort($values, 'PieGraph::svggpsort');
}
$body = '';
$labels = '';
$slice = 0;
foreach ($values as $key => $value) {
// get the original array position of the value
$original_position = $value[0];
$value = $value[1];
if (!$value) {
continue;
}
++$slice;
$angle_start = $sub_total * $unit_slice;
$angle_end = ($sub_total + $value) * $unit_slice;
// get the path (or whatever) for a pie slice
$attr = array('fill' => $this->GetColour(($slice - 1) % $ccount, true));
$style = $attr;
$this->SetStroke($style);
// store the current style referenced by the original position
$this->slice_styles[$original_position] = $style;
if ($this->show_tooltips) {
$this->SetTooltip($attr, $key, $value, !$this->compat_events);
}
$t_style = NULL;
if ($this->show_labels) {
$ac = $this->s_angle + ($sub_total + $value * 0.5) * $unit_slice;
$xc = $this->label_position * $this->radius_x * cos($ac);
$yc = ($this->reverse ? -1 : 1) * $this->label_position * $this->radius_y * sin($ac);
$text['id'] = $this->NewID();
if ($this->label_fade_in_speed && $this->compat_events) {
$text['opacity'] = '0.0';
}
$tx = $this->x_centre + $xc;
$ty = $this->y_centre + $yc + $this->label_font_size * 0.3;
// display however many lines of label
$parts = array($key);
if ($this->show_label_amount) {
$parts[] = $value;
}
if ($this->show_label_percent) {
$parts[] = $value / $total * 100.0 . '%';
}
$x_offset = empty($this->label_back_colour) ? $tx : 0;
$string = $this->TextLines($parts, $x_offset, $this->label_font_size);
if (!empty($this->label_back_colour)) {
$labels .= $this->ContrastText($tx, $ty, $string, $this->label_colour, $this->label_back_colour, $text);
} else {
$text['x'] = $tx;
$text['y'] = $ty;
$text['fill'] = $this->label_colour;
$labels .= $this->Element('text', $text, NULL, $string);
}
}
if ($speed_in || $speed_out) {
$this->SetFader($attr, $speed_in, $speed_out, $text['id'], !$this->compat_events);
}
$path = $this->GetSlice($angle_start, $angle_end, $attr);
$body .= $this->GetLink($key, $path);
$sub_total += $value;
}
// group the slices
$attr = array();
$this->SetStroke($attr, 'round');
$body = $this->Element('g', $attr, NULL, $body);
if ($this->show_labels) {
$label_group = array('text-anchor' => 'middle', 'font-size' => $this->label_font_size, 'font-family' => $this->label_font, 'font-weight' => $this->label_font_weight);
$labels = $this->Element('g', $label_group, NULL, $labels);
}
return $body . $labels;
}