function _easychart_print_chart in Easychart 7.2
Same name and namespace in other branches
- 7.3 easychart.module \_easychart_print_chart()
- 7 easychart.module \_easychart_print_chart()
1 call to _easychart_print_chart()
- easychart_field_formatter_view in ./
easychart.module - Implements hook_field_formatter_view().
File
- ./
easychart.module, line 359 - Easychart module file.
Code
function _easychart_print_chart($item, $delta) {
global $chart_count;
$chart_count++;
$output = '';
if (!empty($item['config'])) {
if ($chart_count == 1) {
// Add the highcharts javascript.
libraries_load('highcharts');
libraries_load('easychart');
// Add the easychart javascript.
drupal_add_js(drupal_get_path('module', 'easychart') . '/js/easychart.js');
}
// Print a div and add inline javascript
$output = '<div class="easychart-chart-' . $chart_count . '">';
$output .= '</div>';
// Get the csv data.
if (!empty($item['csv_url'])) {
// check if url is relative
if (!preg_match("/^ht{2}ps?\\:\\/{2}/", $item['csv_url'])) {
// if so, prepend base-url
$url = url(NULL, array(
'absolute' => TRUE,
)) . $item['csv_url'];
}
else {
$url = $item['csv_url'];
}
$csv = file_get_contents($url);
// TODO: turn into array.
$csv = str_replace("\r\n", 'EC_EOL', $csv);
$csv = str_replace("\n", 'EC_EOL', $csv);
}
else {
if (!empty($item['csv'])) {
$csv = $item['csv'];
}
}
drupal_add_js('Drupal.behaviors.easyChart_' . $chart_count . ' = { attach: function() { if (jQuery(".easychart-chart-' . $chart_count . '").length > 0) { var options = ' . $item['config'] . '; options = _preprocessHighchartsData(options, \'' . $csv . '\'); jQuery(".easychart-chart-' . $chart_count . '").highcharts(options);}}};', array(
'type' => 'inline',
'scope' => 'footer',
));
}
return $output;
}