You are here

function charts_examples in Charts 7.2

Menu callback; Display all examples in the system.

1 string reference to 'charts_examples'
charts_menu in ./charts.module
Implements hook_menu().

File

includes/charts.examples.inc, line 6

Code

function charts_examples($library = NULL, $id = NULL) {
  $functions = get_defined_functions();
  if ($library && ($library_info = chart_get_library($library))) {
    $charts_info = array(
      $library => $library_info,
    );
  }
  else {
    $charts_info = charts_info();
  }
  $table = array();
  foreach ($charts_info as $library => $chart_library_info) {
    $table['header'][] = array(
      'width' => 1 / count($charts_info) * 100 . '%',
      'data' => $chart_library_info['label'],
    );
  }
  $table['rows'] = array();
  foreach ($functions['user'] as $function) {
    if ($id && '_charts_examples_' . $id === $function || !$id && strpos($function, '_charts_examples_') === 0) {
      $row = array();
      foreach ($charts_info as $library => $chart_library_info) {
        $example = $function();
        $example['chart']['#chart_library'] = $library;
        $example['chart']['#height'] = 200;
        $notes = '';
        if (isset($example['notes'][$library])) {
          $notes = '<p>' . t('Note') . ': ' . $example['notes'][$library] . '</p>';
        }
        $row[] = array(
          'data' => drupal_render($example['chart']) . l(t('View'), 'charts/examples/built-in/' . $library . '/' . str_replace('_charts_examples_', '', $function)) . $notes,
          'valign' => 'top',
        );
      }
      $table['rows'][] = $row;
    }
  }
  return theme('table', $table);
}