You are here

function theme_flot_graph in Flot 6

Same name and namespace in other branches
  1. 7 flot.module \theme_flot_graph()

Main flot graphing function

Parameters

$element: An associative array to define a placeholder element. If an 'id' is omitted one will be generated, If no 'style' is specified and width and height style will be added. In short you can just pass an empty array and everything will still work. This argument is essentially optional and has been kept as the first argument to remain consistant with flots own api.

$data: The data series for the graph. Optional. See flot's API.txt for more details. This module defines the flotData class which can be used or extended to make generating data objects simpler.

$options: Options to pass to flot. Optional. See flot's API.txt for more details.

$loader: Allows alterative loading of flot data. If 'false' data will passed directly to an invocation of $.plot(). Otherwise the contents of $loader should be js.

Return value

The placeholder element

2 theme calls to theme_flot_graph()
flot-views-style.tpl.php in views/flot-views-style.tpl.php
flot-views-summary-style.tpl.php Template to display a flot summary view.
flot-views-summary-style.tpl.php in views/flot-views-summary-style.tpl.php
flot-views-summary-style.tpl.php Template to display a flot summary view.

File

./flot.module, line 47

Code

function theme_flot_graph($element, $data = array(), $options = array(), $loader = false) {
  static $n;
  if (!isset($element['id'])) {
    $n++;
    $element['id'] = 'flot-auto-identifier-' . $n;
  }
  if (!isset($element['style'])) {
    $element['style'] = "width:100%;height:200px";
  }
  flot_add_js();
  if (count($data)) {
    $extra = '';
    $id = str_replace('-', '_', $element['id']);
    if ($loader) {
      $json_data = function_exists('json_encode') ? json_encode($data) : drupal_to_js($data);
      $extra = "Drupal.flot.{$id}_data = {$json_data}; {$loader}";
      $data = array();
    }
    $json_data = function_exists('json_encode') ? json_encode($data) : drupal_to_js($data);
    $json_options = function_exists('json_encode') ? json_encode($options) : drupal_to_js($options);
    $data = "if (Drupal.jsEnabled) {\n      \$(document).ready(function() {\n        Drupal.flot.{$id} = \$.plot(\$('#{$element['id']}'), {$json_data}, {$json_options});\n        {$extra}\n      });\n    }";
    drupal_add_js($data, 'inline');
  }
  return '<div ' . drupal_attributes($element) . '> </div>';
}