array( 'arguments' => array('element' => array(), 'data' => array(), 'options' => array()), ), ); } /** * Main flot graphing function * * @param $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. * @param $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. * @param $options * Options to pass to flot. Optional. See flot's API.txt for more details. * @param $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 * The placeholder element */ 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 = ''; if ($loader) { $extra = 'Drupal.flot.'. str_replace('-', '_', $element['id']) .'_data = '. drupal_to_js($data) .';'; $extra .= "$loader"; $data = array(); } $data = 'if (Drupal.jsEnabled) { $(document).ready(function() { Drupal.flot.'. str_replace('-', '_', $element['id']).' = $.plot($("#'.$element['id'].'"), '. drupal_to_js($data). ', '. drupal_to_js($options) .'); '. $extra .' }); }'; drupal_add_js($data, 'inline'); } return '
'; } /** * Helper to add flot's js */ function flot_add_js() { static $added; if ($added !== true) { drupal_set_html_head(''); drupal_add_js(drupal_get_path('module', 'flot') .'/flot/jquery.flot.js'); drupal_add_js('if (Drupal.jsEnabled) { Drupal.flot = {}; }', 'inline'); $added = true; } } /** * Data class for the flot API. * * Make some nested objects to keep things simple when creating a data series. */ class flotData { public $data; public $lines; public $bars; public $points; function __construct($data) { $this->data = $data; $this->lines = new stdClass(); $this->bars = new stdClass(); $this->points = new stdClass(); } }