You are here

function _charts_chart in Charts 7

Same name and namespace in other branches
  1. 6 charts.inc \_charts_chart()

The main Chart API function, that calls any chart provider to print the given data.

Parameters

&$data: Array. The chart data, described on chart_api.txt

Return value

String. The HTML with the propper chart (might include Flash or JavaScript external files)

1 call to _charts_chart()
charts_chart in ./charts.module
The main Chart API function, that calls any chart provider to print the given data.

File

./charts.inc, line 18
@author Bruno Massa http://drupal.org/user/67164

Code

function _charts_chart(&$data) {

  // Get the previously saved data from database
  $settings = _charts_settings();

  // Check if the Chart will use the color palette for individual values
  // instead for series, like Pie charts
  $options = array(
    'pie2D' => TRUE,
    'pie3D' => TRUE,
  );
  if (!empty($data['#type']) and !empty($options[$data['#type']]) or !empty($options[$settings['#type']])) {
    $invert_attributes = TRUE;
  }

  // Merge deafult series attributes with data
  $number = -1;
  foreach (element_children($data) as $series) {
    ++$number;
    if (!is_numeric($series)) {
      $data[$number] = $data[$series];
      unset($data[$series]);
      $series = $number;
    }
    foreach (element_children($data[$series]) as $value) {
      if (!is_array($data[$series][$value])) {
        $data[$series][$value] = array(
          '#value' => $data[$series][$value],
        );
      }
      if (!empty($invert_attributes)) {
        _chart_series_attributes($data[$series][$value], $value, $settings);
      }
    }
    if (empty($invert_attributes)) {
      _chart_series_attributes($data[$series], $series, $settings);
    }
  }
  $data += $settings;
  if (!empty($data['#plugin']) and $chart_provider = module_invoke_all('charts_info') and isset($chart_provider[$data['#plugin']]['file']) and is_file($chart_provider[$data['#plugin']]['file']) and $func = $chart_provider[$data['#plugin']]['render']) {

    // Include the file that has the rendering function
    include_once $chart_provider[$data['#plugin']]['file'];

    // Using the filter's rendering function, print the chart
    return $func($data);
  }
  return '';
}