From 63faa7d9ceddd37b730d2fc580d84e97cb20a284 Mon Sep 17 00:00:00 2001 From: Bruno Massa <brmassa@67164.no-reply.drupal.org> Date: Fri, 15 May 2009 03:33:31 +0000 Subject: [PATCH] Internals: * Views integration now works after the internal data modification --- charts.admin.inc | 70 ++++++++++++++++------------- views/charts_plugin_style_chart.inc | 30 ++++++++----- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/charts.admin.inc b/charts.admin.inc index b8143ca..dbde71d 100644 --- a/charts.admin.inc +++ b/charts.admin.inc @@ -21,28 +21,30 @@ function _charts_color_form_complete(&$form, $default) { '#title' => t('Color'), '#tree' => TRUE ); - $form['color']['color_palettes'] = array( + $form['color']['color_palette'] = array( '#type' => 'select', '#title' => t('Color palettes'), '#options' => $default['#color_palettes'], '#default_value' => $default['#color_palette'], ); $form['color']['background'] = array( - '#type' => $field_type, - '#title' => t('Background'), - '#default_value' => $default['#color']['background'], // '#colorpicker' => 'colorpicker', + '#default_value' => $default['#color']['background'], + '#title' => t('Background'), + '#type' => $field_type, ); $form['color']['text'] = array( - '#type' => $field_type, - '#title' => t('Text'), '#default_value' => $default['#color']['text'], + '#required' => TRUE, + '#title' => t('Text'), + '#type' => $field_type, ); for ($series = 0; $series < 8; $series++) { $form['color'][$series] = array( - '#type' => $field_type, - '#title' => t('Series %serie', array('%serie' => $series + 1)), '#default_value' => $default['#color'][$series], + '#required' => TRUE, + '#title' => t('Series %serie', array('%serie' => $series + 1)), + '#type' => $field_type, ); } @@ -57,11 +59,12 @@ function _charts_color_form_complete(&$form, $default) { */ function _charts_color_form_simple(&$form, $settings) { // Load some color palettes - $form['color_palettes'] = array( - '#type' => 'select', - '#title' => t('Color palettes'), - '#options' => $settings['#color_palettes'], + $form['color_palette'] = array( '#default_value' => $settings['#color_palette'], + '#options' => $settings['#color_palettes'], + '#required' => TRUE, + '#title' => t('Color palettes'), + '#type' => 'select', ); } @@ -74,25 +77,24 @@ function _charts_color_form_simple(&$form, $settings) { * HTML. The generic Chart example */ function _charts_example() { -// if (empty($data)) { - // This will hold the example chart - // Since the chart is an example, we should provide - // and example data. - $data[] = array( - '#legend' => 'Profit', - array('#value' => 35, '#label' => t('Jan')), - array('#value' => 25, '#label' => t('Feb')), - array('#value' => 75, '#label' => t('Mar')), - array('#value' => 50, '#label' => t('Apr')), - array('#value' => 23, '#label' => t('May')), - array('#value' => 12, '#label' => t('Jun')), - ); - $data[] = array( - '#legend' => 'Revenue', - 10, 20, 55, 72, 45, 50 - ); - $data['#title'] = 'Testing Chart'; -// } + // This will hold the example chart + // Since the chart is an example, we should provide + // and example data. + $data[] = array( + '#legend' => 'Profit', + array('#value' => 35, '#label' => t('Jan')), + array('#value' => 25, '#label' => t('Feb')), + array('#value' => 75, '#label' => t('Mar')), + array('#value' => 50, '#label' => t('Apr')), + array('#value' => 23, '#label' => t('May')), + array('#value' => 12, '#label' => t('Jun')), + ); + $data[] = array( + '#legend' => 'Revenue', + 10, 20, 55, 72, 45, 50 + ); + $data['#title'] = 'Testing Chart'; + return charts_chart($data); } @@ -143,6 +145,7 @@ function _charts_settings_form(&$form, $default = array(), $options = array()) { $form['plugin'] = array( '#default_value' => $default['#plugin'], '#options' => $default['#plugins'], + '#required' => TRUE, '#type' => 'select', '#title' => t('Chart plugin'), ); @@ -151,6 +154,7 @@ function _charts_settings_form(&$form, $default = array(), $options = array()) { $form['type'] = array( '#default_value' => $default['#type'], '#options' => $default['#types'], + '#required' => TRUE, '#type' => 'radios', '#title' => t('Chart type'), ); @@ -158,6 +162,7 @@ function _charts_settings_form(&$form, $default = array(), $options = array()) { $form['width'] = array( '#default_value' => $default['#width'], '#description' => t('The chart width, in pixels'), + '#required' => TRUE, '#size' => 8, '#type' => 'textfield', '#title' => t('Width'), @@ -165,6 +170,7 @@ function _charts_settings_form(&$form, $default = array(), $options = array()) { $form['height'] = array( '#default_value' => $default['#height'], '#description' => t('The chart height, in pixels'), + '#required' => TRUE, '#size' => 8, '#type' => 'textfield', '#title' => t('Height'), @@ -215,7 +221,7 @@ function _charts_settings_page_submit(&$form, &$form_state) { unset($settings['op']); // Unwanted values - unset($settings['color']['color_palettes']); + unset($settings['color']['color_palette']); // Include a # sign in all attributes, because it will make the // merge between the chart data and the defaults easier on every diff --git a/views/charts_plugin_style_chart.inc b/views/charts_plugin_style_chart.inc index 9bd1466..a49af12 100644 --- a/views/charts_plugin_style_chart.inc +++ b/views/charts_plugin_style_chart.inc @@ -35,7 +35,8 @@ class charts_plugin_style_chart extends views_plugin_style { // Add the Chart Settings form module_load_include('admin.inc', 'charts'); - $form['charts']['#tree'] = TRUE; + + // Get chart settings from options form. _charts_settings_form($form['charts'], $this->options['charts']); $form['show_legend'] = array( @@ -48,7 +49,7 @@ class charts_plugin_style_chart extends views_plugin_style { // Views Calc related fields $form['aggregation_field'] = array( '#type' => 'select', - '#title' => t('Aggregation field'), + '#title' => t('Legend field'), '#options' => $this->aggregated_field_options(), '#default_value' => $this->options['aggregation_field'], '#description' => t('Select a field to aggreagate the results on.') @@ -57,25 +58,36 @@ class charts_plugin_style_chart extends views_plugin_style { // update Multiple to TRUE if that changes. $form['calc_fields'] = array( '#type' => 'select', - '#title' => t('Computation field'), + '#title' => t('Operation field'), '#options' => $this->aggregated_field_options(), '#default_value' => $this->calc_fields(), '#multiple' => FALSE, '#description' => t('Select field to perform computations on.') - ); + ); $form['calc'] = array( '#type' => 'select', - '#title' => t('Computation to perform'), + '#title' => t('Operation'), '#options' => $this->calc_options(), '#default_value' => $this->options['calc'], - ); + ); $form['precision'] = array( '#type' => 'select', '#title' => t('Precision'), '#options' => range(0, 4), '#default_value' => $this->options['precision'], '#description' => t('Decimal points to use in computed values.'), - ); + ); + } + + /** + * Generate a form for setting options. + */ + function options_submit(&$form, &$form_state) { + $chart = &$form_state['values']['style_options']['charts']; + foreach (element_children($chart) as $index) { + $chart['#'. $index] = $chart[$index]; + unset($chart[$index]); + } } /** @@ -122,9 +134,7 @@ class charts_plugin_style_chart extends views_plugin_style { */ function render() { // Get chart settings from options form. - foreach ($this->options['charts'] as $index => $value) { - $chart['#'. $index] = $value; - } + $chart = $this->options['charts']; // Get values from rows. foreach ($this->calc_fields() as $calc) { -- GitLab