From 78d6fcfd0dcbfcfc32492b4a1f3f77887037a1e3 Mon Sep 17 00:00:00 2001 From: Daniel Cothran <daniel@andile.co> Date: Mon, 25 Dec 2017 03:41:13 -0500 Subject: [PATCH] Issue #2879533 by lbaran: Improve Charts code documentation --- charts.api.php | 18 +++--- includes/charts.pages.inc | 63 ++++++++----------- modules/charts_c3/charts_c3.module | 4 +- .../charts_c3/src/Charts/C3ChartsRender.php | 7 --- .../src/Plugin/chart/CThreeCharts.php | 8 --- .../src/Settings/Google/ChartAxes.php | 2 +- .../src/Settings/Google/GoogleOptions.php | 3 +- .../src/Charts/HighchartsChartsRender.php | 2 +- .../src/Plugin/chart/Highchart.php | 2 +- src/Plugin/chart/ChartInterface.php | 3 +- src/Plugin/chart/ChartManager.php | 2 + src/Util/Util.php | 5 +- 12 files changed, 46 insertions(+), 73 deletions(-) diff --git a/charts.api.php b/charts.api.php index d9caeab..593b6ad 100644 --- a/charts.api.php +++ b/charts.api.php @@ -57,9 +57,9 @@ use Drupal\charts\Theme\ChartsInterface; /** * Alter an individual chart before it is printed. * - * @param $chart + * @param mixed $chart * The chart renderable. Passed in by reference. - * @param $chart_id + * @param mixed $chart_id * The chart identifier, pulled from the $chart['#chart_id'] property (if * any). Not all charts have a chart identifier. */ @@ -76,10 +76,10 @@ function hook_chart_alter(&$chart, $chart_id) { * Same as hook_chart_alter(), only including the $chart_id in the function * name instead of being passed in as an argument. * - * @see hook_chart_alter() - * * @param mixed $chart * Chart. + * + * @see hook_chart_alter() */ function hook_chart_CHART_ID_alter(&$chart) { } @@ -116,10 +116,10 @@ function hook_chart_definition_alter(&$definition, $chart) { * Same as hook_chart_definition_alter(), only including the $chart_id in the * function name instead of being passed in as an argument. * - * @see hook_chart_definition_alter() - * - * @param $chart + * @param mixed $chart * Chart. + * + * @see hook_chart_definition_alter() */ function hook_chart_definition_CHART_ID_alter(&$chart) { } @@ -151,7 +151,7 @@ function hook_charts_info() { * If your module needs to modify the capabilities of a charting library, such * as to add support for a new chart type, it may do so with this hook. * - * @param array $info + * @param mixed $info * Info. */ function hook_charts_info_alter(&$info) { @@ -191,7 +191,7 @@ function hook_charts_type_info() { * If your module needs to modify the capabilities or labels of a paricular * chart type, it may alter the definitions provided by other modules. * - * @param array $chart_types + * @param mixed $chart_types * Chart Types. */ function hook_charts_type_info_alter(&$chart_types) { diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc index dc43888..2e92c25 100644 --- a/includes/charts.pages.inc +++ b/includes/charts.pages.inc @@ -237,20 +237,6 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren } } -/* - // Get a list of available chart libraries. - $charts_info = charts_info(); - $library_options = []; - foreach ($charts_info as $library_name => $library_info) { - if (Drupal::moduleHandler()->moduleExists($charts_info[$library_name]['module'])) { - $library_options[$library_name] = $library_info['label']; - } - } - if (count($library_options) == 0) { - drupal_set_message(t('There are no enabled charting libraries. Please enable a Charts sub-module.')); - } -*/ - $form['library'] = [ '#title' => t('Charting library'), '#type' => 'select', @@ -299,7 +285,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren /* $form['#theme'] = 'charts_settings_fields'; */ - $form['fields'] = [ + $form['fields'] = [ '#title' => t('Charts fields'), '#type' => 'fieldset', ]; @@ -313,7 +299,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#parents' => array_merge($parents, ['label_field']), ]; - $form['fields']['table'] = [ + $form['fields']['table'] = [ '#type' => 'table', '#header' => [t('Field Name'), t('Provides Data'), t('Color')], '#tabledrag' => TRUE, @@ -321,13 +307,13 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren $field_count = 0; foreach ($field_options as $field_name => $field_label) { - $form['fields']['table'][$field_count]['label_label'] = [ + $form['fields']['table'][$field_count]['label_label'] = [ '#type' => 'label', '#title' => $field_label, '#column' => 'one', ]; - $form['fields']['table'][$field_count]['data_fields'][$field_name] = [ + $form['fields']['table'][$field_count]['data_fields'][$field_name] = [ '#type' => 'checkbox', '#title' => $field_name, '#default_value' => $options['data_fields'][$field_name], @@ -356,14 +342,14 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren } } - $form['display'] = [ + $form['display'] = [ '#title' => t('Display'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, ]; - $form['display']['title'] = [ + $form['display']['title'] = [ '#title' => t('Chart title'), '#type' => 'textfield', '#default_value' => $options['title'], @@ -431,13 +417,13 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#parents' => array_merge($parents, ['background']), ]; - $form['display']['dimensions'] = [ + $form['display']['dimensions'] = [ '#title' => t('Dimensions'), '#theme_wrappers' => ['form_element'], '#description' => t('If dimensions are left empty, the chart will fill its containing element.'), ]; - $form['display']['dimensions']['width'] = [ + $form['display']['dimensions']['width'] = [ '#type' => 'textfield', '#attributes' => [ 'TYPE' => 'number', @@ -469,7 +455,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#parents' => array_merge($parents, ['height']), ]; - $form['xaxis'] = [ + $form['xaxis'] = [ '#title' => t('Horizontal axis'), '#type' => 'fieldset', '#collapsible' => TRUE, @@ -477,7 +463,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#attributes' => ['class' => ['chart-xaxis']], ]; - $form['xaxis']['xaxis_title'] = [ + $form['xaxis']['xaxis_title'] = [ '#title' => t('Custom title'), '#type' => 'textfield', '#default_value' => $options['xaxis_title'], @@ -500,24 +486,26 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#parents' => array_merge($parents, ['xaxis_labels_rotation']), ]; - $form['yaxis'] = [ + $form['yaxis'] = [ '#title' => t('Vertical axis'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#attributes' => ['class' => ['chart-yaxis']], ]; - $form['yaxis']['title'] = [ + $form['yaxis']['title'] = [ '#title' => t('Custom title'), '#type' => 'textfield', '#default_value' => $options['yaxis_title'], '#parents' => array_merge($parents, ['yaxis_title']), ]; - $form['yaxis']['minmax'] = [ + + $form['yaxis']['minmax'] = [ '#title' => t('Value range'), '#theme_wrappers' => ['form_element'], ]; - $form['yaxis']['minmax']['min'] = [ + + $form['yaxis']['minmax']['min'] = [ '#type' => 'textfield', '#attributes' => [ 'TYPE' => 'number', @@ -530,7 +518,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#suffix' => ' ', '#theme_wrappers' => [], ]; - $form['yaxis']['minmax']['max'] = [ + $form['yaxis']['minmax']['max'] = [ '#type' => 'textfield', '#attributes' => [ 'TYPE' => 'number', @@ -543,7 +531,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#theme_wrappers' => [], ]; - $form['yaxis']['prefix'] = [ + $form['yaxis']['prefix'] = [ '#title' => t('Value prefix'), '#type' => 'textfield', '#default_value' => $options['yaxis_prefix'], @@ -551,7 +539,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#parents' => array_merge($parents, ['yaxis_prefix']), ]; - $form['yaxis']['suffix'] = [ + $form['yaxis']['suffix'] = [ '#title' => t('Value suffix'), '#type' => 'textfield', '#default_value' => $options['yaxis_suffix'], @@ -559,7 +547,7 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren '#parents' => array_merge($parents, ['yaxis_suffix']), ]; - $form['yaxis']['decimal_count'] = [ + $form['yaxis']['decimal_count'] = [ '#title' => t('Decimal count'), '#type' => 'textfield', '#attributes' => [ @@ -597,9 +585,9 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren /** * Menu callback; Configure the site-wide defaults for charts. * - * @param array $form + * @param mixed $form * Form. - * @param array $form_state + * @param mixed $form_state * Form State, Standard parameters for a form. * * @return mixed @@ -646,14 +634,13 @@ function charts_default_settings_form($form, $form_state) { /** * Submit handler for charts_default_settings_form(). * - * @param array $form + * @param mixed $form * Form. - * @param array $form_state + * @param mixed $form_state * Form State. */ function charts_default_settings_form_submit($form, $form_state) { - \Drupal::state() - ->set('charts_default_settings', $form_state['values']['charts_default_settings']); + \Drupal::state()->set('charts_default_settings', $form_state['values']['charts_default_settings']); } /** diff --git a/modules/charts_c3/charts_c3.module b/modules/charts_c3/charts_c3.module index f72fa7c..2d73eac 100644 --- a/modules/charts_c3/charts_c3.module +++ b/modules/charts_c3/charts_c3.module @@ -22,7 +22,7 @@ function charts_c3_charts_info() { 'line', 'pie', 'donut', - 'scatter' + 'scatter', ], ], ]; @@ -30,7 +30,7 @@ function charts_c3_charts_info() { /** * Implements hook_charts_type_info(). -*/ + */ function charts_c3_charts_type_info() { $chart_types['donut'] = [ 'label' => t('Donut'), diff --git a/modules/charts_c3/src/Charts/C3ChartsRender.php b/modules/charts_c3/src/Charts/C3ChartsRender.php index 4d08dd6..062a434 100644 --- a/modules/charts_c3/src/Charts/C3ChartsRender.php +++ b/modules/charts_c3/src/Charts/C3ChartsRender.php @@ -61,19 +61,12 @@ class C3ChartsRender implements ChartsRenderInterface { } // Sets the primary y axis. -/* - $yAxis = []; - $yAxis[$seriesData[0]['name']] = 'y'; -*/ $showAxis['show'] = TRUE; $showAxis['label'] = $options['yaxis_title']; $chartAxis->y = $showAxis; // Sets secondary axis from the first attachment only. if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) { -/* - $yAxis[$seriesData[1]['name']] = 'y2'; -*/ $showSecAxis['show'] = TRUE; $showSecAxis['label'] = $attachmentDisplayOptions[0]['style']['options']['yaxis_title']; $chartAxis->y2 = $showSecAxis; diff --git a/modules/charts_c3/src/Plugin/chart/CThreeCharts.php b/modules/charts_c3/src/Plugin/chart/CThreeCharts.php index db351ca..3fef33d 100644 --- a/modules/charts_c3/src/Plugin/chart/CThreeCharts.php +++ b/modules/charts_c3/src/Plugin/chart/CThreeCharts.php @@ -70,20 +70,12 @@ class CThreeCharts extends AbstractChart { $chartData->setLabels(FALSE); } - // Sets the primary y axis. -/* - $yAxis = []; - $yAxis[$seriesData[0]['name']] = 'y'; -*/ $showAxis['show'] = TRUE; $showAxis['label'] = $options['yaxis_title']; $chartAxis->y = $showAxis; // Sets secondary axis from the first attachment only. if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) { -/* - $yAxis[$seriesData[1]['name']] = 'y2'; -*/ $showSecAxis['show'] = TRUE; $showSecAxis['label'] = $attachmentDisplayOptions[0]['style']['options']['yaxis_title']; $chartAxis->y2 = $showSecAxis; diff --git a/modules/charts_google/src/Settings/Google/ChartAxes.php b/modules/charts_google/src/Settings/Google/ChartAxes.php index d2a6f06..bf47c07 100644 --- a/modules/charts_google/src/Settings/Google/ChartAxes.php +++ b/modules/charts_google/src/Settings/Google/ChartAxes.php @@ -133,7 +133,7 @@ class ChartAxes implements \JsonSerializable { /** * Set Chart Axis property that specifies a title for the axis. * - * @param $value + * @param mixed $value * Title. */ public function setTitle($value) { diff --git a/modules/charts_google/src/Settings/Google/GoogleOptions.php b/modules/charts_google/src/Settings/Google/GoogleOptions.php index ba63f1b..fee23fe 100644 --- a/modules/charts_google/src/Settings/Google/GoogleOptions.php +++ b/modules/charts_google/src/Settings/Google/GoogleOptions.php @@ -70,7 +70,7 @@ class GoogleOptions implements \JsonSerializable { * Colors. * * The colors to use for the chart elements. An array of strings, where each - * element is an HTML color string + * element is an HTML color string. * * @var mixed */ @@ -296,6 +296,7 @@ class GoogleOptions implements \JsonSerializable { * Sets the Legend properties. * * @param mixed $legend + * Legend. */ public function setLegend($legend) { $this->legend = $legend; diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php index efd13d9..d6f848a 100644 --- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php +++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php @@ -48,7 +48,7 @@ class HighchartsChartsRender implements ChartsRenderInterface { $value = str_replace('donut', 'pie', $value); } // Add innerSize to differentiate between donut and pie. - foreach ($seriesData as $key => &$value) { + foreach ($seriesData as &$value) { if ($typeOptions == 'pie') { $innerSize['showInLegend'] = 'true'; $innerSize['innerSize'] = '40%'; diff --git a/modules/charts_highcharts/src/Plugin/chart/Highchart.php b/modules/charts_highcharts/src/Plugin/chart/Highchart.php index d883dd7..b7c14fb 100644 --- a/modules/charts_highcharts/src/Plugin/chart/Highchart.php +++ b/modules/charts_highcharts/src/Plugin/chart/Highchart.php @@ -62,7 +62,7 @@ class Highchart extends AbstractChart { $value = str_replace('donut', 'pie', $value); } // Add innerSize to differentiate between donut and pie. - foreach ($seriesData as $key => &$value) { + foreach ($seriesData as &$value) { if ($typeOptions == 'pie') { $innerSize['showInLegend'] = 'true'; $innerSize['innerSize'] = '40%'; diff --git a/src/Plugin/chart/ChartInterface.php b/src/Plugin/chart/ChartInterface.php index a63b427..05d590d 100644 --- a/src/Plugin/chart/ChartInterface.php +++ b/src/Plugin/chart/ChartInterface.php @@ -21,7 +21,8 @@ interface ChartInterface extends PluginInspectionInterface { * Return the name of the chart. * * @return string - * returns the name as a string. + * Returns the name as a string. */ public function getChartName(); + } diff --git a/src/Plugin/chart/ChartManager.php b/src/Plugin/chart/ChartManager.php index 9952088..be5b51e 100644 --- a/src/Plugin/chart/ChartManager.php +++ b/src/Plugin/chart/ChartManager.php @@ -7,6 +7,8 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; /** + * Chart Manager. + * * Provides the Chart plugin plugin manager and manages discovery and * instantiation of chart plugins. */ diff --git a/src/Util/Util.php b/src/Util/Util.php index 29e6f05..7ea0c5b 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -3,15 +3,12 @@ namespace Drupal\charts\Util; use Drupal\views\ViewExecutable; -use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Util. */ class Util { - use StringTranslationTrait; - /** * Views Data. * @@ -118,7 +115,7 @@ class Util { $module_path = drupal_get_path('module', $moduleName); if (!file_exists($module_path . $libraryPath)) { $text = 'Charting libraries for ' . $moduleName . ' might not be installed. Run \'composer install\' for ' . $moduleName . ' sub-module.'; - drupal_set_message($this->t($text), 'error'); + drupal_set_message(t($text), 'error'); } } -- GitLab