Skip to content
Snippets Groups Projects
Commit d17ea1c2 authored by Bruno Massa's avatar Bruno Massa
Browse files

Misc:

* Converting all files to UNIX end-of-file
parent 488a027f
No related branches found
No related tags found
No related merge requests found
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Transform DATA into INFORMATION using beautiful CHARTS.
*
* @note only hooks are here.
* @note For instructions about the API, see chart_api.txt file.
*/
/**
* The main Chart API function, that calls any chart provider
* to print the given data.
*
* @param &$data
* Array. The chart data, described on chart_api.txt
* @return
* String. The HTML with the propper chart (might include Flash or
* JavaScript external files)
*/
function charts_chart(&$data) {
// Get the previously saved data from database
$settings = variable_get('charts_settings', array());
// Split the color palette data into inidividual values
$color_palette = explode(',', ereg_replace('#', '', $settings['#color_palette']));
// Check if the Chart will use the color palette for individual values
// instead for series, like Pie Charts
$options = array('pie2D' => TRUE, 'pie3D' => TRUE);
if ((!empty($data['#type']) and !empty($options[$data['#type']]) ) or
(!empty($settings['#type']) and !empty($options[$settings['#type']]) ) ) {
$individual_color_palette = TRUE;
}
// Merge all series option to the main data array,
foreach (element_children($data) as $series) {
if (!empty($settings[$series])) {
$data[$series] = array_merge($settings[$series], $data[$series]);
}
unset($settings[$series]);
// Apply the Color Palette: normally, apply one color to each series.
// But for some types of charts, is one color to each value into the series
if (empty($individual_color_palette) and empty($data[$series]['#color'])) {
$data[$series]['#color'] = $color_palette[$series];
}
elseif (!empty($individual_color_palette)) {
foreach (element_children($data[$series]) as $values) {
if (!is_array($data[$series][$values])) {
$data[$series][$values] = array(
'#value' => $data[$series][$values],
'#color' => $color_palette[$values],
);
}
elseif (empty($data[$series][$values]['#color'])) {
$data[$series][$values]['#color'] = $color_palette[$values];
}
}
}
}
// Now, merge all the rest of the options saved by default
$data = array_merge($settings, $data);
$chart_provider = $data['#plugin'] .'_chartsapi';
if (function_exists($chart_provider)) {
return $chart_provider($data);
}
}
/**
* Implementation of hook_menu().
*/
function charts_menu() {
$items['admin/settings/charts'] = array(
'access arguments' => array('access administration pages'),
'description' => 'Set the default behaviour and look of all your charts',
'file' => 'charts.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('_charts_settings'),
'title' => 'Charts'
);
$items['admin/settings/charts/example'] = array(
'access arguments' => array('access content'),
'file' => 'charts.inc',
'page callback' => '_charts_example',
'title' => 'Example',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_requirements().
*/
function charts_requirements($phase) {
if ($phase == 'runtime' and !$modules = module_invoke_all('chartsinfo', 'list')) {
$requirements['charts']['title'] = t('Charts');
$requirements['charts']['value'] = t('No Charts provider installed');
$requirements['charts']['severity'] = REQUIREMENT_ERROR;
$requirements['charts']['description'] = t('Charts core module only provides a a common set of functions. You must install a Charts provider module to create charts.');
return $requirements;
}
}
/**
* Even if the series have values with attributes,
* return only the numeric values of them.
*
* @param
* Array. A given data series with or without attributes.
* @return
* Array. A data series, but only with the values, without
* the attributes.
*/
function _charts_series_values($series) {
$data = array();
foreach ($series as $index => $value) {
if (!is_numeric($index)) {
continue;
}
if (is_array($value)) {
$data[] = $value['#value'];
}
else {
$data[] = $value;
}
}
return $data;
}
/**
* Implementation of hook_theme().
*/
function charts_theme() {
return array(
'_charts_settings' => array(
'arguments' => array('form' => NULL),
),
);
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Transform DATA into INFORMATION using beautiful CHARTS.
*
* @note only hooks are here.
* @note For instructions about the API, see chart_api.txt file.
*/
/**
* The main Chart API function, that calls any chart provider
* to print the given data.
*
* @param &$data
* Array. The chart data, described on chart_api.txt
* @return
* String. The HTML with the propper chart (might include Flash or
* JavaScript external files)
*/
function charts_chart(&$data) {
// Get the previously saved data from database
$settings = variable_get('charts_settings', array());
// Split the color palette data into inidividual values
$color_palette = explode(',', ereg_replace('#', '', $settings['#color_palette']));
// Check if the Chart will use the color palette for individual values
// instead for series, like Pie Charts
$options = array('pie2D' => TRUE, 'pie3D' => TRUE);
if ((!empty($data['#type']) and !empty($options[$data['#type']]) ) or
(!empty($settings['#type']) and !empty($options[$settings['#type']]) ) ) {
$individual_color_palette = TRUE;
}
// Merge all series option to the main data array,
foreach (element_children($data) as $series) {
if (!empty($settings[$series])) {
$data[$series] = array_merge($settings[$series], $data[$series]);
}
unset($settings[$series]);
// Apply the Color Palette: normally, apply one color to each series.
// But for some types of charts, is one color to each value into the series
if (empty($individual_color_palette) and empty($data[$series]['#color'])) {
$data[$series]['#color'] = $color_palette[$series];
}
elseif (!empty($individual_color_palette)) {
foreach (element_children($data[$series]) as $values) {
if (!is_array($data[$series][$values])) {
$data[$series][$values] = array(
'#value' => $data[$series][$values],
'#color' => $color_palette[$values],
);
}
elseif (empty($data[$series][$values]['#color'])) {
$data[$series][$values]['#color'] = $color_palette[$values];
}
}
}
}
// Now, merge all the rest of the options saved by default
$data = array_merge($settings, $data);
$chart_provider = $data['#plugin'] .'_chartsapi';
if (function_exists($chart_provider)) {
return $chart_provider($data);
}
}
/**
* Implementation of hook_menu().
*/
function charts_menu() {
$items['admin/settings/charts'] = array(
'access arguments' => array('access administration pages'),
'description' => 'Set the default behaviour and look of all your charts',
'file' => 'charts.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('_charts_settings'),
'title' => 'Charts'
);
$items['admin/settings/charts/example'] = array(
'access arguments' => array('access content'),
'file' => 'charts.inc',
'page callback' => '_charts_example',
'title' => 'Example',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_requirements().
*/
function charts_requirements($phase) {
if ($phase == 'runtime' and !$modules = module_invoke_all('chartsinfo', 'list')) {
$requirements['charts']['title'] = t('Charts');
$requirements['charts']['value'] = t('No Charts provider installed');
$requirements['charts']['severity'] = REQUIREMENT_ERROR;
$requirements['charts']['description'] = t('Charts core module only provides a a common set of functions. You must install a Charts provider module to create charts.');
return $requirements;
}
}
/**
* Even if the series have values with attributes,
* return only the numeric values of them.
*
* @param
* Array. A given data series with or without attributes.
* @return
* Array. A data series, but only with the values, without
* the attributes.
*/
function _charts_series_values($series) {
$data = array();
foreach ($series as $index => $value) {
if (!is_numeric($index)) {
continue;
}
if (is_array($value)) {
$data[] = $value['#value'];
}
else {
$data[] = $value;
}
}
return $data;
}
/**
* Implementation of hook_theme().
*/
function charts_theme() {
return array(
'_charts_settings' => array(
'arguments' => array('form' => NULL),
),
);
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use Charts for Drupal administration
*/
/**
* Implementation of hook_menu().
*/
function charts_system_menu() {
$items['admin/reports/charts'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('nodes'),
'title' => 'Charts'
);
$items['admin/reports/charts/nodes'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('nodes'),
'title' => 'Nodes',
'type' => MENU_DEFAULT_LOCAL_TASK
);
$items['admin/reports/charts/users'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('users'),
'title' => 'Users',
'type' => MENU_LOCAL_TASK
);
$items['admin/reports/charts/watchdog'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('watchdog'),
'title' => 'Watchdog',
'type' => MENU_LOCAL_TASK
);
return $items;
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use Charts for Drupal administration
*/
/**
* Implementation of hook_menu().
*/
function charts_system_menu() {
$items['admin/reports/charts'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('nodes'),
'title' => 'Charts'
);
$items['admin/reports/charts/nodes'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('nodes'),
'title' => 'Nodes',
'type' => MENU_DEFAULT_LOCAL_TASK
);
$items['admin/reports/charts/users'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('users'),
'title' => 'Users',
'type' => MENU_LOCAL_TASK
);
$items['admin/reports/charts/watchdog'] = array(
'access arguments' => array('access site reports'),
'file' => 'charts_system.inc',
'page callback' => '_charts_system_charts',
'page arguments' => array('watchdog'),
'title' => 'Watchdog',
'type' => MENU_LOCAL_TASK
);
return $items;
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use Google Charts on your site.
*
* @note only hooks are here.
*/
/**
* Immplementation of hook_chartsapi().
*
* Its a Charts module hook. It defines almost all aspects
* of a chart provider, like its name, what types of charts
* it can perform and what are the restrictions.
*/
function google_charts_chartsinfo($op) {
switch ($op) {
case 'list':
return array('google_charts' => 'Google Chart API');
case 'charttypes':
return array(
'line2D' => t('Line 2D'),
'hbar2D' => t('Horizontal Bar 2D'),
'vbar2D' => t('Vertical Bar 2D'),
'pie2D' => t('Pie 2D'),
'pie3D' => t('Pie 3D'),
'venn' => t('Venn'),
'scatter' => t('Scatter Plot'),
);
}
}
/**
* Immplementation of hook_chartsapi().
*
* Its a Charts module hook. It transform the data into a HTML chart.
*
* @param &$data
* Array. The
*/
function google_charts_chartsapi(&$data) {
// Include the specific Google Chart API helper functions
include_once drupal_get_path('module', 'google_charts') .'/google_charts.inc';
$chart = array();
if ($message = _google_charts_chart($chart, $data)) {
return $message;
}
// Convert the chat DATA into the Google Chart way.
// Since its a requirement to build the chart on Google, if the value
// was not found, return nothing and stop the execution.
if ($message = _google_charts_series($chart, $data)) {
return $message;
}
// If its all ok, build the HTML img tag
return '<img src="http://chart.apis.google.com/chart?'. implode('&amp;', $chart) .'" />';
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use Google Charts on your site.
*
* @note only hooks are here.
*/
/**
* Immplementation of hook_chartsapi().
*
* Its a Charts module hook. It defines almost all aspects
* of a chart provider, like its name, what types of charts
* it can perform and what are the restrictions.
*/
function google_charts_chartsinfo($op) {
switch ($op) {
case 'list':
return array('google_charts' => 'Google Chart API');
case 'charttypes':
return array(
'line2D' => t('Line 2D'),
'hbar2D' => t('Horizontal Bar 2D'),
'vbar2D' => t('Vertical Bar 2D'),
'pie2D' => t('Pie 2D'),
'pie3D' => t('Pie 3D'),
'venn' => t('Venn'),
'scatter' => t('Scatter Plot'),
);
}
}
/**
* Immplementation of hook_chartsapi().
*
* Its a Charts module hook. It transform the data into a HTML chart.
*
* @param &$data
* Array. The
*/
function google_charts_chartsapi(&$data) {
// Include the specific Google Chart API helper functions
include_once drupal_get_path('module', 'google_charts') .'/google_charts.inc';
$chart = array();
if ($message = _google_charts_chart($chart, $data)) {
return $message;
}
// Convert the chat DATA into the Google Chart way.
// Since its a requirement to build the chart on Google, if the value
// was not found, return nothing and stop the execution.
if ($message = _google_charts_series($chart, $data)) {
return $message;
}
// If its all ok, build the HTML img tag
return '<img src="http://chart.apis.google.com/chart?'. implode('&amp;', $chart) .'" />';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment