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

Internals:

* Better merging between the default settings and the chart data.
* $settings['#series_attributes'] now stores all attributes that should be merged to series instead the main chart array.
* Color values are now transmitted with the # sign
parent 58f8435d
No related branches found
No related tags found
No related merge requests found
...@@ -18,54 +18,36 @@ ...@@ -18,54 +18,36 @@
*/ */
function _charts_chart(&$data) { function _charts_chart(&$data) {
// Get the previously saved data from database // Get the previously saved data from database
$data = $data + _charts_settings(); $settings = _charts_settings();
if (empty($data['#plugin']) and empty($default['#plugin'])) {
return '';
}
// Split the color palette data into inidividual values
$color_palette = explode(',', ereg_replace('#', '', $default['#color_palette']));
// Check if the Chart will use the color palette for individual values // Check if the Chart will use the color palette for individual values
// instead for series, like Pie Charts // instead for series, like Pie charts
$options = array('pie2D' => TRUE, 'pie3D' => TRUE); $options = array('pie2D' => TRUE, 'pie3D' => TRUE);
if ((!empty($data['#type']) and !empty($options[$data['#type']]) ) or if ((!empty($data['#type']) and !empty($options[$data['#type']])) or !empty($options[$settings['#type']])) {
(!empty($default['#type']) and !empty($options[$default['#type']]) ) ) { $invert_attributes = TRUE;
$individual_color_palette = TRUE;
} }
// Merge all series option to the main data array, // Merge deafult series attributes with data
foreach (element_children($data) as $series) { foreach (element_children($data) as $series) {
if (!empty($default[$series])) { foreach (element_children($data[$series]) as $value) {
$data[$series] = array_merge($default[$series], $data[$series]); if (!is_array($data[$series][$value])) {
} $data[$series][$value] = array(
unset($default[$series]); '#value' => $data[$series][$value]
);
// 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($invert_attributes)) {
if (empty($individual_color_palette) and empty($data[$series]['#color'])) { _chart_series_attributes($data[$series][$value], $value, $settings);
$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];
}
} }
} }
if (empty($invert_attributes)) {
_chart_series_attributes($data[$series], $series, $settings);
}
} }
$data += $settings;
// Get the information about chart modules if (!empty($data['#plugin'])
$chart_provider = module_invoke_all('charts_info'); and $chart_provider = module_invoke_all('charts_info')
and isset($chart_provider[$data['#plugin']]['file'])
if (isset($chart_provider[$data['#plugin']]['file'])
and is_file($chart_provider[$data['#plugin']]['file']) and is_file($chart_provider[$data['#plugin']]['file'])
and $func = $chart_provider[$data['#plugin']]['render']) { and $func = $chart_provider[$data['#plugin']]['render']) {
...@@ -78,6 +60,15 @@ function _charts_chart(&$data) { ...@@ -78,6 +60,15 @@ function _charts_chart(&$data) {
return ''; return '';
} }
/**
* Merge the default series attributes with the actual data.
*/
function _chart_series_attributes(&$data, &$value, &$settings) {
foreach ($settings['#series_attributes'] as $attribute) {
$data[$attribute] = $settings[$attribute][$value];
}
}
/** /**
* Module settings page. Users can set the default layout * Module settings page. Users can set the default layout
* of their charts. * of their charts.
...@@ -123,6 +114,7 @@ function _charts_settings() { ...@@ -123,6 +114,7 @@ function _charts_settings() {
$default['#color'] = explode( ',', $default['#color_palette']); $default['#color'] = explode( ',', $default['#color_palette']);
$default['#color']['background'] = array_shift($default['#color']); $default['#color']['background'] = array_shift($default['#color']);
$default['#color']['text'] = array_shift($default['#color']); $default['#color']['text'] = array_shift($default['#color']);
$default['#series_attributes'][] = '#color';
} }
return $default; return $default;
......
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