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

Improvements:

* Both FusionCharts and OpenFlashCharts removed. Because they never worked correctly, its far better to add them later, with better implementations
parent ce1fe636
No related branches found
No related tags found
No related merge requests found
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use FusionCharts on your site.
*/
/**
* Create the values object using FusionCharts
*
* @param $type
* String. The data type. It can be 'category', 'set' or 'trendline'
* @param $data
* Array. The data to be converted to XML
* @param $options
* Array (optional). Data options
* @return
* Array, the XML array
*/
function _fusioncharts_values($type, $data, $options = array()) {
switch ($type) {
case 'category':
$attr = 'label';
$global_type = 'categories';
break;
case 'set':
$attr = 'value';
$global_type = 'dataSet';
break;
case 'trendline':
$attr = 'value';
$global_type = 'trendlines';
break;
}
// Create each value.
$values = array();
while (list(, $value) = each($data)) {
if (is_array($value)) {
$values[] = array('key' => $type, 'attributes' => $value);
}
else {
$values[] = array('key' => $type, 'attributes' => array($attr => $value));
}
}
// Create the XML array
if (empty($options['no_wrap'])) {
return array(
'key' => $global_type,
'value' => $values,
'attributes' => $options
);
}
else {
return $values;
}
}
/**
* Convert all Chart-level data.
*
* @param &$chart
* Array. The array that will be converted into a string for FusionCharts
* @param &$data
* Array. The raw data.
* @return
* String. The string presentation of series data
*/
function _fusioncharts_chart(&$chart, &$data) {
$chart['attributes']['bgColor'] = $data['#color']['background'];
if (isset($data['#title'])) {
$chart['attributes']['caption'] = $data['#title'];
}
$chart['attributes']['animation'] = '0';
}
/**
* Implementation of hook_charts_render().
*
* Its a Charts module hook. It transform the data into a HTML chart.
*
* @param &$data
* Array. The
*/
function _fusioncharts_charts_render(&$data) {
// Convert the chat TYPE into the FusionCharts way.
// Since its a requirement to build the chart on Google, if the value
// was not found, return nothing and stop the execution.
$options = array(
'line2D' => 'MSLine.swf',
'hbar2D' => 'MSBar2D.swf',
'hbar3D' => 'MSBar3D.swf',
'vbar2D' => 'MSColumn2D.swf',
'vbar3D' => 'MSColumn3D.swf',
'pie2D' => 'Pie2D.swf',
'pie3D' => 'Pie3D.swf',
);
if (empty($options[$data['#type']])) {
return t('This type is not possible using %chartplugin',
array('%chartplugin' => 'FusionCharts'));
}
$file = file_create_url('fusioncharts') .'/'. $options[$data['#type']];
// Convert the chat SIZE into the FusionCharts way.
// Since its a requirement to build the chart on Google, if the value
// was not found, return nothing and stop the execution.
if (empty($data['#width']) or empty($data['#height'])) {
return '';
}
$width = $data['#width'];
$height = $data['#height'];
$chart = array(
'key' => 'chart',
'value' => array()
);
if ($message = _fusioncharts_chart($chart, $data)) {
return $message;
}
$series = '_fusioncharts_series';
if ($data['#type'] == 'pie2D' or $data['#type'] == 'pie3D') {
$series = '_fusioncharts_series_single';
}
if ($message = $series($chart, $data)) {
return $message;
}
$chart = '&dataXML='. str_replace('"', "'", format_xml_elements(array($chart)));
// Its the HTML tag to include the chart
return <<<FUSIONCHARTS
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="$width" height="$height">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="$file" />
<param name="FlashVars" value="&chartWidth=$width&chartHeight=$height$chart" />
<param name="quality" value="high" />
<embed src="$file" flashVars="&chartWidth=$width&chartHeight=$height$chart" width="$width" height="$height" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
FUSIONCHARTS;
}
/**
* Convert all Series-level data.
*
* @param &$chart
* Array. The array that will be converted into a string for FusionCharts
* @param &$data
* Array. The raw data.
* @return
* String. The string presentation of series data
*/
function _fusioncharts_series(&$chart, &$data) {
// Convert the chat DATA into the FusionCharts way.
// Since its a requirement to build the chart on FusionCharts, if the value
// was not found, return nothing and stop the execution.
foreach (element_children($data) as $series) {
$series_data = array();
foreach (element_children($data[$series]) as $values) {
$serie_data = array(
'value' => $data[$series][$values]['#value']
);
if (isset($data[$series][$values]['#label'])) {
$serie_data['label'] = $data[$series][$values]['#label'];
}
$series_data[] = $serie_data;
}
if (isset($data['#color'][$series])) {
$options['color'] = substr($data['#color'][$series], 1);
}
$chart['value'][] = _fusioncharts_values('set', $series_data, $options);
foreach (element_children($data[$series]) as $values) {
$value_labels_temp[] = empty($data[$series][$value]['#label']) ? NULL : $data[$series][$value]['#label'];
}
// X labels
$value_labels = array();
$toogle = FALSE;
foreach (array_keys($series_data) as $value) {
if (empty($data[$series][$value]['#label'])) {
$value_labels[] = '';
$toogle = TRUE;
}
else {
$value_labels[] = $data[$series][$value]['#label'];
$toogle = TRUE;
}
}
if (!empty($toogle) and empty($chart['categories'])) {
$chart['value'][] = _fusioncharts_values('category', $value_labels);
$chart['categories'] = TRUE;
}
}
}
/**
* Convert all Series-level data.
*
* @param &$chart
* Array. The array that will be converted into a string for FusionCharts
* @param &$data
* Array. The raw data.
* @return
* String. The string presentation of series data
*/
function _fusioncharts_series_single(&$chart, &$data) {
// Convert the chat DATA into the FusionCharts way.
// Since its a requirement to build the chart on FusionCharts, if the value
// was not found, return nothing and stop the execution.
foreach (element_children($data) as $series) {
if (!empty($toogle)) {
continue;
}
$toogle = TRUE;
foreach (element_children($data[$series]) as $values) {
$value_labels_temp[] = empty($data[$series][$value]['#label']) ? NULL : $data[$series][$value]['#label'];
if (is_array($data[$series][$values])) {
$series_data[] = array(
'value' => $data[$series][$values]['#value'],
'label' => $data[$series][$values]['#label'],
'color' => trim($data['#color'][$values])
);
}
else {
$series_data[] = array(
'value' => $data[$series][$values],
);
}
}
$options['no_wrap'] = TRUE;
$options['label'] = TRUE;
foreach (_fusioncharts_values('set', $series_data, $options) as $set) {
$chart['value'][] = $set;
}
// X labels
$value_labels = array();
$toogle = FALSE;
foreach (array_keys($series_data) as $value) {
if (empty($data[$series][$value]['#label'])) {
$value_labels[] = '';
}
else {
$value_labels[] = $data[$series][$value]['#label'];
$toogle = TRUE;
}
}
if (!empty($toogle)) {
$chart['value'][] = _fusioncharts_values('category', $value_labels);
}
}
}
; $Id$
core = "6.x"
dependencies[] = charts
description = "Use FusionCharts on your site."
name = "FusionCharts"
package = "Charts"
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Install and unistall functions for this module
*/
/**
* Implementation of hook_requirements().
*/
function fusioncharts_requirements($phase) {
$path = file_create_path() .'/fusioncharts';
if (!file_exists($path .'/MSLine.swf')) {
$requirements['charts']['title'] = t('FusionCharts');
$requirements['charts']['value'] = t('FusionCharts flash files not installed');
$requirements['charts']['severity'] = REQUIREMENT_ERROR;
$requirements['charts']['description'] = t('Put all flash files inside %dir.', array('%dir' => $path));
return $requirements;
}
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use FusionCharts on your site.
*
* @note only hooks are here.
*/
/**
* Immplementation of hook_charts_info().
*
* 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 fusioncharts_charts_info() {
return array(
'fusioncharts' => array(
'file' => drupal_get_path('module', 'fusioncharts') .'/fusioncharts.inc',
'name' => t('FusionCharts'),
'render' => '_fusioncharts_charts_render',
'types' => array('line2D', 'hbar2D', 'hbar3D', 'vbar2D', 'vbar3D', 'pie2D', 'pie3D'),
),
);
}
/**
* Immplementation of hook_chart_types().
*/
function fusioncharts_chart_types() {
return array(
'hbar3D' => t('Horizontal Bar 3D'),
'vbar3D' => t('Vertical Bar 3D'),
);
}
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use Open Flash Chart on your site.
*/
/**
* Convert all Chart-level data.
*
* @param &$chart
* Object. The Open Flash Chart object
* @param &$data
* Array. The raw data.
*/
function _openflashchart_chart(&$chart, &$data) {
$chart->set_title($data['#title']);
$chart->set_width($data['#width']);
$chart->set_height($data['#height']);
$chart->set_bg_colour($data['#color']['#background']);
}
/**
* Implementation of hook_charts_render().
*
* Its a Charts module hook. It transform the data into a HTML chart.
*
* @param &$data
* Array. The
*/
function _openflashchart_charts_render(&$data) {
$chart = new open_flash_chart_api();
if ($error = _openflashchart_chart($chart, $data)) {
return $error;
}
if ($error = _openflashchart_series($chart, $data)) {
return $error;
}
return $chart->render();
}
/**
* Convert all Series-level data.
*
* @param &$chart
* Object. The Open Flash Chart object
* @param &$data
* Array. The raw data.
*/
function _openflashchart_series(&$chart, &$data) {
foreach (element_children($data) as $series) {
// Get the color
$color = empty($data[$series]['#color']) ? '' : $data[$series]['#color'];
switch ($data['#type']) {
case 'line2D':
$chart->line(1, $color);
break;
case 'vbar2D':
$chart->bar(75, $color);
break;
case 'vbar3D':
$chart->bar_3D(75, $color);
break;
case 'pie2D':
$chart->pie(75, '#000000', 'font-size: 12px;');
break;
default:
return t('This type is not possible using %chartplugin',
array('%chartplugin' => 'Open Flash Chart'));
}
// Insert a new series of values
if ($data['#type'] != 'pie2D') {
_openflashchart_series_generic($chart, $data, $series);
}
elseif (empty($series)) {
_openflashchart_series_pie($chart, $data, $series);
}
}
}
function _openflashchart_series_generic(&$chart, &$data, $series) {
static $max;
// Get only the numeric values from the series
$series_data = _charts_series_values($data[$series]);
$chart->set_data($series_data);
// Get the highest value on the series, to be a reference point
$max = $max < max($series_data) ? max($series_data) : $max;
// Y labels
$chart->set_y_max($max);
// X labels
$value_labels = array();
$toogle = FALSE;
foreach (array_keys($series_data) as $value) {
if (empty($data[$series][$value]['#label'])) {
$value_labels[] = '';
}
else {
$value_labels[] = $data[$series][$value]['#label'];
$toogle = TRUE;
}
}
if (!empty($toogle)) {
$chart->set_x_labels($value_labels);
}
}
function _openflashchart_series_pie(&$chart, &$data, $series) {
// Get only the numeric values from the series
$series_data = _charts_series_values($data[$series]);
if (empty($series)) {
// Pieces labels
$value_labels = array();
foreach (array_keys($series_data) as $value) {
if (empty($data[$series][$value]['#label'])) {
$value_labels[] = '';
}
else {
$value_labels[] = $data[$series][$value]['#label'];
}
$color[] = $data[$series][$value]['#color'];
}
$chart->pie_values($series_data, $value_labels, array());
$chart->pie_slice_colours($color);
}
}
; $Id$
core = "6.x"
dependencies[] = charts
dependencies[] = open_flash_chart_api
description = "Use Open Flash Charts on your site."
name = "Open Flash Chart"
package = "Charts"
<?php
// $Id$
/**
* @author Bruno Massa http://drupal.org/user/67164
* @file
* Use Open Flash Chart on your site.
*
* @note only hooks are here.
*/
/**
* Immplementation of hook_charts_info().
*
* 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 openflashchart_charts_info() {
return array(
'openflashchart' => array(
'file' => drupal_get_path('module', 'openflashchart') .'/openflashchart.inc',
'name' => t('Open Flash Chart'),
'render' => '_openflashchart_charts_render',
'types' => array('line2D', 'vbar2D', 'vbar3D', 'pie2D'),
),
);
}
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