function _build_pie_chart($config, $chart) { /* polar coordinates */ $theme = drawing_graph_color($config, $chart); $start = 0; //define a starting angle for the first slice $separation = 0.1; // this will be for exploded pie $r = min($config['height'], $config['width'])/2 - 20; $center = '0,0'; foreach($chart['points'] as $points) { $sum += $points[1]; } $L = _crd(_rad_to_crd($start, $r)); $ang = 0; foreach($chart['points'] as $n => $points) { /* $points[0] is the label, $points[1] is the value*/ $stepsize = $points[1]/$sum * 2 * M_PI; //angle of the slice if($stepsize > M_PI) { $longarc = 1; } else { $longarc = 0;} $ang += $stepsize; //to calculate the angle of the end of the arc /*$A = _crd(_rad_to_crd($ang - $separation, $r)); //end of the arc*/ $A = _crd(_rad_to_crd($ang, $r)); //end of the arc /*$center = _crd(_rad_to_crd($ang - $stepsize/2, 10)); //for exploded pie*/ $d[$n] = 'M ' . $center // move to the center (if we want to explode the pie, do here) . ' L ' . $L // move to the start of the arc . ' A ' . $r . ',' . $r . ' 0 ' . $longarc . ',1 ' . $A //arc /*. ' A ' . $r . ',' . $r . ' 0 0,1 ' . $A //arc*/ . ' Z'; // close the curve /*$L = _crd(_rad_to_crd($ang - $separation, $r)); //end of the arc*/ $L = $A; $canvas['plot']['slice_'.$n] = array( '#type' => 'drawing_path', '#fill' => $theme[$n]['fill'], '#explicit' => TRUE, '#points' => $d[$n], '#opacity' => 0.5, ); /* Label part */ $dist = $config['labels']['inside'] ? 2/3 * $r : $r *1.1; $coordinates = _rad_to_crd($ang - $stepsize/2, $dist); $canvas['plot']['label_'.$n] = array( '#type' => 'drawing_text', '#value' => $points[0], '#cx' => $coordinates[0], '#cy' => $coordinates[1], '#stroke' => 'none', ); } return $canvas; }