View source
<?php
function flot_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'flot') . '/views',
);
}
function flot_theme() {
return array(
'flot_graph' => array(
'arguments' => array(
'element' => array(),
'data' => array(),
'options' => array(),
),
),
);
}
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>';
}
function flot_add_js() {
static $added;
if ($added !== true) {
if (module_exists('libraries') && libraries_get_path('flot')) {
$path = libraries_get_path('flot');
}
if (!isset($path)) {
$path = drupal_get_path('module', 'flot') . '/flot';
}
$excanvas = file_exists("{$path}/excanvas.min.js") ? "{$path}/excanvas.min.js" : "{$path}/excanvas.pack.js";
drupal_set_html_head('<!--[if IE]><script language="javascript" type="text/javascript" src="' . base_path() . $excanvas . '"></script><![endif]-->');
drupal_add_js($path . '/jquery.flot.js');
drupal_add_js('if (Drupal.jsEnabled) { Drupal.flot = {}; }', 'inline');
$added = true;
}
}
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();
$this->grid = new StdClass();
}
}
class flotStyle {
public $colors;
public $grid;
public $lines;
public $bars;
public $points;
function __construct() {
$this->lines = new StdClass();
$this->bars = new StdClass();
$this->points = new StdClass();
$this->lines->show = FALSE;
$this->bars->show = FALSE;
$this->points->show = FALSE;
$this->colors = array(
'#666',
'#999',
'#ccc',
);
$this->shadowSize = 0;
$this->grid = new StdClass();
$this->grid->labelMargin = 0;
$this->grid->tickColor = '#eee';
$this->grid->backgroundColor = '#f8f8f8';
$this->grid->borderWidth = 0;
$this->grid->hoverable = true;
$this->grid->autoHighlight = true;
$this->grid->clickable = false;
}
function axis_ticks($axis = 'yaxis', $ticks = array()) {
if (count($ticks)) {
$this->{$axis} = new StdClass();
$this->{$axis}->ticks = $ticks;
}
}
function axis_range($axis = 'yaxis', $range = array(), $granularity = 0) {
if (count($range)) {
$this->{$axis} = new StdClass();
$this->{$axis}->min = min($range);
$this->{$axis}->max = max($range);
if (is_numeric($granularity) && $granularity != 0) {
$tickSize = ($this->{$axis}->max - $this->{$axis}->min) / $granularity;
$this->{$axis}->tickSize = floor($tickSize);
}
}
}
}
class flotStyleLine extends flotStyle {
function __construct() {
parent::__construct();
$this->lines->show = TRUE;
$this->lines->lineWidth = 1;
$this->lines->fill = 0.1;
}
}
class flotStyleBar extends flotStyle {
function __construct() {
parent::__construct();
$this->bars->show = TRUE;
$this->bars->lineWidth = 0;
$this->bars->fill = 0.5;
}
}
class flotStylePoint extends flotStyle {
function __construct() {
parent::__construct();
$this->points->show = TRUE;
$this->points->lineWidth = 1;
$this->points->fill = 0.1;
}
}