You are here

function ChartsAmcharts::_preprocess_values_pie in Charts and Graphs 6

1 call to ChartsAmcharts::_preprocess_values_pie()
ChartsAmcharts::_preprocess_values in apis/amcharts/amcharts.class.inc

File

apis/amcharts/amcharts.class.inc, line 34
Implementation of abstract class ChartCanvas for amCharts library.

Class

ChartsAmcharts
Implementation of abstract class ChartCanvas for amCharts library.

Code

function _preprocess_values_pie() {
  $pie_data = array();
  $keys = array_keys($this->series);
  $first_key = $keys[0];
  $first_series = $this->series[$first_key];
  $idx = 0;
  $max_val = max($first_series);
  $max_idx = -1;
  if (is_array($first_series)) {
    foreach ($first_series as $val) {
      $pie_data[$this->x_labels[$idx]] = $val;
      if ($val == $max_val) {
        $max_idx = $idx;
      }
      $idx++;
    }
  }
  $out = '<pie>';
  if (is_array($pie_data)) {
    $idx = 0;
    foreach ($pie_data as $label => $point) {
      $pullout = $idx == $max_idx ? " pull_out='true' " : '';
      $out .= "<slice title='{$label}' {$pullout} >{$point}</slice>";
      $idx++;
    }
  }
  $out .= '</pie>';
  return $out;
}