You are here

function ChartsGraphsAmcharts::_preprocess_values_pie in Charts and Graphs 6.2

Same name and namespace in other branches
  1. 7 apis/charts_graphs_amcharts/charts_graphs_amcharts.class.inc \ChartsGraphsAmcharts::_preprocess_values_pie()
1 call to ChartsGraphsAmcharts::_preprocess_values_pie()
ChartsGraphsAmcharts::_preprocess_values in apis/charts_graphs_amcharts/charts_graphs_amcharts.class.inc

File

apis/charts_graphs_amcharts/charts_graphs_amcharts.class.inc, line 57

Class

ChartsGraphsAmcharts
Implementation of abstract class ChartsGraphsFlashCanvas for amCharts library.

Code

function _preprocess_values_pie() {
  $pie_data = array();
  $first_series = reset($this->series);
  $idx = 0;
  $max_val = max($first_series);
  $max_idx = -1;
  $x_labels_keys = array_keys($this->x_labels);
  if (is_array($first_series)) {
    foreach ($first_series as $val) {
      $pie_data[$this->x_labels[$x_labels_keys[$idx]]] = $val;
      if ($val == $max_val) {
        $max_idx = $idx;
      }
      $idx++;
    }
  }
  $slices = array();
  if (is_array($pie_data)) {
    $idx = 0;
    foreach ($pie_data as $label => $point) {
      $slice = array(
        '#id' => 'slice',
        '#attributes' => array(
          'title' => $this
            ->encode_for_xml($label),
        ),
        '#value' => $this
          ->encode_for_xml($point),
      );
      if ($idx == $max_idx) {
        $slice['#attributes']['pull_out'] = 'true';
      }
      $slices[] = $slice;
      $idx++;
    }
  }
  $slices = $this
    ->merge_xml_values($slices, $this->slices);
  $pie = array(
    '#id' => 'pie',
    '#children' => $slices,
  );
  $this->data_to_use = array(
    $pie,
  );
}