Skip to content

Commit cb24d93

Browse files
committed
Coder upgrade from 6.x to 7.x
1 parent ba16ebd commit cb24d93

6 files changed

+55
-44
lines changed

flot.info

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
name = Flot
22
description = Provides an API for the flot js graphing library.
3-
core = 6.x
3+
core = 7.x
44

5+
6+
files[] = flot.module
7+
files[] = views/flot_handler_field_datapoint.inc
8+
files[] = views/flot_views_plugin_style.inc
9+
files[] = views/flot_views_plugin_summary_style.inc

flot.module

+25-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?php
22

33
/**
4-
* Implementation of hook_views_api().
4+
* Implements hook_views_api().
55
*/
66
function flot_views_api() {
77
return array(
88
'api' => 2,
9-
'path' => drupal_get_path('module', 'flot') .'/views',
9+
'path' => drupal_get_path('module', 'flot') . '/views',
1010
);
1111
}
1212

1313
/**
14-
* Implementation of hook_theme.
14+
* Implements hook_theme().
1515
*/
1616
function flot_theme() {
1717
return array(
1818
'flot_graph' => array(
19-
'arguments' => array('element' => array(), 'data' => array(), 'options' => array()),
19+
'variables' => array('element' => array(), 'data' => array(), 'options' => array()),
2020
),
2121
);
2222
}
@@ -25,30 +25,34 @@ function flot_theme() {
2525
* Main flot graphing function
2626
*
2727
* @param $element
28-
* An associative array to define a placeholder element. If an 'id' is
28+
* An associative array to define a placeholder element. If an 'id' is
2929
* omitted one will be generated, If no 'style' is specified and width and
3030
* height style will be added. In short you can just pass an empty array and
3131
* everything will still work. This argument is essentially optional and has
3232
* been kept as the first argument to remain consistant with flots own api.
3333
* @param $data
34-
* The data series for the graph. Optional. See flot's API.txt for more
34+
* The data series for the graph. Optional. See flot's API.txt for more
3535
* details. This module defines the flotData class which can be used or
3636
* extended to make generating data objects simpler.
3737
* @param $options
3838
* Options to pass to flot. Optional. See flot's API.txt for more details.
3939
* @param $loader
40-
* Allows alterative loading of flot data. If 'false' data will passed
40+
* Allows alterative loading of flot data. If 'false' data will passed
4141
* directly to an invocation of $.plot(). Otherwise the contents of $loader
4242
* should be js.
4343
*
4444
* @return
4545
* The placeholder element
4646
*/
47-
function theme_flot_graph($element, $data = array(), $options = array(), $loader = false) {
47+
function theme_flot_graph($variables) {
48+
$element = $variables['element'];
49+
$data = $variables['data'];
50+
$options = $variables['options'];
51+
// TODO Number of parameters in this theme funcion does not match number of parameters found in hook_theme.
4852
static $n;
4953
if (!isset($element['id'])) {
5054
$n++;
51-
$element['id'] = 'flot-auto-identifier-'. $n;
55+
$element['id'] = 'flot-auto-identifier-' . $n;
5256
}
5357

5458
if (!isset($element['style'])) {
@@ -62,22 +66,22 @@ function theme_flot_graph($element, $data = array(), $options = array(), $loader
6266
$id = str_replace('-', '_', $element['id']);
6367

6468
if ($loader) {
65-
$json_data = function_exists('json_encode') ? json_encode($data) : drupal_to_js($data);
69+
$json_data = function_exists('json_encode') ? json_encode($data) : drupal_json_encode($data);
6670
$extra = "Drupal.flot.{$id}_data = {$json_data}; {$loader}";
6771
$data = array();
6872
}
6973

70-
$json_data = function_exists('json_encode') ? json_encode($data) : drupal_to_js($data);
71-
$json_options = function_exists('json_encode') ? json_encode($options) : drupal_to_js($options);
74+
$json_data = function_exists('json_encode') ? json_encode($data) : drupal_json_encode($data);
75+
$json_options = function_exists('json_encode') ? json_encode($options) : drupal_json_encode($options);
7276
$data = "if (Drupal.jsEnabled) {
7377
$(document).ready(function() {
7478
Drupal.flot.{$id} = $.plot($('#{$element['id']}'), {$json_data}, {$json_options});
7579
{$extra}
7680
});
7781
}";
78-
drupal_add_js($data, 'inline');
82+
drupal_add_js($data, array('type' => 'inline', 'scope' => JS_DEFAULT));
7983
}
80-
return '<div '. drupal_attributes($element) .'> </div>';
84+
return '<div ' . drupal_attributes($element) . '> </div>';
8185
}
8286

8387
/**
@@ -90,24 +94,24 @@ function flot_add_js() {
9094
$path = libraries_get_path('flot');
9195
}
9296
if (!isset($path)) {
93-
$path = drupal_get_path('module', 'flot') .'/flot';
97+
$path = drupal_get_path('module', 'flot') . '/flot';
9498
}
9599

96100
// Different versions of flot have used different packing methods. Attempt to support both.
97101
$excanvas = file_exists("{$path}/excanvas.min.js") ? "{$path}/excanvas.min.js" : "{$path}/excanvas.pack.js";
98-
drupal_set_html_head('<!--[if IE]><script language="javascript" type="text/javascript" src="'. base_path() . $excanvas . '"></script><![endif]-->');
102+
drupal_add_html_head('<!--[if IE]><script language="javascript" type="text/javascript" src="' . base_path() . $excanvas . '"></script><![endif]-->', $key = NULL /* TODO Set this variable. */);
99103
drupal_add_js($path . '/jquery.flot.js');
100-
drupal_add_js('if (Drupal.jsEnabled) { Drupal.flot = {}; }', 'inline');
104+
drupal_add_js('if (Drupal.jsEnabled) { Drupal.flot = {}; }', array('type' => 'inline', 'scope' => JS_DEFAULT));
101105

102106
$added = true;
103107
}
104108
}
105109

106110
/**
107-
* Data class for the flot API.
108-
*
109-
* Make some nested objects to keep things simple when creating a data series.
110-
*/
111+
* Data class for the flot API.
112+
*
113+
* Make some nested objects to keep things simple when creating a data series.
114+
*/
111115
class flotData {
112116

113117
public $data;

views/flot.views.inc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Implementation of hook_views_data_alter().
4+
* Implements hook_views_data_alter().
55
*/
66
function flot_views_data_alter(&$data) {
77
$data['views']['datapoint'] = array(
@@ -14,7 +14,7 @@ function flot_views_data_alter(&$data) {
1414
}
1515

1616
/**
17-
* Implementation of hook_views_handlers().
17+
* Implements hook_views_handlers().
1818
*/
1919
function flot_views_handlers() {
2020
return array(
@@ -28,7 +28,7 @@ function flot_views_handlers() {
2828
}
2929

3030
/**
31-
* Implementation of hook_views_plugins().
31+
* Implements hook_views_plugins().
3232
*/
3333
function flot_views_plugins() {
3434
return array(
@@ -38,8 +38,8 @@ function flot_views_plugins() {
3838
'help' => t('Displays the result set as a flot graph.'),
3939
'handler' => 'flot_views_plugin_style',
4040
'theme' => 'flot_views_style',
41-
'theme path' => drupal_get_path('module', 'flot') .'/views',
42-
'path' => drupal_get_path('module', 'flot') .'/views',
41+
'theme path' => drupal_get_path('module', 'flot') . '/views',
42+
'path' => drupal_get_path('module', 'flot') . '/views',
4343
'even empty' => TRUE,
4444
'uses row plugin' => FALSE,
4545
'uses fields' => TRUE,
@@ -51,9 +51,9 @@ function flot_views_plugins() {
5151
'title' => t('Flot'),
5252
'help' => t('Displays the default summary as a flot graph.'),
5353
'handler' => 'flot_views_plugin_summary_style',
54-
'path' => drupal_get_path('module', 'flot') .'/views',
54+
'path' => drupal_get_path('module', 'flot') . '/views',
5555
'theme' => 'flot_views_summary_style',
56-
'theme path' => drupal_get_path('module', 'flot') .'/views',
56+
'theme path' => drupal_get_path('module', 'flot') . '/views',
5757
'type' => 'summary', // only shows up as a summary style
5858
'uses options' => TRUE,
5959
),

views/flot_handler_field_datapoint.inc

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3-
class flot_handler_field_datapoint extends views_handler_field {
3+
class flot_handler_field_datapoint extends views_handler_field {
44
protected $use_date;
55

66
/**
77
* Disable advanced render.
88
*/
9-
function allow_advanced_render() { return FALSE; }
9+
function allow_advanced_render() {
10+
return FALSE;
11+
}
1012

1113
/**
1214
* Option defaults.
@@ -82,9 +84,9 @@ class flot_handler_field_datapoint extends views_handler_field {
8284
'#title' => t('Date format'),
8385
'#type' => 'select',
8486
'#options' => array(
85-
'small' => format_date(time(), 'small'),
86-
'medium' => format_date(time(), 'medium'),
87-
'large' => format_date(time(), 'large'),
87+
'small' => format_date(REQUEST_TIME, 'short'),
88+
'medium' => format_date(REQUEST_TIME, 'medium'),
89+
'large' => format_date(REQUEST_TIME, 'long'),
8890
),
8991
'#process' => array('views_process_dependency'),
9092
'#dependency' => array(),
@@ -187,9 +189,9 @@ class flot_handler_field_datapoint extends views_handler_field {
187189
foreach ($filters as $filter => $handler) {
188190
if (strpos(get_class($handler), '_date') !== FALSE) {
189191
$min = $handler->value['min'];
190-
$min = !is_numeric($min) ? time() + intval(strtotime($min, 0)) : $min;
192+
$min = !is_numeric($min) ? REQUEST_TIME + intval(strtotime($min, 0)) : $min;
191193
$max = $handler->value['max'];
192-
$max = !is_numeric($max) ? time() + intval(strtotime($max, 0)) : $max;
194+
$max = !is_numeric($max) ? REQUEST_TIME + intval(strtotime($max, 0)) : $max;
193195
$value = intval(strtotime($handler->value['value'], 0));
194196
switch ($handler->operator) {
195197
case 'between':

views/flot_views_plugin_style.inc

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class flot_views_plugin_style extends views_plugin_style {
2929

3030
// Generate label fields
3131
$label_options = array(
32-
'' => '< '. t('No labels') .' >',
32+
'' => '< ' . t('No labels') . ' >',
3333
'default' => t('Default (from data points)'),
3434
);
3535

@@ -53,13 +53,13 @@ class flot_views_plugin_style extends views_plugin_style {
5353
);
5454
$form['x']['label'] = array(
5555
'#type' => 'select',
56-
'#options'=> $label_options,
56+
'#options' => $label_options,
5757
'#title' => t('Labels'),
5858
'#default_value' => $this->options['x']['label'],
5959
);
6060
$form['x']['granularity'] = array(
6161
'#type' => 'select',
62-
'#options'=> $xaxis_granularity,
62+
'#options' => $xaxis_granularity,
6363
'#title' => t('Granularity'),
6464
'#default_value' => $this->options['x']['granularity'],
6565
);
@@ -73,13 +73,13 @@ class flot_views_plugin_style extends views_plugin_style {
7373
);
7474
$form['y']['label'] = array(
7575
'#type' => 'select',
76-
'#options'=> $label_options,
76+
'#options' => $label_options,
7777
'#title' => t('Labels'),
7878
'#default_value' => $this->options['y']['label'],
7979
);
8080
$form['y']['granularity'] = array(
8181
'#type' => 'select',
82-
'#options'=> $yaxis_granularity,
82+
'#options' => $yaxis_granularity,
8383
'#title' => t('Granularity'),
8484
'#default_value' => $this->options['y']['granularity'],
8585
);
@@ -221,7 +221,7 @@ class flot_views_plugin_style extends views_plugin_style {
221221

222222
// Parameters
223223
$type = !empty($options['type']) ? $options['type'] : 'line';
224-
$size = !empty($options['size']) ? explode('x', $options['size']) : array('200','100');
224+
$size = !empty($options['size']) ? explode('x', $options['size']) : array('200', '100');
225225

226226
// DOM element options
227227
$element = array();

views/flot_views_plugin_summary_style.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class flot_views_plugin_summary_style extends flot_views_plugin_style {
1111

1212
// Parameters
1313
$type = !empty($options['type']) ? $options['type'] : 'line';
14-
$size = !empty($options['size']) ? explode('x', $options['size']) : array('200','100');
14+
$size = !empty($options['size']) ? explode('x', $options['size']) : array('200', '100');
1515
$reverse = !empty($options['reverse']) ? $options['reverse'] : 1;
1616
$pad_y = !empty($options['pad_y']) ? $options['pad_y'] : 1;
1717

@@ -71,7 +71,7 @@ class flot_views_plugin_summary_style extends flot_views_plugin_style {
7171
// If max is too small Flot barfs -- set a minimum value
7272
$range['max'] = ($range['max'] < 5) ? 5 : $range['max'];
7373

74-
// Pad Y axis if necessary
74+
// Pad Y axis if necessary
7575
if ($pad_y) {
7676
$range['min'] = 0;
7777
$range['max'] = floor($range['max'] + ($range['max'] * .1));

0 commit comments

Comments
 (0)