function flot_views_plugin_style::preprocess in Flot 6
Same name and namespace in other branches
- 7 flot_views/views/flot_views_plugin_style.inc \flot_views_plugin_style::preprocess()
Theme template preprocessor.
1 method overrides flot_views_plugin_style::preprocess()
- flot_views_plugin_summary_style::preprocess in views/
flot_views_plugin_summary_style.inc - Theme template preprocessor.
File
- views/
flot_views_plugin_style.inc, line 218
Class
Code
function preprocess(&$vars) {
$view = $this->view;
$options = $this->options;
// Parameters
$type = !empty($options['type']) ? $options['type'] : 'line';
$size = !empty($options['size']) ? explode('x', $options['size']) : array(
'200',
'100',
);
// DOM element options
$element = array();
$element['style'] = is_numeric($size[0]) ? "width:{$size[0]}px;" : "width:{$size[0]};";
$element['style'] .= is_numeric($size[1]) ? "height:{$size[1]}px;" : "height:{$size[1]};";
$vars['element'] = $element;
// Build layers.
$layers = $this
->get_layers();
$vars['data'] = $layers['series'];
$vars['titles'] = $layers['titles'];
$range = $layers['range'];
$ticks = $layers['ticks'];
// Set up the type class, set axes
switch ($options['type']) {
case 'point':
$style = new flotStylePoint();
break;
case 'bar':
$style = new flotStyleBar();
break;
case 'line':
default:
$style = new flotStyleLine();
break;
}
// Format Y Axis
$granularity = 0;
// If max is too small Flot barfs -- set a minimum value
$range['max'] = $range['max'] < 5 ? 5 : $range['max'];
// Pad Y axis if necessary
if ($options['y']['pad']) {
$range['min'] = 0;
$range['max'] = floor($range['max'] + $range['max'] * 0.1);
}
if (!empty($options['y']['label'])) {
switch ($options['y']['granularity']) {
case 'endpoints':
$yticks = array(
array(
$range['min'],
$range['min'],
),
array(
$range['max'],
$range['max'],
),
);
$style
->axis_ticks('yaxis', $yticks);
break;
case 'auto':
$style
->axis_range('yaxis', $range);
break;
default:
$style
->axis_range('yaxis', $range, $options['y']['granularity']);
break;
}
}
else {
$style->yaxis->ticks = array();
}
if (count($ticks) > 1 && !empty($options['x']['label'])) {
$domain = array(
reset($ticks),
end($ticks),
);
switch ($options['x']['granularity']) {
case 'endpoints':
$style
->axis_ticks('xaxis', $domain);
break;
case 'auto':
$style
->axis_ticks('xaxis', $ticks);
break;
default:
$domain_range = array(
$domain[0][0],
$domain[1][0],
);
$style
->axis_range('xaxis', $domain_range, $options['x']['granularity']);
break;
}
}
else {
$style->xaxis->ticks = array();
}
$vars['options'] = $style;
}