function template_preprocess_visualization in Visualization API 7
Same name and namespace in other branches
- 8 visualization.theme.inc \template_preprocess_visualization()
Preprocess function for visualization function.
Used by both regular calls to theme() and the visualization Views handler.
File
- theme/
visualization.theme.inc, line 12 - Theme file for the visualization part of the module.
Code
function template_preprocess_visualization(&$vars) {
$options = $vars['options'];
drupal_add_library('visualization', 'visualization');
if (!empty($vars['view'])) {
$view = $vars['view'];
// Fields.
foreach ($view->field as $name => $field) {
$options['fields'][$name]['label'] = $field->options['label'];
}
// Data.
$data = $view->style_plugin->rendered_fields;
}
else {
$data = $options['data'];
}
if (!empty($options['xAxis']['invert'])) {
$data = array_reverse($data);
}
$chart_id = 'visualization_' . uniqid();
$plugin = visualization_plugin($options['type']);
$vars['chart'] = $plugin['handler']
->render($chart_id, $data, $options);
$vars['chart_attributes'] = drupal_attributes(array(
'id' => $chart_id,
'class' => array(
'visualization-chart',
'visualization-chart-' . $plugin['name'],
),
));
$plugin['handler']
->postRender();
}