You are here

function _charts_settings in Charts 7

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

Module settings page. Users can set the default layout of their charts.

3 calls to _charts_settings()
charts_plugin_style_chart::options in views/charts_plugin_style_chart.inc
Set default options.
_charts_chart in ./charts.inc
The main Chart API function, that calls any chart provider to print the given data.
_charts_settings_form in ./charts.admin.inc
Module settings page. Users can set the default layout of their charts.

File

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

Code

function _charts_settings() {

  // Get the previously saved data from Data Base
  static $default = array();
  if (empty($default)) {
    $default = variable_get('charts_settings', array());

    // Plugin
    $charts_info = module_invoke_all('charts_info', 'list');
    foreach ($charts_info as $chart_code => $chart) {
      $default['#plugins'][$chart_code] = $chart['name'];
    }
    asort($default['#plugins']);
    $default['#plugin'] = empty($default['#plugin']) ? current(array_keys($default['#plugins'])) : $default['#plugin'];

    // Type
    $default['#types'] = module_invoke_all('chart_types');
    $ctypes_allowed = array_fill_keys($charts_info[$default['#plugin']]['types'], TRUE);
    foreach (array_keys($default['#types']) as $ctype_code) {
      if (empty($ctypes_allowed[$ctype_code])) {
        unset($default['#types'][$ctype_code]);
      }
    }
    $default['#type'] = empty($default['#type']) ? current(array_keys($default['#types'])) : $default['#type'];

    // Width and Height
    $default['#width'] = empty($default['#width']) ? 400 : $default['#width'];
    $default['#height'] = empty($default['#height']) ? 200 : $default['#height'];

    // Color Palette
    $default['#series_attributes'][] = '#color';
    $default['#color_palettes'] = _charts_settings_color_palette();
    if (empty($default['#color'])) {
      $default['#color_palette'] = current(array_keys($default['#color_palettes']));
      $default['#color'] = explode(',', $default['#color_palette']);
      $default['#color']['background'] = array_shift($default['#color']);
      $default['#color']['text'] = array_shift($default['#color']);
    }
    else {
      $color_palette = implode(',', $default['#color']);
      $default['#color_palette'] = isset($default['#color_palettes'][$color_palette]) ? $color_palette : '';
    }
  }
  return $default;
}