diff --git a/charts.api.php b/charts.api.php index cdd8c6ac5d2dfb60ebe428ae28d9df7d06acdd35..d9caeab5f42a450f5692b91e75f9dfc234935f60 100644 --- a/charts.api.php +++ b/charts.api.php @@ -1,9 +1,8 @@ <?php -use Drupal\charts\Theme\ChartsInterface; - /** * @file + * * Documentation on hooks provided by the Charts module. * * Charts module provides 4 element types that can be used to construct a chart. @@ -50,10 +49,12 @@ use Drupal\charts\Theme\ChartsInterface; * chart_data, chart_xaxis, and chart_yaxis). For a full list, see the * charts_element_info() function. * - * * @see charts_element_info() - * - * + */ + +use Drupal\charts\Theme\ChartsInterface; + +/** * Alter an individual chart before it is printed. * * @param $chart @@ -76,7 +77,9 @@ function hook_chart_alter(&$chart, $chart_id) { * name instead of being passed in as an argument. * * @see hook_chart_alter() - * @param $chart + * + * @param mixed $chart + * Chart. */ function hook_chart_CHART_ID_alter(&$chart) { } @@ -93,13 +96,14 @@ function hook_chart_CHART_ID_alter(&$chart) { * Even though this hook may be fragile, it may provide developers with access * to library-specific functionality. * - * @param $definition + * @param mixed $definition * The chart definition to be modified. The raw values are passed directly to * the charting library. - * @param $chart + * @param mixed $chart * The chart renderable. This may be used for reference (or read to add * support for new properties), but any changes to this variable will not * have an effect on output. + * * @internal param $chart_id The chart ID, derived from the $chart['#chart_id'] property. Note that not* The chart ID, derived from the $chart['#chart_id'] property. Note that not * all charts may have a $chart_id. */ @@ -111,8 +115,11 @@ 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 + * Chart. */ function hook_chart_definition_CHART_ID_alter(&$chart) { } @@ -133,7 +140,7 @@ function hook_charts_info() { // Specify the chart types your library is capable of providing. 'types' => ['area', 'bar', 'column', 'donut', 'line', 'pie', 'scatter'], // If your callback function is in a separate file, specify it's location. - // 'file' => 'includes/my_charting_library.inc', + /* 'file' => 'includes/my_charting_library.inc', */ ]; return $info; } @@ -143,7 +150,9 @@ 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 $info + * + * @param array $info + * Info. */ function hook_charts_info_alter(&$info) { // Say the Google charts library supports geo charts. @@ -167,7 +176,8 @@ function hook_charts_type_info() { // Many charting libraries always refer to the main axis as the "y-axis", // even if the chart's main axis is horizontal. An example of this is a // bar chart, where the values are along the horizontal axis. - 'axis_inverted' => TRUE, // Meaning x/y axis are flipped. + // Meaning x/y axis are flipped. + 'axis_inverted' => TRUE, // For bar/area/other charts that support stacking of series, set this value // to TRUE. 'stacking' => TRUE, @@ -180,7 +190,9 @@ 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 $chart_types + * + * @param array $chart_types + * Chart Types. */ function hook_charts_type_info_alter(&$chart_types) { $chart_types['bar']['stacking'] = FALSE; diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc index 1405b5ed8338ef49f864c67433e6c583ddb1a042..dc43888307c1dc5f927f47c395158e4ee56abadc 100644 --- a/includes/charts.pages.inc +++ b/includes/charts.pages.inc @@ -2,8 +2,10 @@ /** * @file + * * Menu callbacks for Charts module. */ + use Drupal\charts\Theme\ChartsInterface; /** @@ -20,8 +22,8 @@ use Drupal\charts\Theme\ChartsInterface; * namespace, an array of parent names that will be prepended to each * element's #parents property. * - * @return mixed The form with the chart settings added. - * The form with the chart settings added. + * @return mixed + * The form with the chart settings added. */ /** @@ -34,8 +36,7 @@ function charts_info() { $charts_info = []; $chart_modules = Drupal::moduleHandler()->getImplementations('charts_info'); foreach ($chart_modules as $module) { - $module_charts_info = Drupal::moduleHandler() - ->invoke($module, 'charts_info'); + $module_charts_info = Drupal::moduleHandler()->invoke($module, 'charts_info'); foreach ($module_charts_info as $chart_library => $chart_library_info) { $module_charts_info[$chart_library]['module'] = $module; } @@ -57,10 +58,10 @@ function charts_type_info() { foreach ($charts_type_info as $chart_type => $chart_type_info) { $charts_type_info[$chart_type] += [ - 'label' => '', - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'label' => '', + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, 'axis_inverted' => FALSE, - 'stacking' => FALSE, + 'stacking' => FALSE, ]; } @@ -72,10 +73,10 @@ function charts_type_info() { * Retrieve a specific chart type. * * @param string $chart_type - * The type of chart selected for display. + * The type of chart selected for display. * * @return mixed - * If not false, returns an array of values from charts_charts_type_info. + * If not false, returns an array of values from charts_charts_type_info. */ function charts_get_type($chart_type) { $types = charts_type_info(); @@ -86,39 +87,44 @@ function charts_get_type($chart_type) { * Implements hook_charts_type_info(). */ function charts_charts_type_info() { - $chart_types['pie'] = [ - 'label' => t('Pie'), - 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, - ]; - $chart_types['bar'] = [ - 'label' => t('Bar'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, - 'axis_inverted' => TRUE, - 'stacking' => TRUE, - ]; - $chart_types['column'] = [ - 'label' => t('Column'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, - 'stacking' => TRUE, - ]; - $chart_types['line'] = [ - 'label' => t('Line'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, - ]; - $chart_types['area'] = [ - 'label' => t('Area'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, - 'stacking' => TRUE, - ]; - $chart_types['scatter'] = [ - 'label' => t('Scatter'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + + return [ + 'pie' => [ + 'label' => t('Pie'), + 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, + ], + 'bar' => [ + 'label' => t('Bar'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'axis_inverted' => TRUE, + 'stacking' => TRUE, + ], + 'column' => [ + 'label' => t('Column'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'stacking' => TRUE, + ], + 'line' => [ + 'label' => t('Line'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + ], + 'area' => [ + 'label' => t('Area'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'stacking' => TRUE, + ], + 'scatter' => [ + 'label' => t('Scatter'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + ], ]; - return $chart_types; } /** * Default colors used in all libraries. + * + * @return array + * Default Colors. */ function charts_default_colors() { return [ @@ -138,14 +144,15 @@ function charts_default_colors() { /** * Recursive function to trim out empty options that aren't used. * - * @param array $array - * Array may contain empty options. + * @param mixed $array + * Array may contain empty options. */ function charts_trim_array(&$array) { foreach ($array as $key => &$value) { if (is_array($value)) { charts_trim_array($value); - } elseif (is_null($value) || (is_array($value) && count($value) === 0)) { + } + elseif (is_null($value) || (is_array($value) && count($value) === 0)) { unset($array[$key]); } } @@ -155,7 +162,7 @@ function charts_trim_array(&$array) { * Recursive function to cast integer values. * * @param mixed $element - * Cast options to integers to avoid redundant library fixing problems. + * Cast options to integers to avoid redundant library fixing problems. */ function charts_cast_element_integer_values(&$element) { $integer_options = [ @@ -179,53 +186,60 @@ function charts_cast_element_integer_values(&$element) { foreach ($element as $property_name => $value) { if (is_array($element[$property_name])) { charts_cast_element_integer_values($element[$property_name]); - } elseif ($property_name && in_array($property_name, $integer_options)) { - $element[$property_name] = (is_null($element[$property_name]) || strlen($element[$property_name]) === 0) - ? NULL : (int)$element[$property_name]; + } + elseif ($property_name && in_array($property_name, $integer_options)) { + $element[$property_name] = (is_null($element[$property_name]) || strlen($element[$property_name]) === 0) ? NULL : (int) $element[$property_name]; } } } /** - * @param $form - * @param array $defaults - * @param array $field_options - * @param array $parents + * Charts Settings Form. + * + * @param mixed $form + * Form. + * @param mixed $defaults + * Defaults. + * @param mixed $field_options + * Field Options. + * @param mixed $parents + * Parents. * * @return mixed + * Form. */ function charts_settings_form($form, $defaults = [], $field_options = [], $parents = []) { + // Ensure all defaults are set. $options = array_merge(charts_default_settings(), $defaults); - //using plugins to get the available installed libraries + // Using plugins to get the available installed libraries. $plugin_manager = \Drupal::service('plugin.manager.charts'); $plugin_definitions = $plugin_manager->getDefinitions(); $library_options = []; - foreach ($plugin_definitions as $plugin_definition){ - $library_options[$plugin_definition['id']] = $plugin_definition['name']; + foreach ($plugin_definitions as $plugin_definition) { + $library_options[$plugin_definition['id']] = $plugin_definition['name']; } - // Get a list of available chart libraries if plugins have not been implemented. - // This will be removed as ModuleSelector is now @deprecated - - if (empty($library_options)){ - $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 (empty($library_options)) { - drupal_set_message(t('There are no enabled charting libraries. Please enable a Charts sub-module.')); + // Get a list of available chart libraries if plugins have not been + // implemented. This will be removed as ModuleSelector is now @deprecated. + if (empty($library_options)) { + $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 (empty($library_options)) { + drupal_set_message(t('There are no enabled charting libraries. Please enable a Charts sub-module.')); + } } +/* // Get a list of available chart libraries. - /*$charts_info = charts_info(); + $charts_info = charts_info(); $library_options = []; foreach ($charts_info as $library_name => $library_info) { if (Drupal::moduleHandler()->moduleExists($charts_info[$library_name]['module'])) { @@ -234,17 +248,19 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren } 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', - '#options' => $library_options, + '#title' => t('Charting library'), + '#type' => 'select', + '#options' => $library_options, '#default_value' => $options['library'], - '#required' => TRUE, - '#access' => count($library_options) > 0, - '#attributes' => ['class' => ['chart-library-select']], - '#weight' => -15, - '#parents' => array_merge($parents, ['library']), + '#required' => TRUE, + '#access' => count($library_options) > 0, + '#attributes' => ['class' => ['chart-library-select']], + '#weight' => -15, + '#parents' => array_merge($parents, ['library']), ]; $chart_types = charts_type_info(); @@ -253,19 +269,19 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren $type_options[$chart_type] = $chart_type_info['label']; } $form['type'] = [ - '#title' => t('Chart type'), - '#type' => 'radios', + '#title' => t('Chart type'), + '#type' => 'radios', '#default_value' => $options['type'], - '#options' => $type_options, - '#required' => TRUE, - '#weight' => -20, - '#attributes' => [ + '#options' => $type_options, + '#required' => TRUE, + '#weight' => -20, + '#attributes' => [ 'class' => [ 'chart-type-radios', 'container-inline', ], ], - '#parents' => array_merge($parents, ['type']), + '#parents' => array_merge($parents, ['type']), ]; // Set data attributes to identify special properties of different types. @@ -281,284 +297,298 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren if ($field_options) { $first_field = key($field_options); - // $form['#theme'] = 'charts_settings_fields'; - $form['fields'] = [ + /* $form['#theme'] = 'charts_settings_fields'; */ + + $form['fields'] = [ '#title' => t('Charts fields'), - '#type' => 'fieldset', + '#type' => 'fieldset', ]; + $form['fields']['label_field'] = [ - '#type' => 'radios', - '#title' => t('Label field'), - '#options' => $field_options + ['' => t('No label field')], + '#type' => 'radios', + '#title' => t('Label field'), + '#options' => $field_options + ['' => t('No label field')], '#default_value' => isset($options['label_field']) ? $options['label_field'] : $first_field, - '#weight' => -10, - '#parents' => array_merge($parents, ['label_field']), + '#weight' => -10, + '#parents' => array_merge($parents, ['label_field']), ]; - $form['fields']['table'] = [ - '#type' => 'table', - '#header' => [t('Field Name'), t('Provides Data'), t('Color')], + + $form['fields']['table'] = [ + '#type' => 'table', + '#header' => [t('Field Name'), t('Provides Data'), t('Color')], '#tabledrag' => TRUE, ]; $field_count = 0; foreach ($field_options as $field_name => $field_label) { - $form['fields']['table'][$field_count]['label_label'] = [ - '#type' => 'label', - '#title' => $field_label, + $form['fields']['table'][$field_count]['label_label'] = [ + '#type' => 'label', + '#title' => $field_label, '#column' => 'one', ]; - $form['fields']['table'][$field_count]['data_fields'][$field_name] = [ - '#type' => 'checkbox', - '#title' => $field_name, + + $form['fields']['table'][$field_count]['data_fields'][$field_name] = [ + '#type' => 'checkbox', + '#title' => $field_name, '#default_value' => $options['data_fields'][$field_name], - '#return_value' => $field_name, - '#weight' => -9, - '#states' => [ + '#return_value' => $field_name, + '#weight' => -9, + '#states' => [ 'disabled' => [ ':input[name="style_options[label_field]"]' => ['value' => $field_name], ], ], - '#parents' => array_merge($parents, ['data_fields', $field_name]), - '#column' => 'two', + '#parents' => array_merge($parents, ['data_fields', $field_name]), + '#column' => 'two', ]; + $form['fields']['table'][$field_count]['field_colors'][$field_name] = [ - '#type' => 'textfield', - '#attributes' => ['TYPE' => 'color'], - '#size' => 10, - '#maxlength' => 7, + '#type' => 'textfield', + '#attributes' => ['TYPE' => 'color'], + '#size' => 10, + '#maxlength' => 7, '#theme_wrappers' => [], - '#default_value' => !empty($options['field_colors'][$field_name]) ? $options['field_colors'][$field_name] : $options['colors'][$field_count], - '#parents' => array_merge($parents, ['field_colors', $field_name]), - '#column' => 'three', + '#default_value' => !empty($options['field_colors'][$field_name]) ? $options['field_colors'][$field_name] : $options['colors'][$field_count], + '#parents' => array_merge($parents, ['field_colors', $field_name]), + '#column' => 'three', ]; $field_count++; - } - } - $form['display'] = [ - '#title' => t('Display'), - '#type' => 'fieldset', + + $form['display'] = [ + '#title' => t('Display'), + '#type' => 'fieldset', '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#collapsed' => TRUE, ]; - $form['display']['title'] = [ - '#title' => t('Chart title'), - '#type' => 'textfield', + + $form['display']['title'] = [ + '#title' => t('Chart title'), + '#type' => 'textfield', '#default_value' => $options['title'], - '#parents' => array_merge($parents, ['title']), + '#parents' => array_merge($parents, ['title']), ]; + $form['display']['title_position'] = [ - '#title' => t('Title position'), - '#type' => 'select', - '#options' => [ - '' => t('None'), + '#title' => t('Title position'), + '#type' => 'select', + '#options' => [ + '' => t('None'), 'out' => t('Outside'), - 'in' => t('Inside'), + 'in' => t('Inside'), ], '#default_value' => $options['title_position'], - '#parents' => array_merge($parents, ['title_position']), + '#parents' => array_merge($parents, ['title_position']), ]; $form['display']['tooltips'] = [ - '#title' => t('Tooltips'), - '#type' => 'select', - '#options' => [ - '' => t('Disabled'), + '#title' => t('Tooltips'), + '#type' => 'select', + '#options' => [ + '' => t('Disabled'), 'TRUE' => t('Enabled'), ], - '#description' => t('Show data details on mouse over? Note: unavailable for print or on mobile devices.'), + '#description' => t('Show data details on mouse over? Note: unavailable for print or on mobile devices.'), '#default_value' => $options['tooltips'], - '#parents' => array_merge($parents, ['tooltips']), + '#parents' => array_merge($parents, ['tooltips']), ]; $form['display']['data_labels'] = [ - '#title' => t('Data labels'), - '#type' => 'select', - '#options' => [ - '' => t('Disabled'), + '#title' => t('Data labels'), + '#type' => 'select', + '#options' => [ + '' => t('Disabled'), 'TRUE' => t('Enabled'), ], '#default_value' => $options['data_labels'], - '#description' => t('Show data details as labels on chart? Note: recommended for print or on mobile devices.'), - '#parents' => array_merge($parents, ['data_labels']), + '#description' => t('Show data details as labels on chart? Note: recommended for print or on mobile devices.'), + '#parents' => array_merge($parents, ['data_labels']), ]; $form['display']['legend_position'] = [ - '#title' => t('Legend position'), - '#type' => 'select', - '#options' => [ - '' => t('None'), - 'top' => t('Top'), - 'right' => t('Right'), + '#title' => t('Legend position'), + '#type' => 'select', + '#options' => [ + '' => t('None'), + 'top' => t('Top'), + 'right' => t('Right'), 'bottom' => t('Bottom'), - 'left' => t('Left'), + 'left' => t('Left'), ], '#default_value' => $options['legend_position'], - '#parents' => array_merge($parents, ['legend_position']), + '#parents' => array_merge($parents, ['legend_position']), ]; $form['display']['background'] = [ - '#title' => t('Background color'), - '#type' => 'textfield', - '#size' => 10, - '#maxlength' => 7, - '#attributes' => ['placeholder' => t('transparent')], - '#description' => t('Leave blank for a transparent background.'), + '#title' => t('Background color'), + '#type' => 'textfield', + '#size' => 10, + '#maxlength' => 7, + '#attributes' => ['placeholder' => t('transparent')], + '#description' => t('Leave blank for a transparent background.'), '#default_value' => $options['background'], - '#parents' => array_merge($parents, ['background']), + '#parents' => array_merge($parents, ['background']), ]; - $form['display']['dimensions'] = [ - '#title' => t('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.'), + '#description' => t('If dimensions are left empty, the chart will fill its containing element.'), ]; - $form['display']['dimensions']['width'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 9999, + + $form['display']['dimensions']['width'] = [ + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 9999, 'placeholder' => t('auto'), ], - '#default_value' => $options['width'], - '#size' => 8, - '#suffix' => ' x ', + '#default_value' => $options['width'], + '#size' => 8, + '#suffix' => ' x ', '#theme_wrappers' => [], - '#parents' => array_merge($parents, ['width']), + '#parents' => array_merge($parents, ['width']), ]; + $form['display']['dimensions']['height'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 9999, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 9999, 'placeholder' => t('auto'), ], - '#default_value' => $options['height'], - '#size' => 8, - '#suffix' => ' px', + '#default_value' => $options['height'], + '#size' => 8, + '#suffix' => ' px', '#theme_wrappers' => [], - '#parents' => array_merge($parents, ['height']), + '#parents' => array_merge($parents, ['height']), ]; - $form['xaxis'] = [ - '#title' => t('Horizontal axis'), - '#type' => 'fieldset', + $form['xaxis'] = [ + '#title' => t('Horizontal axis'), + '#type' => 'fieldset', '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#attributes' => ['class' => ['chart-xaxis']], + '#collapsed' => TRUE, + '#attributes' => ['class' => ['chart-xaxis']], ]; - $form['xaxis']['xaxis_title'] = [ - '#title' => t('Custom title'), - '#type' => 'textfield', + + $form['xaxis']['xaxis_title'] = [ + '#title' => t('Custom title'), + '#type' => 'textfield', '#default_value' => $options['xaxis_title'], - '#parents' => array_merge($parents, ['xaxis_title']), + '#parents' => array_merge($parents, ['xaxis_title']), ]; + $form['xaxis']['labels_rotation'] = [ - '#title' => t('Labels rotation'), - '#type' => 'select', - '#options' => [ - 0 => t('0°'), + '#title' => t('Labels rotation'), + '#type' => 'select', + '#options' => [ + 0 => t('0°'), 30 => t('30°'), 45 => t('45°'), 60 => t('60°'), 90 => t('90°'), ], // This is only shown on non-inverted charts. - '#attributes' => ['class' => ['axis-inverted-hide']], + '#attributes' => ['class' => ['axis-inverted-hide']], '#default_value' => $options['xaxis_labels_rotation'], - '#parents' => array_merge($parents, ['xaxis_labels_rotation']), + '#parents' => array_merge($parents, ['xaxis_labels_rotation']), ]; - $form['yaxis'] = [ - '#title' => t('Vertical axis'), - '#type' => 'fieldset', + $form['yaxis'] = [ + '#title' => t('Vertical axis'), + '#type' => 'fieldset', '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#attributes' => ['class' => ['chart-yaxis']], + '#collapsed' => TRUE, + '#attributes' => ['class' => ['chart-yaxis']], ]; - $form['yaxis']['title'] = [ - '#title' => t('Custom title'), - '#type' => 'textfield', + $form['yaxis']['title'] = [ + '#title' => t('Custom title'), + '#type' => 'textfield', '#default_value' => $options['yaxis_title'], - '#parents' => array_merge($parents, ['yaxis_title']), + '#parents' => array_merge($parents, ['yaxis_title']), ]; - $form['yaxis']['minmax'] = [ - '#title' => t('Value range'), + $form['yaxis']['minmax'] = [ + '#title' => t('Value range'), '#theme_wrappers' => ['form_element'], ]; - $form['yaxis']['minmax']['min'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'max' => 999999, + $form['yaxis']['minmax']['min'] = [ + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'max' => 999999, 'placeholder' => t('Minimum'), ], - '#default_value' => $options['yaxis_min'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_min']), - '#suffix' => ' ', + '#default_value' => $options['yaxis_min'], + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_min']), + '#suffix' => ' ', '#theme_wrappers' => [], ]; - $form['yaxis']['minmax']['max'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'max' => 999999, + $form['yaxis']['minmax']['max'] = [ + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'max' => 999999, 'placeholder' => t('Maximum'), ], - '#default_value' => $options['yaxis_max'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_max']), + '#default_value' => $options['yaxis_max'], + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_max']), '#theme_wrappers' => [], ]; - $form['yaxis']['prefix'] = [ - '#title' => t('Value prefix'), - '#type' => 'textfield', + + $form['yaxis']['prefix'] = [ + '#title' => t('Value prefix'), + '#type' => 'textfield', '#default_value' => $options['yaxis_prefix'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_prefix']), + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_prefix']), ]; - $form['yaxis']['suffix'] = [ - '#title' => t('Value suffix'), - '#type' => 'textfield', + + $form['yaxis']['suffix'] = [ + '#title' => t('Value suffix'), + '#type' => 'textfield', '#default_value' => $options['yaxis_suffix'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_suffix']), - ]; - $form['yaxis']['decimal_count'] = [ - '#title' => t('Decimal count'), - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 20, + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_suffix']), + ]; + + $form['yaxis']['decimal_count'] = [ + '#title' => t('Decimal count'), + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 20, 'placeholder' => t('auto'), ], '#default_value' => $options['yaxis_decimal_count'], - '#size' => 5, - '#description' => t('Enforce a certain number of decimal-place digits in displayed values.'), - '#parents' => array_merge($parents, ['yaxis_decimal_count']), + '#size' => 5, + '#description' => t('Enforce a certain number of decimal-place digits in displayed values.'), + '#parents' => array_merge($parents, ['yaxis_decimal_count']), ]; + $form['yaxis']['labels_rotation'] = [ - '#title' => t('Labels rotation'), - '#type' => 'select', - '#options' => [ - 0 => t('0°'), + '#title' => t('Labels rotation'), + '#type' => 'select', + '#options' => [ + 0 => t('0°'), 30 => t('30°'), 45 => t('45°'), 60 => t('60°'), 90 => t('90°'), ], // This is only shown on inverted charts. - '#attributes' => ['class' => ['axis-inverted-show']], + '#attributes' => ['class' => ['axis-inverted-show']], '#default_value' => $options['yaxis_labels_rotation'], - '#parents' => array_merge($parents, ['yaxis_labels_rotation']), + '#parents' => array_merge($parents, ['yaxis_labels_rotation']), ]; return $form; @@ -567,23 +597,23 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren /** * Menu callback; Configure the site-wide defaults for charts. * - * @param $form - * @param $form_state - * Standard parameters for a form. + * @param array $form + * Form. + * @param array $form_state + * Form State, Standard parameters for a form. * * @return mixed - * + * Form. */ function charts_default_settings_form($form, $form_state) { - $defaults = \Drupal::state() - ->get('charts_default_settings', []); + $defaults = \Drupal::state()->get('charts_default_settings', []); $defaults += charts_default_settings(); $field_options = []; $parents = ['charts_default_settings']; // Add help. $form['help'] = [ - '#type' => 'markup', + '#type' => 'markup', '#markup' => '<p>' . t('The settings on this page are used to set <strong>default</strong> settings. They do not affect existing charts. To make a new chart, <a href="!views">create a new view</a> and select the display format of "Chart".', ['!views' => url('admin/structure/views/add')]) . '</p>', '#weight' => -100, ]; @@ -606,7 +636,7 @@ function charts_default_settings_form($form, $form_state) { // Add submit buttons and normal saving behavior. $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = [ - '#type' => 'submit', + '#type' => 'submit', '#value' => t('Save defaults'), ]; @@ -615,16 +645,22 @@ function charts_default_settings_form($form, $form_state) { /** * Submit handler for charts_default_settings_form(). - * @param $form - * @param $form_state + * + * @param array $form + * Form. + * @param array $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']); + ->set('charts_default_settings', $form_state['values']['charts_default_settings']); } /** * Provides default options used by charts_settings_form(). + * + * @return array + * Default settings. */ function charts_default_settings() { $defaults = [ diff --git a/modules/charts_c3/charts_c3.module b/modules/charts_c3/charts_c3.module index 45469508b0c10089adec04073cf6e3cbd21de5ac..f72fa7c355956f43de04a8afa809066506cc992f 100644 --- a/modules/charts_c3/charts_c3.module +++ b/modules/charts_c3/charts_c3.module @@ -11,11 +11,21 @@ use Drupal\charts\Theme\ChartsInterface; * Implements hook_charts_info(). */ function charts_c3_charts_info() { - $info['c3'] = [ - 'label' => t('C3 Charts'), - 'types' => ['area', 'bar', 'column', 'donut', 'line', 'pie', 'donut', 'scatter'], + return [ + 'c3' => [ + 'label' => t('C3 Charts'), + 'types' => [ + 'area', + 'bar', + 'column', + 'donut', + 'line', + 'pie', + 'donut', + 'scatter' + ], + ], ]; - return $info; } /** @@ -23,8 +33,8 @@ function charts_c3_charts_info() { */ function charts_c3_charts_type_info() { $chart_types['donut'] = [ - 'label' => t('Donut'), - 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, - ]; + 'label' => t('Donut'), + 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, + ]; return $chart_types; } diff --git a/modules/charts_c3/src/Charts/C3ChartsRender.php b/modules/charts_c3/src/Charts/C3ChartsRender.php index 7bf275cdd9209f8d63243aedf0476bda017f98b7..4d08dd6233fb94324f42f322cde42931896f1640 100644 --- a/modules/charts_c3/src/Charts/C3ChartsRender.php +++ b/modules/charts_c3/src/Charts/C3ChartsRender.php @@ -61,15 +61,19 @@ 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 b4bf849e9eed06c8437803e81f95e069b49faf48..db351ca0a7b14aac694e9eeac131957f5ed679ef 100644 --- a/modules/charts_c3/src/Plugin/chart/CThreeCharts.php +++ b/modules/charts_c3/src/Plugin/chart/CThreeCharts.php @@ -20,6 +20,22 @@ use Drupal\charts_c3\Settings\CThree\ChartAxis; */ class CThreeCharts extends AbstractChart { + /** + * Creates a JSON Object formatted for Google charts to use. + * + * @param mixed $options + * Options. + * @param mixed $categories + * Categories. + * @param mixed $seriesData + * Series data. + * @param mixed $attachmentDisplayOptions + * Attachment display options. + * @param mixed $variables + * Variables. + * @param mixed $chartId + * Chart Id. + */ public function buildVariables($options, $categories = [], $seriesData = [], $attachmentDisplayOptions = [], &$variables, $chartId) { $noAttachmentDisplays = count($attachmentDisplayOptions) === 0; $types = []; @@ -55,15 +71,19 @@ class CThreeCharts extends AbstractChart { } // 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'; +/* + $yAxis[$seriesData[1]['name']] = 'y2'; +*/ $showSecAxis['show'] = TRUE; $showSecAxis['label'] = $attachmentDisplayOptions[0]['style']['options']['yaxis_title']; $chartAxis->y2 = $showSecAxis; @@ -78,14 +98,14 @@ class CThreeCharts extends AbstractChart { array_push($c3Data, $categories); $chartData->setColumns($c3Data); } - else if ($options['type'] == 'column') { + elseif ($options['type'] == 'column') { $chartData->setType('bar'); $chartAxis->setRotated(FALSE); array_unshift($categories, 'x'); array_push($c3Data, $categories); $chartData->setColumns($c3Data); } - else if ($options['type'] == 'pie' || $options['type'] == 'donut') { + elseif ($options['type'] == 'pie' || $options['type'] == 'donut') { $chartData->setColumns($c3Data); } else { diff --git a/modules/charts_c3/src/Settings/CThree/ChartData.php b/modules/charts_c3/src/Settings/CThree/ChartData.php index 8c0d4b968e50ae5b001b7e9110e221e1962d25a6..8768a57637fb204b09fc424570741bf36926c576 100644 --- a/modules/charts_c3/src/Settings/CThree/ChartData.php +++ b/modules/charts_c3/src/Settings/CThree/ChartData.php @@ -25,7 +25,7 @@ class ChartData implements \JsonSerializable { /** * Set X. * - * @param array $x + * @param mixed $x * X. */ public function setX($x) { @@ -45,7 +45,7 @@ class ChartData implements \JsonSerializable { /** * Set Columns. * - * @param array $columns + * @param mixed $columns * Columns. */ public function setColumns($columns) { diff --git a/modules/charts_c3/src/Settings/CThree/ChartType.php b/modules/charts_c3/src/Settings/CThree/ChartType.php index 75321513c6d2d5eb8a5247cc5fcd6f554d9b8897..0b348a105536fc9f847d71bce25406ae55101e9a 100644 --- a/modules/charts_c3/src/Settings/CThree/ChartType.php +++ b/modules/charts_c3/src/Settings/CThree/ChartType.php @@ -33,6 +33,7 @@ class ChartType implements \JsonSerializable { * Json Serialize. * * @return array + * Json Serialize. */ public function jsonSerialize() { $vars = get_object_vars($this); diff --git a/modules/charts_google/js/charts_google.js b/modules/charts_google/js/charts_google.js index d72285bbe072df5e916fd37b1c64646b8d6b1f7a..db39601bd1fc0a78022654871abdfff9a2df3a29 100644 --- a/modules/charts_google/js/charts_google.js +++ b/modules/charts_google/js/charts_google.js @@ -36,7 +36,7 @@ /** * Helper function to draw Google Charts. * - * @param {boolean} reload Reload. + * @param {boolean} reload - Reload. */ Drupal.googleCharts.drawCharts = function (reload) { $('.charts-google').each(function () { @@ -66,11 +66,13 @@ /** * Helper function to draw a Google Chart. - * + * * @param {string} chartId - Chart Id. * @param {string} chartType - Chart Type. * @param {string} dataTable - Data. * @param {string} googleChartOptions - Options. + * + * @return {function} Draw Chart. */ Drupal.googleCharts.drawChart = function (chartId, chartType, dataTable, googleChartOptions) { return function () { diff --git a/modules/charts_google/src/Charts/GoogleChartsRender.php b/modules/charts_google/src/Charts/GoogleChartsRender.php index b83794a74390b563fffea3b4aaca00de8c11baa5..7e1022296486900a9fbd9ee6c2705248f84abfbd 100644 --- a/modules/charts_google/src/Charts/GoogleChartsRender.php +++ b/modules/charts_google/src/Charts/GoogleChartsRender.php @@ -7,8 +7,7 @@ use Drupal\charts\Util\Util; use Drupal\charts_google\Settings\Google\GoogleOptions; use Drupal\charts_google\Settings\Google\ChartType; use Drupal\charts_google\Settings\Google\ChartArea; -use Drupal\charts_google\Settings\Google\HorizontalAxis; -use Drupal\charts_google\Settings\Google\VerticalAxis; +use Drupal\charts_google\Settings\Google\ChartAxes; /** * Google Charts Render. @@ -47,7 +46,7 @@ class GoogleChartsRender implements ChartsRenderInterface { array_unshift($rowDataTable, $categories[$j]); array_push($dataTable, $rowDataTable); } - + $dataTableHeader = []; for ($r = 0; $r < $seriesCount; $r++) { array_push($dataTableHeader, $seriesData[$r]['name']); @@ -68,7 +67,7 @@ class GoogleChartsRender implements ChartsRenderInterface { /** * Create charts options. - * + * * @param array $options * Options. * @param array $seriesData @@ -77,7 +76,8 @@ class GoogleChartsRender implements ChartsRenderInterface { * Attachment Display Options. * * @return \Drupal\charts_google\Settings\Google\GoogleOptions - * GoogleOptions object with chart options or settings to be used by google visualization framework. + * GoogleOptions object with chart options or settings to be used by google + * visualization framework. */ private function createChartsOptions(array $options = [], array $seriesData = [], array $attachmentDisplayOptions = []) { $noAttachmentDisplays = count($attachmentDisplayOptions) === 0; @@ -85,7 +85,7 @@ class GoogleChartsRender implements ChartsRenderInterface { $chartSelected = []; $seriesTypes = []; - $firstVaxis = new VerticalAxis(); + $firstVaxis = new ChartAxes(); if (isset($options['yaxis_min'])) { $firstVaxis->setMinValue($options['yaxis_min']); @@ -154,7 +154,7 @@ class GoogleChartsRender implements ChartsRenderInterface { $firstVaxis->setViewWindowMode($options['yaxis_view_window_mode']); } - $firstHaxis = new HorizontalAxis(); + $firstHaxis = new ChartAxes(); if (isset($options['xaxis_min'])) { $firstHaxis->setMinValue($options['xaxis_min']); @@ -231,7 +231,7 @@ class GoogleChartsRender implements ChartsRenderInterface { // Sets secondary axis from the first attachment only. if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) { - $secondVaxis = new VerticalAxis(); + $secondVaxis = new ChartAxes(); $secondVaxis->setTitle($attachmentDisplayOptions[0]['style']['options']['yaxis_title']); array_push($vAxes, $secondVaxis); } @@ -249,7 +249,7 @@ class GoogleChartsRender implements ChartsRenderInterface { if ($attachmentDisplayOptions[$i]['inherit_yaxis'] == 0 && $i == 0) { $seriesTypes[$i + 1] = [ 'type' => $attachmentChartType, - 'targetAxisIndex' => 1 + 'targetAxisIndex' => 1, ]; } else { @@ -326,17 +326,18 @@ class GoogleChartsRender implements ChartsRenderInterface { } // 'legend' can be a string (for position) or an array with legend - // properties: [position: 'top', textStyle: [color: 'blue', fontSize: 16]] + // properties: [position: 'top', textStyle: [color: 'blue', fontSize: 16]]. if (isset($options['legend'])) { $googleOptions->setLegend($options['legend']); } // Set legend position. if (isset($options['legend_position'])) { - if(empty($options['legend_position'])) { + if (empty($options['legend_position'])) { $options['legend_position'] = 'none'; $googleOptions->setLegend($options['legend_position']); - } else { + } + else { $googleOptions->setLegend($options['legend_position']); } } @@ -346,7 +347,7 @@ class GoogleChartsRender implements ChartsRenderInterface { $googleOptions->setTitlePosition($options['title_position']); } - // Where to place the axis titles, compared to the chart area + // Where to place the axis titles, compared to the chart area. if (isset($options['axis_titles_position'])) { $googleOptions->setAxisTitlesPosition($options['axis_titles_position']); } diff --git a/modules/charts_google/src/Plugin/chart/GoogleCharts.php b/modules/charts_google/src/Plugin/chart/GoogleCharts.php index d6f0d86c19b175d6158262d10e14292b9675e068..67d42cba708438127645b05ac281da2d7379dc2d 100644 --- a/modules/charts_google/src/Plugin/chart/GoogleCharts.php +++ b/modules/charts_google/src/Plugin/chart/GoogleCharts.php @@ -6,8 +6,7 @@ use Drupal\charts\Plugin\chart\AbstractChart; use Drupal\charts_google\Settings\Google\GoogleOptions; use Drupal\charts_google\Settings\Google\ChartType; use Drupal\charts_google\Settings\Google\ChartArea; -use Drupal\charts_google\Settings\Google\HorizontalAxis; -use Drupal\charts_google\Settings\Google\VerticalAxis; +use Drupal\charts_google\Settings\Google\ChartAxes; /** * Define a concrete class for a Chart. @@ -30,7 +29,7 @@ class GoogleCharts extends AbstractChart { * Series data. * @param mixed $attachmentDisplayOptions * Attachment display options. - * @param mixed &$variables + * @param mixed $variables * Variables. * @param mixed $chartId * Chart Id. @@ -95,7 +94,7 @@ class GoogleCharts extends AbstractChart { $chartSelected = []; $seriesTypes = []; - $firstVaxis = new VerticalAxis(); + $firstVaxis = new ChartAxes(); if (isset($options['yaxis_min'])) { $firstVaxis->setMinValue($options['yaxis_min']); @@ -164,7 +163,7 @@ class GoogleCharts extends AbstractChart { $firstVaxis->setViewWindowMode($options['yaxis_view_window_mode']); } - $firstHaxis = new HorizontalAxis(); + $firstHaxis = new ChartAxes(); if (isset($options['xaxis_min'])) { $firstHaxis->setMinValue($options['xaxis_min']); @@ -241,7 +240,7 @@ class GoogleCharts extends AbstractChart { // Sets secondary axis from the first attachment only. if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) { - $secondVaxis = new VerticalAxis(); + $secondVaxis = new ChartAxes(); $secondVaxis->setTitle($attachmentDisplayOptions[0]['style']['options']['yaxis_title']); array_push($vAxes, $secondVaxis); } @@ -259,7 +258,7 @@ class GoogleCharts extends AbstractChart { if ($attachmentDisplayOptions[$i]['inherit_yaxis'] == 0 && $i == 0) { $seriesTypes[$i + 1] = [ 'type' => $attachmentChartType, - 'targetAxisIndex' => 1 + 'targetAxisIndex' => 1, ]; } else { @@ -336,7 +335,7 @@ class GoogleCharts extends AbstractChart { } // 'legend' can be a string (for position) or an array with legend - // properties: [position: 'top', textStyle: [color: 'blue', fontSize: 16]] + // properties: [position: 'top', textStyle: [color: 'blue', fontSize: 16]]. if (isset($options['legend'])) { $googleOptions->setLegend($options['legend']); } @@ -357,7 +356,7 @@ class GoogleCharts extends AbstractChart { $googleOptions->setTitlePosition($options['title_position']); } - // Where to place the axis titles, compared to the chart area + // Where to place the axis titles, compared to the chart area. if (isset($options['axis_titles_position'])) { $googleOptions->setAxisTitlesPosition($options['axis_titles_position']); } diff --git a/modules/charts_google/src/Settings/Google/ChartArea.php b/modules/charts_google/src/Settings/Google/ChartArea.php index 5461af3cf0dc9987e2b297d9f1e78e4c3ce7163f..3d4a930817cceb4cd1fb41907851d0b784bfc77f 100644 --- a/modules/charts_google/src/Settings/Google/ChartArea.php +++ b/modules/charts_google/src/Settings/Google/ChartArea.php @@ -11,21 +11,29 @@ class ChartArea implements \JsonSerializable { /** * Chart area width. + * + * @var mixed */ private $width; /** * Chart area height. + * + * @var mixed */ private $height; /** * How far to draw the chart from the top border. + * + * @var mixed */ private $top; /** * How far to draw the chart from the left border. + * + * @var mixed */ private $left; @@ -33,6 +41,7 @@ class ChartArea implements \JsonSerializable { * Gets the chart area width. * * @return mixed + * Width. */ public function getWidth() { return $this->width; @@ -42,6 +51,7 @@ class ChartArea implements \JsonSerializable { * Sets the chart area width. * * @param mixed $width + * Width. */ public function setWidth($width) { $this->width = $width; @@ -51,6 +61,7 @@ class ChartArea implements \JsonSerializable { * Gets the chart area height. * * @return mixed + * Height. */ public function getHeight() { return $this->height; @@ -60,6 +71,7 @@ class ChartArea implements \JsonSerializable { * Sets the chart area height. * * @param mixed $height + * Height. */ public function setHeight($height) { $this->height = $height; @@ -69,6 +81,7 @@ class ChartArea implements \JsonSerializable { * Gets how far to draw the chart from the top border. * * @return mixed + * Padding Top. */ public function getPaddingTop() { return $this->top; @@ -78,6 +91,7 @@ class ChartArea implements \JsonSerializable { * Sets how far to draw the chart from the top border. * * @param mixed $top + * Padding Top. */ public function setPaddingTop($top) { $this->top = $top; @@ -87,6 +101,7 @@ class ChartArea implements \JsonSerializable { * Gets how far to draw the chart from the left border. * * @return mixed + * Padding Left. */ public function getPaddingLeft() { return $this->left; @@ -96,13 +111,17 @@ class ChartArea implements \JsonSerializable { * Sets how far to draw the chart from the left border. * * @param mixed $left + * Padding Left. */ public function setPaddingLeft($left) { $this->left = $left; } /** + * Json Serialize. + * * @return array + * Json Serialize. */ public function jsonSerialize() { $vars = get_object_vars($this); diff --git a/modules/charts_google/src/Settings/Google/ChartAxis.php b/modules/charts_google/src/Settings/Google/ChartAxes.php similarity index 85% rename from modules/charts_google/src/Settings/Google/ChartAxis.php rename to modules/charts_google/src/Settings/Google/ChartAxes.php index 27afcbf4b146375a37b7ff3737b650312990bf62..d2a6f0607006ed8d0f44e5a2d175616a44cb5634 100644 --- a/modules/charts_google/src/Settings/Google/ChartAxis.php +++ b/modules/charts_google/src/Settings/Google/ChartAxes.php @@ -3,82 +3,120 @@ namespace Drupal\charts_google\Settings\Google; /** - * Class ChartAxis. + * Class ChartAxes. * * @package Drupal\charts_google\Settings\Google * * Chart Axis options are described here: * @see https://developers.google.com/chart/interactive/docs/gallery/columnchart#configuration-options */ -class ChartAxis implements \JsonSerializable { +class ChartAxes implements \JsonSerializable { /** * Chart Axis property that specifies a title for the axis. + * + * @var mixed */ private $title; /** * An array that specifies the axis title text style. + * + * @var mixed */ private $titleTextStyle; /** + * Baseline. + * * Chart Axis property that specifies the baseline for the axis. If the * baseline is larger than the highest grid line or smaller than the lowest * grid line, it will be rounded to the closest gridline. + * + * @var mixed */ private $baseline; /** + * Baseline Color. + * * Specifies the color of the baseline for the axis. Can be any HTML * color string, for example: 'red' or '#00cc00'. + * + * @var mixed */ private $baselineColor; /** + * Direction. + * * The direction in which the values along the axis grow. Specify -1 * to reverse the order of the values. + * + * @var mixed */ private $direction; /** * A format string for numeric axis labels. + * + * @var mixed */ private $format; /** + * Text Position. + * * Position of the axis text, relative to the chart area. * Supported values: 'out', 'in', 'none'. + * + * @var mixed */ private $textPosition; /** * An array that specifies the axis text style. + * + * @var mixed */ private $textStyle; /** + * Max Value. + * * Moves the max value of the axis to the specified value; this will * be upward in most charts. Ignored if this is set to a value smaller than * the maximum y-value of the data. + * + * @var mixed */ private $maxValue; /** + * Min Value. + * * Moves the min value of the axis to the specified value; this will * be downward in most charts. Ignored if this is set to a value greater than * the minimum y-value of the data. + * + * @var mixed */ private $minValue = 0; /** + * View Window Mode. + * * Specifies how to scale the axis to render the values within the * chart area. + * + * @var mixed */ private $viewWindowMode; /** * Specifies the cropping range of the axis. + * + * @var mixed */ private $viewWindow; @@ -86,6 +124,7 @@ class ChartAxis implements \JsonSerializable { * Get Chart Axis property that specifies a title for the axis. * * @return mixed + * Title. */ public function getTitle() { return $this->title; @@ -95,6 +134,7 @@ class ChartAxis implements \JsonSerializable { * Set Chart Axis property that specifies a title for the axis. * * @param $value + * Title. */ public function setTitle($value) { $this->title = $value; @@ -104,6 +144,7 @@ class ChartAxis implements \JsonSerializable { * Get an array that specifies the axis title text style. * * @return mixed + * Title Text Style. */ public function getTitleTextStyle() { return $this->titleTextStyle; @@ -113,6 +154,7 @@ class ChartAxis implements \JsonSerializable { * Set an array that specifies the axis title text style. * * @param mixed $value + * Title Text Style. */ public function setTitleTextStyle($value) { $this->titleTextStyle = $value; @@ -125,6 +167,7 @@ class ChartAxis implements \JsonSerializable { * Machine name of the text style property. * * @return mixed + * Title Text Style Value. */ public function getTitleTextStyleValue($key) { return isset($this->titleTextStyle[$key]) ? $this->titleTextStyle[$key] : NULL; @@ -146,6 +189,7 @@ class ChartAxis implements \JsonSerializable { * Get Chart Axis property that specifies the baseline for the axis. * * @return mixed + * Baseline. */ public function getBaseline() { return $this->baseline; @@ -155,6 +199,7 @@ class ChartAxis implements \JsonSerializable { * Set Chart Axis property that specifies the baseline for the axis. * * @param mixed $value + * Baseline. */ public function setBaseline($value) { $this->baseline = $value; @@ -164,6 +209,7 @@ class ChartAxis implements \JsonSerializable { * Get the color of the baseline for the axis. * * @return mixed + * Baseline Color. */ public function getBaselineColor() { return $this->baselineColor; @@ -173,6 +219,7 @@ class ChartAxis implements \JsonSerializable { * Set the color of the baseline for the axis. * * @param mixed $value + * Baseline Color. */ public function setBaselineColor($value) { $this->baselineColor = $value; @@ -182,6 +229,7 @@ class ChartAxis implements \JsonSerializable { * Get the direction in which the values along the axis grow. * * @return mixed + * Direction. */ public function getDirection() { return $this->direction; @@ -191,24 +239,27 @@ class ChartAxis implements \JsonSerializable { * Set the direction in which the values along the axis grow. * * @param mixed $value + * Direction. */ public function setDirection($value) { $this->direction = $value; } /** - * Get the format string for numeric axis labels + * Get the format string for numeric axis labels. * * @return mixed + * Format. */ public function getFormat() { return $this->format; } /** - * Set a format string for numeric axis labels + * Set a format string for numeric axis labels. * * @param mixed $value + * Format. */ public function setFormat($value) { $this->format = $value; @@ -218,6 +269,7 @@ class ChartAxis implements \JsonSerializable { * Get the position of the axis text, relative to the chart area. * * @return mixed + * Text Position. */ public function getTextPosition() { return $this->textPosition; @@ -227,6 +279,7 @@ class ChartAxis implements \JsonSerializable { * Set the position of the axis text, relative to the chart area. * * @param mixed $value + * Text Position. */ public function setTextPosition($value) { $this->textPosition = $value; @@ -236,6 +289,7 @@ class ChartAxis implements \JsonSerializable { * Get an array that specifies the axis text style. * * @return mixed + * Text Style. */ public function getTextStyle() { return $this->textStyle; @@ -245,6 +299,7 @@ class ChartAxis implements \JsonSerializable { * Set an array that specifies the axis text style. * * @param mixed $value + * Text Style. */ public function setTextStyle($value) { $this->textStyle = $value; @@ -257,6 +312,7 @@ class ChartAxis implements \JsonSerializable { * Machine name of the text style property. * * @return mixed + * Text Style Value. */ public function getTextStyleValue($key) { return isset($this->textStyle[$key]) ? $this->textStyle[$key] : NULL; @@ -278,6 +334,7 @@ class ChartAxis implements \JsonSerializable { * Get the max value of the axis. * * @return mixed + * Max Value. */ public function getMaxValue() { return $this->maxValue; @@ -287,6 +344,7 @@ class ChartAxis implements \JsonSerializable { * Set the max value of the axis. * * @param mixed $value + * Max Value. */ public function setMaxValue($value) { $this->maxValue = $value; @@ -296,6 +354,7 @@ class ChartAxis implements \JsonSerializable { * Get the min value of the axis. * * @return mixed + * Min Value. */ public function getMinValue() { return $this->minValue; @@ -305,26 +364,33 @@ class ChartAxis implements \JsonSerializable { * Set the min value of the axis. * * @param mixed $value + * Min Value. */ public function setMinValue($value) { $this->minValue = $value; } /** + * Get View Window Mode. + * * Get the value that specifies how to scale the axis to render the * values within the chart area. * * @return mixed + * View Window Mode. */ public function getViewWindowMode() { return $this->viewWindowMode; } /** + * Set View Window Mode. + * * Set the value that specifies how to scale the axis to render the * values within the chart area. * * @param mixed $value + * View Window Mode. */ public function setViewWindowMode($value) { $this->viewWindowMode = $value; @@ -334,6 +400,7 @@ class ChartAxis implements \JsonSerializable { * Get an array that specifies the cropping range of the axis. * * @return mixed + * View Window. */ public function getViewWindow() { return $this->viewWindow; @@ -343,12 +410,15 @@ class ChartAxis implements \JsonSerializable { * Set an array that specifies the cropping range of the axis. * * @param mixed $value + * View Window. */ public function setViewWindow($value) { $this->viewWindow = $value; } /** + * Get View Window Value. + * * Get an array property that specifies the the cropping range of the * axis. * @@ -356,12 +426,15 @@ class ChartAxis implements \JsonSerializable { * Property key. * * @return mixed + * View Window Value. */ public function getViewWindowValue($key) { return isset($this->viewWindow[$key]) ? $this->viewWindow[$key] : NULL; } /** + * Set View Window Value. + * * Set an array property that specifies the cropping range of the horizontal * axis. * @@ -375,7 +448,10 @@ class ChartAxis implements \JsonSerializable { } /** + * Json Serialize. + * * @return array + * Json Serialize. */ public function jsonSerialize() { $vars = get_object_vars($this); @@ -383,4 +459,3 @@ class ChartAxis implements \JsonSerializable { } } - diff --git a/modules/charts_google/src/Settings/Google/ChartType.php b/modules/charts_google/src/Settings/Google/ChartType.php index 972b1430d07bfd86a11c2b9f4f7058dd69ceb606..7388fe2afe974e8ce568ec5fd81fb87f0083a377 100644 --- a/modules/charts_google/src/Settings/Google/ChartType.php +++ b/modules/charts_google/src/Settings/Google/ChartType.php @@ -2,18 +2,28 @@ namespace Drupal\charts_google\Settings\Google; +/** + * Chart Type. + */ class ChartType implements \JsonSerializable { + private $type; /** + * Get Chart Type. + * * @return mixed + * Chart Type. */ public function getChartType() { return $this->type; } /** + * Chart Type. + * * @param mixed $type + * Chart Type. */ public function setChartType($type) { $ucType = ucfirst($type); @@ -21,7 +31,10 @@ class ChartType implements \JsonSerializable { } /** + * Json Serialize. + * * @return array + * Json Serialize. */ public function jsonSerialize() { $vars = get_object_vars($this); diff --git a/modules/charts_google/src/Settings/Google/GoogleOptions.php b/modules/charts_google/src/Settings/Google/GoogleOptions.php index 042b0351121dcbf322cd90e5498770fd1bde2b3a..ba63f1bee1752f470afe7d1a2eb1e050527e6b57 100644 --- a/modules/charts_google/src/Settings/Google/GoogleOptions.php +++ b/modules/charts_google/src/Settings/Google/GoogleOptions.php @@ -11,60 +11,92 @@ class GoogleOptions implements \JsonSerializable { /** * For Material Charts, this option specifies the title. + * + * @var mixed */ private $title; /** * For Material Charts, this option specifies the subtitle. + * + * @var mixed */ private $subTitle; /** * Where to place the chart title, compared to the chart area. + * + * @var mixed */ private $titlePosition; /** * Where to place the axis titles, compared to the chart area. + * + * @var mixed */ private $axisTitlesPosition; /** + * Chart Area. + * * An array with members to configure the placement and size of the chart * area. + * + * @var mixed */ private $chartArea; /** + * Horizontal Axes. + * * Specifies properties for individual horizontal axes, if the chart has * multiple horizontal axes. + * + * @var mixed */ private $hAxes; /** + * Vertical Axes. + * * An array with members to configure various vertical axis elements. + * + * @var mixed */ private $vAxes; /** + * Colors. + * * The colors to use for the chart elements. An array of strings, where each * element is an HTML color string + * + * @var mixed */ private $colors; /** + * Legend. + * * An array with members to configure various aspects of the legend. Or string * for the position of the legend. + * + * @var mixed */ private $legend; /** * Width of the chart, in pixels. + * + * @var mixed */ private $width; /** * Height of the chart, in pixels. + * + * @var mixed */ private $height; @@ -89,6 +121,8 @@ class GoogleOptions implements \JsonSerializable { } /** + * Get Subtitle. + * * Gets the subtitle of the Material Chart. Only Material Charts support * subtitle. * @@ -100,10 +134,13 @@ class GoogleOptions implements \JsonSerializable { } /** + * Set Subtitle. + * * Sets the subtitle of the Material Chart. Only Material Charts support * subtitle. * * @param string $title + * SubTitle. */ public function setSubTitle($title) { $this->subTitle = $title; @@ -113,6 +150,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the position of chart title. * * @return string + * Title Position. */ public function getTitlePosition() { return $this->titlePosition; @@ -127,6 +165,7 @@ class GoogleOptions implements \JsonSerializable { * - none: Omit the title. * * @param string $position + * Title Position. */ public function setTitlePosition($position) { $this->titlePosition = $position; @@ -136,6 +175,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the position of the axis titles. * * @return string + * Axis Titles Position. */ public function getAxisTitlesPosition() { return $this->axisTitlesPosition; @@ -150,6 +190,7 @@ class GoogleOptions implements \JsonSerializable { * - none: Omit the axis titles. * * @param string $position + * Position. */ public function setAxisTitlesPosition($position) { $this->axisTitlesPosition = $position; @@ -159,6 +200,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the chartArea property. * * @return mixed + * Chart Area. */ public function getChartArea() { return $this->chartArea; @@ -168,6 +210,7 @@ class GoogleOptions implements \JsonSerializable { * Sets the chartArea property. * * @param mixed $chartArea + * Chart Area. */ public function setChartArea($chartArea) { $this->chartArea = $chartArea; @@ -177,6 +220,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the horizontal axes. * * @return array + * Horizontal Axes. */ public function getHorizontalAxes() { return $this->hAxes; @@ -213,6 +257,8 @@ class GoogleOptions implements \JsonSerializable { } /** + * Get Colors. + * * Gets the colors to use for the chart elements. An array of strings, where * each element is an HTML color string. * @@ -224,6 +270,8 @@ class GoogleOptions implements \JsonSerializable { } /** + * Set Colors. + * * Sets the colors to use for the chart elements. An array of strings, where * each element is an HTML color string. * @@ -238,6 +286,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the Legend properties. * * @return mixed + * Legend. */ public function getLegend() { return $this->legend; @@ -255,10 +304,11 @@ class GoogleOptions implements \JsonSerializable { /** * Gets a Legend property. * - * @param $key + * @param mixed $key * Property key. * * @return mixed + * Legend Property. */ public function getLegendProperty($key) { return isset($this->legend[$key]) ? $this->legend[$key] : NULL; @@ -267,9 +317,9 @@ class GoogleOptions implements \JsonSerializable { /** * Sets a Legend property. * - * @param $key + * @param mixed $key * Property key. - * @param $value + * @param mixed $value * Property value. */ public function setLegendProperty($key, $value) { @@ -280,6 +330,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the width of the chart. * * @return mixed + * Width. */ public function getWidth() { return $this->width; @@ -299,6 +350,7 @@ class GoogleOptions implements \JsonSerializable { * Gets the height of the chart. * * @return mixed + * Height. */ public function getHeight() { return $this->height; @@ -315,8 +367,10 @@ class GoogleOptions implements \JsonSerializable { } /** + * Json Serialize. + * * @return array - * Get an array. + * Json Serialize. */ public function jsonSerialize() { $vars = get_object_vars($this); diff --git a/modules/charts_google/src/Settings/Google/HorizontalAxis.php b/modules/charts_google/src/Settings/Google/HorizontalAxis.php deleted file mode 100644 index 429933f098154d8833f2074cd2b0705d868b7f48..0000000000000000000000000000000000000000 --- a/modules/charts_google/src/Settings/Google/HorizontalAxis.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace Drupal\charts_google\Settings\Google; - -use Drupal\charts_google\Settings\Google\ChartAxis; - -/** - * Class HorizontalAxis. - * - * @package Drupal\charts_google\Settings\Google - * - * hAxis options are described here: - * @see https://developers.google.com/chart/interactive/docs/gallery/columnchart#configuration-options - */ -class HorizontalAxis extends ChartAxis { - -} diff --git a/modules/charts_google/src/Settings/Google/VerticalAxis.php b/modules/charts_google/src/Settings/Google/VerticalAxis.php deleted file mode 100644 index 57bfffa495c2de69a5d1fd2b51c6af3e44d2d4ff..0000000000000000000000000000000000000000 --- a/modules/charts_google/src/Settings/Google/VerticalAxis.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace Drupal\charts_google\Settings\Google; - -use Drupal\charts_google\Settings\Google\ChartAxis; - -/** - * Class VerticalAxis. - * - * @package Drupal\charts_google\Settings\Google - * - * vAxis options are described here: - * @see https://developers.google.com/chart/interactive/docs/gallery/columnchart#configuration-options - */ -class VerticalAxis extends ChartAxis { - -} diff --git a/modules/charts_highcharts/charts_highcharts.install b/modules/charts_highcharts/charts_highcharts.install index c5fce614a91b519bb6649fabe2b2c7f6e2865dce..c4ec3624e31b19391473d3ad43ca570bb663bd69 100644 --- a/modules/charts_highcharts/charts_highcharts.install +++ b/modules/charts_highcharts/charts_highcharts.install @@ -9,15 +9,15 @@ * Implements hook_requirements(). */ function charts_highcharts_requirements($phase) { - $requirements = array(); + $requirements = []; if (function_exists('libraries_detect') && $highcharts_info = libraries_detect('highcharts')) { if (is_dir($highcharts_info['library path'] . '/js/exporting-server')) { - $requirements['highcharts_security'] = array( - 'title' => t('Highcharts vulnerability'), - 'severity' => REQUIREMENT_ERROR, - 'value' => t('Dangerous sample code present'), - 'description' => t('Your installation of the Highcharts library at "@path" contains a directory named "exporting-server". This directory contains dangerous sample files that may compromise the security of your site. You must delete this directory before you may use the Charts Highcharts module.', array('@path' => $highcharts_info['library path'])), - ); + $requirements['highcharts_security'] = [ + 'title' => t('Highcharts vulnerability'), + 'severity' => REQUIREMENT_ERROR, + 'value' => t('Dangerous sample code present'), + 'description' => t('Your installation of the Highcharts library at "@path" contains a directory named "exporting-server". This directory contains dangerous sample files that may compromise the security of your site. You must delete this directory before you may use the Charts Highcharts module.', ['@path' => $highcharts_info['library path']]), + ]; } } diff --git a/modules/charts_highcharts/charts_highcharts.module b/modules/charts_highcharts/charts_highcharts.module index 73e5fe75c0da2883766b56d9d9fbf2eb0fc099d1..473f669a8e94dd7a2d1b23f420f23e89e0bb0e26 100644 --- a/modules/charts_highcharts/charts_highcharts.module +++ b/modules/charts_highcharts/charts_highcharts.module @@ -1,4 +1,5 @@ <?php + /** * @file * Charts module integration with Highcharts library. diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php index d28285a93d4ca97aa3ad2b3a2999b264a9e4caa6..4b768e61de4928b25afd8f1114930d18893fbba8 100644 --- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php +++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php @@ -44,7 +44,7 @@ class HighchartsChartsRender implements ChartsRenderInterface { if ($typeOptions == 'donut') { $typeOptions = 'pie'; // Remove donut from seriesData. - foreach ($seriesData as $key => &$value) { + foreach ($seriesData as &$value) { $value = str_replace('donut', 'pie', $value); } // Add innerSize to differentiate between donut and pie. @@ -136,7 +136,7 @@ class HighchartsChartsRender implements ChartsRenderInterface { $highchart = new Highcharts(); $highchart->setChart($chart); $highchart->setTitle($chartTitle); - $highchart->setXAxis($chartXaxis); + $highchart->setAxisX($chartXaxis); /* $highchart->yAxis = $yAxes; */ $highchart->setTooltip($chartTooltip); $highchart->setPlotOptions($plotOptions); diff --git a/modules/charts_highcharts/src/Plugin/chart/Highchart.php b/modules/charts_highcharts/src/Plugin/chart/Highchart.php index 9922807835e1d4b04d4f757549695ba068097126..4b17ca63fb90bdeb4f1cd2402274c5d0190c9d50 100644 --- a/modules/charts_highcharts/src/Plugin/chart/Highchart.php +++ b/modules/charts_highcharts/src/Plugin/chart/Highchart.php @@ -32,15 +32,20 @@ use Drupal\charts_highcharts\Settings\Highcharts\Highcharts; class Highchart extends AbstractChart { /** - * Creates a JSON Object formatted for Highcharts to use + * Creates a JSON Object formatted for Google charts to use. * - * @param $options - * @param array $categories - * @param array $seriesData - * - * @param array $attachmentDisplayOptions - * - * @return Highcharts object to be used by highcharts javascripts visualization framework + * @param mixed $options + * Options. + * @param mixed $categories + * Categories. + * @param mixed $seriesData + * Series data. + * @param mixed $attachmentDisplayOptions + * Attachment display options. + * @param mixed $variables + * Variables. + * @param mixed $chartId + * Chart Id. */ public function buildVariables($options, $categories = [], $seriesData = [], $attachmentDisplayOptions = [], &$variables, $chartId) { $noAttachmentDisplays = count($attachmentDisplayOptions) === 0; @@ -51,7 +56,7 @@ class Highchart extends AbstractChart { if ($typeOptions == 'donut') { $typeOptions = 'pie'; // Remove donut from seriesData. - foreach ($seriesData as $key => &$value) { + foreach ($seriesData as &$value) { $value = str_replace('donut', 'pie', $value); } // Add innerSize to differentiate between donut and pie. @@ -80,7 +85,7 @@ class Highchart extends AbstractChart { $chartTitle->setText($options['title']); } - $chartXaxis = new Xaxis(); + $chartXaxis = new Xaxis(); $chartLabels = new ChartLabel(); // Set x-axis label rotation. @@ -141,7 +146,7 @@ class Highchart extends AbstractChart { $highchart = new Highcharts(); $highchart->setChart($chart); $highchart->setTitle($chartTitle); - $highchart->setXAxis($chartXaxis); + $highchart->setAxisX($chartXaxis); /* $highchart->yAxis = $yAxes; */ $highchart->setTooltip($chartTooltip); $highchart->setPlotOptions($plotOptions); diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Chart.php b/modules/charts_highcharts/src/Settings/Highcharts/Chart.php index 90725c9877461304b40794551ef2778ded4e3550..4a02b0e5dd64171dfc6625c7d1da3111d005287a 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Chart.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Chart.php @@ -6,15 +6,16 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; * Chart. */ class Chart implements \JsonSerializable { - + private $type; private $width = NULL; private $height = NULL; - + /** * Get Type. * * @return string + * Type. */ public function getType() { return $this->type; @@ -24,6 +25,7 @@ class Chart implements \JsonSerializable { * Set Type. * * @param string $type + * Type. */ public function setType($type = '') { $this->type = $type; @@ -58,12 +60,12 @@ class Chart implements \JsonSerializable { * Get Height. * * @return int|null - * Height. + * Height. */ public function getHeight() { return $this->height; } - + /** * Set Height. * @@ -75,13 +77,13 @@ class Chart implements \JsonSerializable { $this->height = NULL; } else { - $this->height = (int)$height; + $this->height = (int) $height; } } - + /** * Json Serialize. - * + * * @return array * Variables. */ diff --git a/modules/charts_highcharts/src/Settings/Highcharts/ChartCredits.php b/modules/charts_highcharts/src/Settings/Highcharts/ChartCredits.php index bf179d8b2d98e9451ac4bac27621847746dcad11..59436a2f4cd1a1eaf3664c988e15293c756bf5b0 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/ChartCredits.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/ChartCredits.php @@ -12,7 +12,7 @@ class ChartCredits implements \JsonSerializable { /** * Is Enabled. * - * @return boolean + * @return bool * Enabled. */ public function isEnabled() { @@ -22,7 +22,7 @@ class ChartCredits implements \JsonSerializable { /** * Set Enabled. * - * @param boolean $enabled + * @param bool $enabled * Enabled. */ public function setEnabled($enabled) { diff --git a/modules/charts_highcharts/src/Settings/Highcharts/ChartLabel.php b/modules/charts_highcharts/src/Settings/Highcharts/ChartLabel.php index 3d4995ad9e33ef41908475f8f718c97eee327c42..009b67b21a9921f3c2eab2cc2dbb3fc2d17c8312 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/ChartLabel.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/ChartLabel.php @@ -26,7 +26,7 @@ class ChartLabel implements \JsonSerializable { * Rotation. */ public function setRotation($rotation) { - $this->rotation = (int)$rotation; + $this->rotation = (int) $rotation; } /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php b/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php index 2bf6f5bfc25690ff98d1945c474ac4281ab703a1..67efd52130e6fd4b844291f1c4d76eb1b6fbf78f 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php @@ -120,7 +120,7 @@ class ChartLegend implements \JsonSerializable { /** * Is Floating. * - * @return boolean + * @return bool * Floating. */ public function isFloating() { @@ -130,7 +130,7 @@ class ChartLegend implements \JsonSerializable { /** * Set Floating. * - * @param boolean $floating + * @param bool $floating * Floating. */ public function setFloating($floating) { @@ -180,7 +180,7 @@ class ChartLegend implements \JsonSerializable { /** * Is Shadow. * - * @return boolean + * @return bool * Shadow. */ public function isShadow() { @@ -190,7 +190,7 @@ class ChartLegend implements \JsonSerializable { /** * Set Shadow. * - * @param boolean $shadow + * @param bool $shadow * Shadow. */ public function setShadow($shadow) { diff --git a/modules/charts_highcharts/src/Settings/Highcharts/DataLabelStatus.php b/modules/charts_highcharts/src/Settings/Highcharts/DataLabelStatus.php index 305c97a5675e98d0b4e39cde1e49e9cf38297179..7dd954f795aafc08711e8dff435cc67c9d281f35 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/DataLabelStatus.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/DataLabelStatus.php @@ -12,7 +12,7 @@ class DataLabelStatus implements \JsonSerializable { /** * Is Enabled. * - * @return boolean + * @return bool * Enabled. */ public function isEnabled() { @@ -22,7 +22,7 @@ class DataLabelStatus implements \JsonSerializable { /** * Set Enabled. * - * @param boolean $enabled + * @param bool $enabled * Enabled. */ public function setEnabled($enabled) { diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php b/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php index 7d990dc7eca1dd29825fec2d885c8ef7062c18d5..ee34c06e5ae7fbfe27682f97cfd193438aea0e69 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php @@ -10,13 +10,13 @@ class Highcharts implements \JsonSerializable { private $chart; private $title; private $xAxis; - /* private $yAxis; */ private $tooltip; private $plotOptions; private $legend; private $credits; private $innerSize = '%20'; private $series; + /* private $yAxis; */ /** * Get Chart. @@ -64,7 +64,7 @@ class Highcharts implements \JsonSerializable { * @return mixed * X Axis. */ - public function getXAxis() { + public function getAxisX() { return $this->xAxis; } @@ -74,11 +74,11 @@ class Highcharts implements \JsonSerializable { * @param mixed $xAxis * X Axis. */ - public function setXAxis($xAxis) { + public function setAxisX($xAxis) { $this->xAxis = $xAxis; } - /* +/* @return mixed public function getYAxis() { return $this->yAxis; @@ -87,7 +87,7 @@ class Highcharts implements \JsonSerializable { public function setYAxis($yAxis) { $this->yAxis = $yAxis; } - */ +*/ /** * Get Tooltip. diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php b/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php index d30a0121075f492af1af8ea82a9b15bb816209b7..e846124a23a7c0aa8b6bdf46d417a2736c0fa62a 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php @@ -24,7 +24,7 @@ class Xaxis implements \JsonSerializable { /** * Set Categories. * - * @param array $categories + * @param mixed $categories * Categories. */ public function setCategories($categories) { diff --git a/modules/charts_highcharts/src/Settings/Highcharts/YaxisLabel.php b/modules/charts_highcharts/src/Settings/Highcharts/YaxisLabel.php index 0e6eac8d18b38e272f01b43f5ad22f73e2f37f52..caacf745487828c301b6e29011f4561cefb1664a 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/YaxisLabel.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/YaxisLabel.php @@ -6,7 +6,7 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; * Y Axis Label. */ class YaxisLabel implements \JsonSerializable { - + private $overflow = 'justify'; /** diff --git a/src/Annotation/Chart.php b/src/Annotation/Chart.php old mode 100755 new mode 100644 index 2b95c0e6286f7a526d51991239cd2b8dce6f1b5f..d6360ea1ccefa2c81b71701127a733e9a1f2cb64 --- a/src/Annotation/Chart.php +++ b/src/Annotation/Chart.php @@ -1,5 +1,7 @@ <?php + namespace Drupal\charts\Annotation; + use Drupal\Component\Annotation\Plugin; /** @@ -7,18 +9,20 @@ use Drupal\Component\Annotation\Plugin; * * @Annotation */ -class Chart extends Plugin{ - /** - * The plugin ID. - * - * @var string - */ - public $id; - /** - * The plugin name. - * - * @var string - */ - public $name; +class Chart extends Plugin { + + /** + * The plugin ID. + * + * @var string + */ + public $id; + + /** + * The plugin name. + * + * @var string + */ + public $name; -} \ No newline at end of file +} diff --git a/src/Plugin/chart/AbstractChart.php b/src/Plugin/chart/AbstractChart.php index a2422a97ff5017461ce723d1ee6a9f0dbbb14e4b..226f69e1431608b81b14fbb494506eea578d3be5 100644 --- a/src/Plugin/chart/AbstractChart.php +++ b/src/Plugin/chart/AbstractChart.php @@ -14,13 +14,6 @@ abstract class AbstractChart extends PluginBase implements ChartInterface, Conta use StringTranslationTrait; - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - /** * {@inheritdoc} */ diff --git a/src/Plugin/chart/ChartInterface.php b/src/Plugin/chart/ChartInterface.php old mode 100755 new mode 100644 index 22d64bee44ea8ef475a6b1758bdccbd85a906c79..a63b42787c0ba2881531a07b52dbffc24b84a98b --- a/src/Plugin/chart/ChartInterface.php +++ b/src/Plugin/chart/ChartInterface.php @@ -1,21 +1,27 @@ <?php + namespace Drupal\charts\Plugin\chart; + use Drupal\Component\Plugin\PluginInspectionInterface; + /** * Defines an interface for Chart plugins. */ -interface ChartInterface extends PluginInspectionInterface{ - /** - * Build Variables. - * - * @return an array - */ - public function buildVariables($options, $categories, $seriesData, $attachmentDisplayOptions, &$variables, $chartId); - /** - * Return the name of the chart. - * - * @return string - * returns the name as a string. - */ - public function getChartName(); -} \ No newline at end of file +interface ChartInterface extends PluginInspectionInterface { + + /** + * Build Variables. + * + * @return array + * Variables. + */ + public function buildVariables($options, $categories, $seriesData, $attachmentDisplayOptions, &$variables, $chartId); + + /** + * Return the name of the chart. + * + * @return string + * returns the name as a string. + */ + public function getChartName(); +} diff --git a/src/Plugin/chart/ChartManager.php b/src/Plugin/chart/ChartManager.php old mode 100755 new mode 100644 index f3e4c4ff2b32adaea48266891239c7428bbd031c..99520888ea1d8403b834547e7366741dee80ef7c --- a/src/Plugin/chart/ChartManager.php +++ b/src/Plugin/chart/ChartManager.php @@ -1,4 +1,5 @@ <?php + namespace Drupal\charts\Plugin\chart; use Drupal\Core\Plugin\DefaultPluginManager; @@ -6,25 +7,24 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; /** - * @file - * - * Provides the Chart plugin plugin manager and manages discovery and instantiation of chart plugins. - * + * Provides the Chart plugin plugin manager and manages discovery and + * instantiation of chart plugins. */ -class ChartManager extends DefaultPluginManager{ - /** - * Constructor for ChartManager objects. - * - * @param \Traversable $namespaces - * An object that implements \Traversable which contains the root paths - * keyed by the corresponding namespace to look for plugin implementations. - * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend - * Cache backend instance to use. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to invoke the alter hook with. - */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler){ - parent::__construct('Plugin/chart',$namespaces,$module_handler,'Drupal\charts\Plugin\chart\ChartInterface', - 'Drupal\charts\Annotation\Chart'); - } -} \ No newline at end of file +class ChartManager extends DefaultPluginManager { + + /** + * Constructor for ChartManager objects. + * + * @param \Traversable $namespaces + * An object that implements \Traversable which contains the root paths + * keyed by the corresponding namespace to look for plugin implementations. + * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend + * Cache backend instance to use. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke the alter hook with. + */ + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { + parent::__construct('Plugin/chart', $namespaces, $module_handler, 'Drupal\charts\Plugin\chart\ChartInterface', 'Drupal\charts\Annotation\Chart'); + } + +} diff --git a/src/Plugin/views/style/ChartsPluginStyleChart.php b/src/Plugin/views/style/ChartsPluginStyleChart.php index 98fc94395254380ccd48a4fc27509661e449ffe1..e7e2b9fc49516c0f544016a80635075f4753ba4f 100644 --- a/src/Plugin/views/style/ChartsPluginStyleChart.php +++ b/src/Plugin/views/style/ChartsPluginStyleChart.php @@ -107,7 +107,7 @@ class ChartsPluginStyleChart extends StylePluginBase { $dataFieldsCounter++; } - // If total sum of dataFieldsValueState is less than 1, then no dataFields + // If total sum of dataFieldsValueState is less than 1, then no dataFields // were selected otherwise 1 or more selected total sum will be greater // than 1. if (array_sum($dataFieldsValueState) < 1) { diff --git a/src/Services/ChartsSettingsService.php b/src/Services/ChartsSettingsService.php index d5c093fd2fc3b622b469f69c48539509f25c175f..08522474ac72cf852472cbe9c8d0e7d2952227a8 100644 --- a/src/Services/ChartsSettingsService.php +++ b/src/Services/ChartsSettingsService.php @@ -9,8 +9,8 @@ use Drupal\Core\Config\ConfigFactory; */ class ChartsSettingsService implements ChartsSettingsServiceInterface { - /* private $editableConfigName = 'charts.settings'; */ private $configFactory; + /* private $editableConfigName = 'charts.settings'; */ /** * Construct. @@ -30,4 +30,5 @@ class ChartsSettingsService implements ChartsSettingsServiceInterface { return $config->get('charts_default_settings'); } + } diff --git a/src/Theme/ChartsInterface.php b/src/Theme/ChartsInterface.php index 6b43398b46299db22fc77745de20c9d435bfd4e3..c01cbe7da9b67b73c6136806ec68b59036d0d83f 100644 --- a/src/Theme/ChartsInterface.php +++ b/src/Theme/ChartsInterface.php @@ -10,7 +10,7 @@ interface ChartsInterface { /** * Used to define a single axis. * - * Constant used in hook_charts_type_info() to declare chart types with a + * Constant used in hook_charts_type_info() to declare chart types with a * single axis. For example a pie chart only has a single dimension. */ const CHARTS_SINGLE_AXIS = 'y_only'; diff --git a/src/Util/Util.php b/src/Util/Util.php index c2560c3911512885a45167369c76c052ee4b1292..29e6f05a27312e75c7e26d78e2ed540ad6180628 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -117,7 +117,8 @@ class Util { public static function checkMissingLibrary($moduleName = '', $libraryPath = '') { $module_path = drupal_get_path('module', $moduleName); if (!file_exists($module_path . $libraryPath)) { - drupal_set_message($this->t('Charting libraries for ' . $moduleName . ' might not be installed. Run \'composer install\' for ' . $moduleName . ' sub-module.'), 'error'); + $text = 'Charting libraries for ' . $moduleName . ' might not be installed. Run \'composer install\' for ' . $moduleName . ' sub-module.'; + drupal_set_message($this->t($text), 'error'); } }