diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc index f4a9b9fed886f906daa667821bcb814a5f0be3d9..60cde8007088b32015572db28510a26569d34692 100644 --- a/includes/charts.pages.inc +++ b/includes/charts.pages.inc @@ -35,7 +35,8 @@ 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, ]; } @@ -88,33 +89,33 @@ function charts_get_type($chart_type) { function charts_charts_type_info() { return [ - 'pie' => [ + 'pie' => [ 'label' => t('Pie'), - 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, + 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, ], - 'bar' => [ - 'label' => t('Bar'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'bar' => [ + 'label' => t('Bar'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, 'axis_inverted' => TRUE, - 'stacking' => TRUE, + 'stacking' => TRUE, ], - 'column' => [ - 'label' => t('Column'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'column' => [ + 'label' => t('Column'), + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, 'stacking' => TRUE, ], - 'line' => [ + 'line' => [ 'label' => t('Line'), - 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, ], - 'area' => [ - 'label' => t('Area'), - '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, + 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, ], 'donut' => [ 'label' => t('Donut'), @@ -226,15 +227,15 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren } $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(); @@ -243,19 +244,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. @@ -273,26 +274,26 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren $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')], + '#type' => 'table', + '#header' => [t('Field Name'), t('Provides Data'), t('Color')], '#tabledrag' => [ [ - 'action' => 'order', + 'action' => 'order', 'relationship' => 'sibling', - 'group' => 'weight', + 'group' => 'weight', ], ], ]; @@ -300,135 +301,135 @@ 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'] = [ - '#type' => 'label', - '#title' => $field_label, + '#type' => 'label', + '#title' => $field_label, '#column' => 'one', ]; $form['fields']['table'][$field_count]['data_fields'][$field_name] = [ - '#type' => 'checkbox', - '#title' => $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', + '#title' => t('Display'), + '#type' => 'fieldset', '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#collapsed' => TRUE, ]; $form['display']['title'] = [ - '#title' => t('Chart title'), - '#type' => 'textfield', + '#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']['three_dimensional'] = [ - '#title' => t('Make chart three-dimensional (3D)'), - '#type' => 'checkbox', + '#title' => t('Make chart three-dimensional (3D)'), + '#type' => 'checkbox', '#default_value' => $options['three_dimensional'], - '#parents' => array_merge($parents, ['three_dimensional']), - '#attributes' => [ - 'class' => [ - 'chart-type-checkbox', - 'container-inline', - ], + '#parents' => array_merge($parents, ['three_dimensional']), + '#attributes' => [ + 'class' => [ + 'chart-type-checkbox', + 'container-inline', ], - ]; + ], + ]; $form['display']['polar'] = [ - '#title' => t('Transform cartesian charts into the polar coordinate system'), - '#type' => 'checkbox', + '#title' => t('Transform cartesian charts into the polar coordinate system'), + '#type' => 'checkbox', '#default_value' => $options['polar'], - '#parents' => array_merge($parents, ['polar']), - '#attributes' => [ - 'class' => [ + '#parents' => array_merge($parents, ['polar']), + '#attributes' => [ + 'class' => [ 'chart-type-checkbox', 'container-inline', ], @@ -436,165 +437,165 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren ]; $form['display']['dimensions'] = [ - '#title' => t('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, + '#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', + '#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', + '#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', + '#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', + '#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'), + '#title' => t('Value range'), '#theme_wrappers' => ['form_element'], ]; $form['yaxis']['minmax']['min'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'max' => 999999, + '#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, + '#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', + '#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', + '#title' => t('Value suffix'), + '#type' => 'textfield', '#default_value' => $options['yaxis_suffix'], - '#size' => 12, - '#parents' => array_merge($parents, ['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, + '#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; @@ -619,7 +620,7 @@ function charts_default_settings_form($form, $form_state) { // 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, ]; @@ -642,7 +643,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'), ]; @@ -658,7 +659,8 @@ function charts_default_settings_form($form, $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']); } /** @@ -669,33 +671,33 @@ function charts_default_settings_form_submit($form, $form_state) { */ function charts_default_settings() { $defaults = [ - 'type' => 'line', - 'library' => NULL, - 'grouping' => FALSE, - 'label_field' => NULL, - 'data_fields' => NULL, - 'field_colors' => NULL, - 'title' => '', - 'title_position' => 'out', - 'data_labels' => FALSE, - 'legend' => TRUE, - 'legend_position' => 'right', - 'colors' => charts_default_colors(), - 'background' => '', - 'three_dimensional' => FALSE, - 'polar' => FALSE, - 'tooltips' => TRUE, - 'tooltips_use_html' => FALSE, - 'width' => NULL, - 'height' => NULL, - 'xaxis_title' => '', + 'type' => 'line', + 'library' => NULL, + 'grouping' => FALSE, + 'label_field' => NULL, + 'data_fields' => NULL, + 'field_colors' => NULL, + 'title' => '', + 'title_position' => 'out', + 'data_labels' => FALSE, + 'legend' => TRUE, + 'legend_position' => 'right', + 'colors' => charts_default_colors(), + 'background' => '', + 'three_dimensional' => FALSE, + 'polar' => FALSE, + 'tooltips' => TRUE, + 'tooltips_use_html' => FALSE, + 'width' => NULL, + 'height' => NULL, + 'xaxis_title' => '', 'xaxis_labels_rotation' => 0, - 'yaxis_title' => '', - 'yaxis_min' => '', - 'yaxis_max' => '', - 'yaxis_prefix' => '', - 'yaxis_suffix' => '', - 'yaxis_decimal_count' => '', + 'yaxis_title' => '', + 'yaxis_min' => '', + 'yaxis_max' => '', + 'yaxis_prefix' => '', + 'yaxis_suffix' => '', + 'yaxis_decimal_count' => '', 'yaxis_labels_rotation' => 0, ]; diff --git a/modules/charts_api_example/charts_api_example.module b/modules/charts_api_example/charts_api_example.module index a86155320234729fe3e91279cb84a2459ae8d992..4e92f8c214d867d735e571aee14cfc6d7ff94036 100644 --- a/modules/charts_api_example/charts_api_example.module +++ b/modules/charts_api_example/charts_api_example.module @@ -28,13 +28,13 @@ function charts_api_example_help($route_name, RouteMatchInterface $route_match) function charts_api_example_theme() { return [ 'charts_api_example' => [ - 'template' => 'charts_api_example', + 'template' => 'charts_api_example', 'variables' => [ - 'library' => '', + 'library' => '', 'categories' => [], 'seriesData' => [], - 'options' => [], - 'id' => '', + 'options' => [], + 'id' => '', ], ], ]; diff --git a/modules/charts_api_example/composer.json b/modules/charts_api_example/composer.json index 840f1e5cd4fa3909c8d9000911d341955ce021e7..4fda52976629c1b22aefd17487a1da83196e0f6f 100644 --- a/modules/charts_api_example/composer.json +++ b/modules/charts_api_example/composer.json @@ -2,7 +2,9 @@ "name": "drupal/charts_api_example", "type": "drupal-module", "description": "How to interact with the Charts Api", - "keywords": ["Drupal"], + "keywords": [ + "Drupal" + ], "license": "GPL-2.0+", "homepage": "https://www.drupal.org/project/charts_api_example", "minimum-stability": "dev", @@ -10,5 +12,5 @@ "issues": "https://www.drupal.org/project/issues/charts_api_example", "source": "http://cgit.drupalcode.org/charts_api_example" }, - "require": { } + "require": {} } diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php index bc7186b0343cb6772909292027d4248ba27c9cce..47dabbe511a0e7610b6cf1d0606a81bba1814a63 100644 --- a/modules/charts_api_example/src/Controller/ChartsApiExample.php +++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php @@ -40,12 +40,12 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter // Customize options here. $options = [ - 'type' => $this->chartSettings['type'], - 'title' => $this->t('Chart title'), + 'type' => $this->chartSettings['type'], + 'title' => $this->t('Chart title'), 'xaxis_title' => $this->t('X-Axis'), 'yaxis_title' => $this->t('Y-Axis'), - 'yaxis_min' => '', - 'yaxis_max' => '', + 'yaxis_min' => '', + 'yaxis_max' => '', 'three_dimensional' => FALSE, 'title_position' => 'out', 'legend_position' => 'right', @@ -55,24 +55,24 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter // Sample data format. $categories = ['Category 1', 'Category 2', 'Category 3', 'Category 4']; $seriesData[] = [ - 'name' => 'Series 1', + 'name' => 'Series 1', 'color' => '#0d233a', - 'type' => NULL, - 'data' => [250, 350, 400, 200], + 'type' => NULL, + 'data' => [250, 350, 400, 200], ]; switch ($this->chartSettings['type']) { default: $seriesData[] = [ - 'name' => 'Series 2', + 'name' => 'Series 2', 'color' => '#8bbc21', - 'type' => 'column', - 'data' => [150, 450, 500, 300], - ]; + 'type' => 'column', + 'data' => [150, 450, 500, 300], + ]; $seriesData[] = [ - 'name' => 'Series 3', + 'name' => 'Series 3', 'color' => '#910000', - 'type' => 'area', - 'data' => [0, 0, 60, 90], + 'type' => 'area', + 'data' => [0, 0, 60, 90], ]; case 'pie': case 'donut': @@ -84,12 +84,12 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter $chartId = 'chart-' . $uuid_service->generate(); $build = [ - '#theme' => 'charts_api_example', - '#library' => (string) $library, + '#theme' => 'charts_api_example', + '#library' => (string) $library, '#categories' => $categories, '#seriesData' => $seriesData, - '#options' => $options, - '#id' => $chartId, + '#options' => $options, + '#id' => $chartId, ]; return $build; diff --git a/modules/charts_api_example/templates/charts_api_example.html.twig b/modules/charts_api_example/templates/charts_api_example.html.twig index 734319d20cbcd3ff4f8ae2edcf09f8284e8f91e6..f64b0829786f8b787d57cd79b4bc12212bb0485b 100644 --- a/modules/charts_api_example/templates/charts_api_example.html.twig +++ b/modules/charts_api_example/templates/charts_api_example.html.twig @@ -1,3 +1,4 @@ {% set library, height, width = 'charts_' ~ library ~ '/' ~ library, options.height, options.width %} {{ attach_library("#{ library }") }} -<div {{ attributes }} {{ content_attributes }} style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div> +<div {{ attributes }} {{ content_attributes }} + style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div> diff --git a/modules/charts_blocks/charts_blocks.module b/modules/charts_blocks/charts_blocks.module index f92ec69a2f197217e7cec60d50359017e7f9e01a..a9c1ed5f2851559ce6f8c03d25a09afa52972752 100644 --- a/modules/charts_blocks/charts_blocks.module +++ b/modules/charts_blocks/charts_blocks.module @@ -38,7 +38,7 @@ function charts_blocks_theme() { 'seriesData' => '', 'options' => '', 'id' => '', - ] + ], ], ]; } diff --git a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php index 0b32dd4fa6f53bb34fd548d4d449072a3d5690e6..a753870726bd58c1eefdf154acfd2617daceedcc 100644 --- a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php +++ b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php @@ -67,7 +67,7 @@ class ChartsBlock extends BlockBase { '#description' => $this->t('Enter the data for your chart, separated by comma: 1,3,5,7'), '#default_value' => $this->configuration['data'], '#weight' => '-19', - '#states' => [ + '#states' => [ 'invisible' => [ ':input[name="settings[series]"]' => ['checked' => TRUE], ], @@ -79,32 +79,32 @@ class ChartsBlock extends BlockBase { '#description' => $this->t('Provide a label for your legend'), '#default_value' => $this->configuration['series_label'], '#weight' => '-18', - '#states' => [ + '#states' => [ 'invisible' => [ ':input[name="settings[series]"]' => ['checked' => TRUE], ], ], ]; $form['color'] = [ - '#title' => $this->t('Color (single series)'), + '#title' => $this->t('Color (single series)'), '#theme_wrappers' => ['form_element'], - '#prefix' => '<div class="chart-colors">', - '#suffix' => '</div>', + '#prefix' => '<div class="chart-colors">', + '#suffix' => '</div>', '#weight' => '-17', - '#states' => [ + '#states' => [ 'invisible' => [ ':input[name="settings[series]"]' => ['checked' => TRUE], ], ], ]; $form['color'][0] = [ - '#type' => 'textfield', - '#attributes' => ['TYPE' => 'color'], - '#size' => 10, - '#maxlength' => 7, + '#type' => 'textfield', + '#attributes' => ['TYPE' => 'color'], + '#size' => 10, + '#maxlength' => 7, '#theme_wrappers' => [], - '#suffix' => ' ', - '#default_value' => $this->configuration['color'], + '#suffix' => ' ', + '#default_value' => $this->configuration['color'], ]; // If making a series chart, the API requires this format. @@ -114,7 +114,7 @@ class ChartsBlock extends BlockBase { '#description' => $this->t('Enter the data for your chart using this format (must be valid JSON): {"name":"Number of players","color":"#0d233a","data":[50,60,100,132,133,234]},{"name":"Number of coaches","color":"#ff0000","data":[50,80,100,32,133,234]}'), '#default_value' => $this->configuration['data_series'], '#weight' => '-17', - '#states' => [ + '#states' => [ 'invisible' => [ ':input[name="settings[series]"]' => ['checked' => FALSE], ], @@ -225,27 +225,80 @@ class ChartsBlock extends BlockBase { $this->configuration['categories'] = $form_state->getValue('categories'); $this->configuration['grouping'] = $form_state->getValue('grouping'); $this->configuration['field_colors'] = $form_state->getValue('field_colors'); - $this->configuration['title'] = $form_state->getValue(['display','title']); - $this->configuration['title_position'] = $form_state->getValue(['display','title_position']); - $this->configuration['data_labels'] = $form_state->getValue(['display','data_labels']); + $this->configuration['title'] = $form_state->getValue(['display', 'title']); + $this->configuration['title_position'] = $form_state->getValue([ + 'display', + 'title_position', + ]); + $this->configuration['data_labels'] = $form_state->getValue([ + 'display', + 'data_labels', + ]); $this->configuration['legend'] = $form_state->getValue('legend'); - $this->configuration['legend_position'] = $form_state->getValue(['display','legend_position']); - $this->configuration['background'] = $form_state->getValue(['display','background']); - $this->configuration['three_dimensional'] = $form_state->getValue(['display','three_dimensional']); - $this->configuration['polar'] = $form_state->getValue(['display','polar']); - $this->configuration['tooltips'] = $form_state->getValue(['display','tooltips']); + $this->configuration['legend_position'] = $form_state->getValue([ + 'display', + 'legend_position', + ]); + $this->configuration['background'] = $form_state->getValue([ + 'display', + 'background', + ]); + $this->configuration['three_dimensional'] = $form_state->getValue([ + 'display', + 'three_dimensional', + ]); + $this->configuration['polar'] = $form_state->getValue(['display', 'polar']); + $this->configuration['tooltips'] = $form_state->getValue([ + 'display', + 'tooltips', + ]); $this->configuration['tooltips_use_html'] = $form_state->getValue('tooltips_use_html'); - $this->configuration['width'] = $form_state->getValue(['display','dimensions','width']); - $this->configuration['height'] = $form_state->getValue(['display','dimensions','height']); - $this->configuration['xaxis_title'] = $form_state->getValue(['xaxis', 'xaxis_title']); - $this->configuration['xaxis_labels_rotation'] = $form_state->getValue(['xaxis', 'xaxis_labels_rotation']); - $this->configuration['yaxis_title'] = $form_state->getValue(['yaxis', 'yaxis_title']); - $this->configuration['yaxis_min'] = $form_state->getValue(['yaxis', 'yaxis_min']); - $this->configuration['yaxis_max'] = $form_state->getValue(['yaxis', 'yaxis_max']); - $this->configuration['yaxis_prefix'] = $form_state->getValue(['yaxis', 'yaxis_prefix']); - $this->configuration['yaxis_suffix'] = $form_state->getValue(['yaxis', 'yaxis_suffix']); - $this->configuration['yaxis_decimal_count'] = $form_state->getValue(['yaxis', 'yaxis_decimal_count']); - $this->configuration['yaxis_labels_rotation'] = $form_state->getValue(['yaxis', 'yaxis_labels_rotation']); + $this->configuration['width'] = $form_state->getValue([ + 'display', + 'dimensions', + 'width', + ]); + $this->configuration['height'] = $form_state->getValue([ + 'display', + 'dimensions', + 'height', + ]); + $this->configuration['xaxis_title'] = $form_state->getValue([ + 'xaxis', + 'xaxis_title', + ]); + $this->configuration['xaxis_labels_rotation'] = $form_state->getValue([ + 'xaxis', + 'xaxis_labels_rotation', + ]); + $this->configuration['yaxis_title'] = $form_state->getValue([ + 'yaxis', + 'yaxis_title', + ]); + $this->configuration['yaxis_min'] = $form_state->getValue([ + 'yaxis', + 'yaxis_min', + ]); + $this->configuration['yaxis_max'] = $form_state->getValue([ + 'yaxis', + 'yaxis_max', + ]); + $this->configuration['yaxis_prefix'] = $form_state->getValue([ + 'yaxis', + 'yaxis_prefix', + ]); + $this->configuration['yaxis_suffix'] = $form_state->getValue([ + 'yaxis', + 'yaxis_suffix', + ]); + $this->configuration['yaxis_decimal_count'] = $form_state->getValue([ + 'yaxis', + 'yaxis_decimal_count', + ]); + $this->configuration['yaxis_labels_rotation'] = $form_state->getValue([ + 'yaxis', + 'yaxis_labels_rotation', + ]); } @@ -255,17 +308,17 @@ class ChartsBlock extends BlockBase { public function build() { $categories = explode(",", $this->configuration['categories']); - $data = json_decode('[' . $this->configuration['data'] . ']', true); + $data = json_decode('[' . $this->configuration['data'] . ']', TRUE); if (!empty($this->configuration['data_series'])) { - $seriesData = json_decode('[' . $this->configuration['data_series'] . ']', true); + $seriesData = json_decode('[' . $this->configuration['data_series'] . ']', TRUE); } else { $seriesData = [ [ - 'name' => $this->configuration['series_label'], + 'name' => $this->configuration['series_label'], 'color' => $this->configuration['color'][0], - 'data' => $data + 'data' => $data, ], ]; } @@ -279,29 +332,29 @@ class ChartsBlock extends BlockBase { 'library' => $this->configuration['library'], 'type' => $this->configuration['type'], 'grouping' => $this->configuration['grouping'], - 'field_colors'=>$this->configuration['field_colors'], - 'colors'=>$defaults['colors'], - 'title'=>$this->configuration['title'], - 'title_position'=>$this->configuration['title_position'], - 'data_labels'=>$this->configuration['data_labels'], - 'legend'=>$this->configuration['legend'], - 'legend_position'=>$this->configuration['legend_position'], - 'background'=>$this->configuration['background'], - 'three_dimensional'=>$this->configuration['three_dimensional'], - 'polar'=>$this->configuration['polar'], - 'tooltips'=>$this->configuration['tooltips'], - 'tooltips_use_html'=>$this->configuration['tooltips_use_html'], - 'width'=>$this->configuration['width'], - 'height'=>$this->configuration['height'], - 'xaxis_title'=>$this->configuration['xaxis_title'], - 'xaxis_labels_rotation'=>$this->configuration['xaxis_labels_rotation'], - 'yaxis_title'=>$this->configuration['yaxis_title'], - 'yaxis_min'=>$this->configuration['yaxis_min'], - 'yaxis_max'=>$this->configuration['yaxis_max'], - 'yaxis_prefix'=>$this->configuration['yaxis_prefix'], - 'yaxis_suffix'=>$this->configuration['yaxis_suffix'], - 'yaxis_decimal_count'=>$this->configuration['yaxis_decimal_count'], - 'yaxis_labels_rotation'=>$this->configuration['yaxis_labels_rotation'] + 'field_colors' => $this->configuration['field_colors'], + 'colors' => $defaults['colors'], + 'title' => $this->configuration['title'], + 'title_position' => $this->configuration['title_position'], + 'data_labels' => $this->configuration['data_labels'], + 'legend' => $this->configuration['legend'], + 'legend_position' => $this->configuration['legend_position'], + 'background' => $this->configuration['background'], + 'three_dimensional' => $this->configuration['three_dimensional'], + 'polar' => $this->configuration['polar'], + 'tooltips' => $this->configuration['tooltips'], + 'tooltips_use_html' => $this->configuration['tooltips_use_html'], + 'width' => $this->configuration['width'], + 'height' => $this->configuration['height'], + 'xaxis_title' => $this->configuration['xaxis_title'], + 'xaxis_labels_rotation' => $this->configuration['xaxis_labels_rotation'], + 'yaxis_title' => $this->configuration['yaxis_title'], + 'yaxis_min' => $this->configuration['yaxis_min'], + 'yaxis_max' => $this->configuration['yaxis_max'], + 'yaxis_prefix' => $this->configuration['yaxis_prefix'], + 'yaxis_suffix' => $this->configuration['yaxis_suffix'], + 'yaxis_decimal_count' => $this->configuration['yaxis_decimal_count'], + 'yaxis_labels_rotation' => $this->configuration['yaxis_labels_rotation'], ]; // Creates a UUID for the chart ID. @@ -309,12 +362,12 @@ class ChartsBlock extends BlockBase { $chartId = 'chart-' . $uuid_service->generate(); $build = [ - '#theme' => 'charts_blocks', - '#library' => $this->configuration['library'], + '#theme' => 'charts_blocks', + '#library' => $this->configuration['library'], '#categories' => $categories, '#seriesData' => $seriesData, - '#options' => $options, - '#id' => $chartId, + '#options' => $options, + '#id' => $chartId, ]; return $build; diff --git a/modules/charts_blocks/templates/charts-block.html.twig b/modules/charts_blocks/templates/charts-block.html.twig index 734319d20cbcd3ff4f8ae2edcf09f8284e8f91e6..f64b0829786f8b787d57cd79b4bc12212bb0485b 100644 --- a/modules/charts_blocks/templates/charts-block.html.twig +++ b/modules/charts_blocks/templates/charts-block.html.twig @@ -1,3 +1,4 @@ {% set library, height, width = 'charts_' ~ library ~ '/' ~ library, options.height, options.width %} {{ attach_library("#{ library }") }} -<div {{ attributes }} {{ content_attributes }} style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div> +<div {{ attributes }} {{ content_attributes }} + style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div> diff --git a/modules/charts_c3/charts_c3.module b/modules/charts_c3/charts_c3.module index 2d73eac733a950d300aa4e7f36ecf1fb5091ef69..d241116f2b63a6f6962ed3be854133ae2ff6689f 100644 --- a/modules/charts_c3/charts_c3.module +++ b/modules/charts_c3/charts_c3.module @@ -34,7 +34,7 @@ function charts_c3_charts_info() { function charts_c3_charts_type_info() { $chart_types['donut'] = [ 'label' => t('Donut'), - 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, + 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, ]; return $chart_types; } diff --git a/modules/charts_c3/src/Plugin/chart/C3.php b/modules/charts_c3/src/Plugin/chart/C3.php index ca54b6ced70ba1ebb19167fc4db9322623fa8298..3619a36e267d09f2e7bdd3c72eb38c6d9d674fa3 100644 --- a/modules/charts_c3/src/Plugin/chart/C3.php +++ b/modules/charts_c3/src/Plugin/chart/C3.php @@ -90,7 +90,8 @@ class C3 extends AbstractChart { $seriesColor = $seriesData[$i]['color']; array_push($seriesColors, $seriesColor); } - } else { + } + else { $c3Data = []; for ($i = 0; $i < count($seriesData[0]['data']); $i++) { $c3DataTemp = $seriesData[0]['data'][$i]; diff --git a/modules/charts_c3/src/Settings/CThree/CThree.php b/modules/charts_c3/src/Settings/CThree/CThree.php index 80c820581067e10aee23359763acd8efa92e0dd6..ec81b4471135b72395bfab453356c53486b5da94 100644 --- a/modules/charts_c3/src/Settings/CThree/CThree.php +++ b/modules/charts_c3/src/Settings/CThree/CThree.php @@ -8,9 +8,13 @@ namespace Drupal\charts_c3\Settings\CThree; class CThree implements \JsonSerializable { private $color; + private $bindto; + private $data; + private $axis; + private $title; /** diff --git a/modules/charts_c3/src/Settings/CThree/ChartAxis.php b/modules/charts_c3/src/Settings/CThree/ChartAxis.php index c3bd2941f98b46f394b1dfb5f00a78292c0be58f..6ebd1d91255a280c0bd2f45f38f55da2b98e1420 100644 --- a/modules/charts_c3/src/Settings/CThree/ChartAxis.php +++ b/modules/charts_c3/src/Settings/CThree/ChartAxis.php @@ -8,6 +8,7 @@ namespace Drupal\charts_c3\Settings\CThree; class ChartAxis implements \JsonSerializable { private $rotated = FALSE; + private $x = ['type' => 'category']; /** diff --git a/modules/charts_c3/src/Settings/CThree/ChartData.php b/modules/charts_c3/src/Settings/CThree/ChartData.php index f92bebb2382f9b6b134c431ffdb5072761bfe3ba..661927f8c9f7c0d4826a6af1cea71b11a565894c 100644 --- a/modules/charts_c3/src/Settings/CThree/ChartData.php +++ b/modules/charts_c3/src/Settings/CThree/ChartData.php @@ -8,9 +8,13 @@ namespace Drupal\charts_c3\Settings\CThree; class ChartData implements \JsonSerializable { private $columns = []; + private $type; + private $labels = TRUE; + private $x = 'x'; + private $groups = ''; /** diff --git a/modules/charts_google/charts_google.module b/modules/charts_google/charts_google.module index f20e64125fd2b4f9f3c79c66ab75637af47fb7cb..50aa6c190cc3ef01d5fd4473ae3564afefe967ea 100644 --- a/modules/charts_google/charts_google.module +++ b/modules/charts_google/charts_google.module @@ -12,10 +12,10 @@ use Drupal\charts\Theme\ChartsInterface; */ function charts_google_charts_info() { $info['google'] = [ - 'label' => t('Google Charts'), + 'label' => t('Google Charts'), 'render' => '_charts_google_render', - 'types' => ['area', 'bar', 'column', 'donut', 'line', 'pie', 'scatter'], - 'file' => 'charts_google.inc', + 'types' => ['area', 'bar', 'column', 'donut', 'line', 'pie', 'scatter'], + 'file' => 'charts_google.inc', ]; return $info; } diff --git a/modules/charts_google/js/charts_google.js b/modules/charts_google/js/charts_google.js index db39601bd1fc0a78022654871abdfff9a2df3a29..21354d2c45d7494c23134cb2acf05907a5dc2dc1 100644 --- a/modules/charts_google/js/charts_google.js +++ b/modules/charts_google/js/charts_google.js @@ -35,7 +35,7 @@ /** * Helper function to draw Google Charts. - * + * * @param {boolean} reload - Reload. */ Drupal.googleCharts.drawCharts = function (reload) { diff --git a/modules/charts_google/src/Plugin/chart/Google.php b/modules/charts_google/src/Plugin/chart/Google.php index 5c19a823eb705c24d052b8275ece212d2690123d..560699ecf92289dc3d0185ebdcb883dcc03d6373 100644 --- a/modules/charts_google/src/Plugin/chart/Google.php +++ b/modules/charts_google/src/Plugin/chart/Google.php @@ -63,7 +63,7 @@ class Google extends AbstractChart { array_unshift($rowDataTable, $seriesData[$j]['name']); array_push($dataTable, $rowDataTable); } - $dataTableHeader = ['label','value']; + $dataTableHeader = ['label', 'value']; array_unshift($dataTable, $dataTableHeader); } else { @@ -297,7 +297,7 @@ class Google extends AbstractChart { if ($attachmentDisplayOptions[$i]['inherit_yaxis'] == 0 && $i == 0) { $seriesTypes[$i + 1] = [ - 'type' => $attachmentChartType, + 'type' => $attachmentChartType, 'targetAxisIndex' => 1, ]; } @@ -375,7 +375,8 @@ class Google extends AbstractChart { array_push($seriesColors, $seriesColor); } } - } else { + } + else { for ($i = 0; $i < $seriesCount; $i++) { $seriesColor = $seriesData[$i]['color']; array_push($seriesColors, $seriesColor); diff --git a/modules/charts_google/src/Settings/Google/GoogleOptions.php b/modules/charts_google/src/Settings/Google/GoogleOptions.php index 71925fe2ecc4a0757ca4ed26e6157ea93321f99e..7896f889a3ad71388c90557609eef8c3363a5d0a 100644 --- a/modules/charts_google/src/Settings/Google/GoogleOptions.php +++ b/modules/charts_google/src/Settings/Google/GoogleOptions.php @@ -101,10 +101,10 @@ class GoogleOptions implements \JsonSerializable { private $height; /** - * 3D chart option. - * - * @var mixed - */ + * 3D chart option. + * + * @var mixed + */ private $is3D; /** @@ -382,21 +382,21 @@ class GoogleOptions implements \JsonSerializable { } /** - * Gets three-dimensional chart option. - * - * @return mixed - * 3D option. - */ + * Gets three-dimensional chart option. + * + * @return mixed + * 3D option. + */ public function getThreeDimensional() { return $this->is3D; } /** - * Sets three-dimensional chart option. - * - * @param mixed $threeDimensional - * 3D option. - */ + * Sets three-dimensional chart option. + * + * @param mixed $threeDimensional + * 3D option. + */ public function setThreeDimensional($is3D) { $this->is3D = $is3D; } diff --git a/modules/charts_highcharts/charts_highcharts.install b/modules/charts_highcharts/charts_highcharts.install index c4ec3624e31b19391473d3ad43ca570bb663bd69..f088da72d1c39935aba245fa1723963b2419c54e 100644 --- a/modules/charts_highcharts/charts_highcharts.install +++ b/modules/charts_highcharts/charts_highcharts.install @@ -13,9 +13,9 @@ function charts_highcharts_requirements($phase) { if (function_exists('libraries_detect') && $highcharts_info = libraries_detect('highcharts')) { if (is_dir($highcharts_info['library path'] . '/js/exporting-server')) { $requirements['highcharts_security'] = [ - 'title' => t('Highcharts vulnerability'), - 'severity' => REQUIREMENT_ERROR, - 'value' => t('Dangerous sample code present'), + '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 473f669a8e94dd7a2d1b23f420f23e89e0bb0e26..d61c09044442448a2a9e6c6aece20c9b42b36aaf 100644 --- a/modules/charts_highcharts/charts_highcharts.module +++ b/modules/charts_highcharts/charts_highcharts.module @@ -12,10 +12,10 @@ use Drupal\charts\Theme\ChartsInterface; */ function charts_highcharts_charts_info() { $info['highcharts'] = [ - 'label' => t('Highcharts'), + 'label' => t('Highcharts'), 'render' => '_charts_highcharts_render', - 'types' => ['area', 'bar', 'column', 'donut', 'line', 'pie', 'scatter'], - 'file' => 'charts_highcharts.inc', + 'types' => ['area', 'bar', 'column', 'donut', 'line', 'pie', 'scatter'], + 'file' => 'charts_highcharts.inc', ]; return $info; @@ -27,7 +27,7 @@ function charts_highcharts_charts_info() { function charts_highcharts_charts_type_info() { $chart_types['donut'] = [ 'label' => t('Donut'), - 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, + 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, ]; return $chart_types; } diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Chart.php b/modules/charts_highcharts/src/Settings/Highcharts/Chart.php index 2374629dc1ad9b23f3cafd53374171276b3932f9..ff1c5efaef7bd7a1064763ddbb2a27bf2544f2d8 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Chart.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Chart.php @@ -8,10 +8,15 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class Chart implements \JsonSerializable { private $type; + private $width = NULL; + private $height = NULL; + private $backgroundColor; + private $polar = NULL; + private $options3d; /** @@ -105,21 +110,21 @@ class Chart implements \JsonSerializable { } /** - * Get Polar - * - * @return bool - * Polar. - */ + * Get Polar + * + * @return bool + * Polar. + */ public function getPolar() { return $this->polar; } /** - * Set Polar. - * - * @param bool $polar - * Polar. - */ + * Set Polar. + * + * @param bool $polar + * Polar. + */ public function setPolar($polar) { $this->polar = $polar; } diff --git a/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php b/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php index 968e04dd2b1ccf0f29908546606d2fe68de616f0..7d4a206e4d2fa3eea6d596534570f53c2df2d6bd 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/ChartLegend.php @@ -8,13 +8,21 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class ChartLegend implements \JsonSerializable { private $layout = 'vertical'; + private $align = 'right'; + private $verticalAlign = 'top'; + private $x = 0; + private $y = 0; + private $floating = TRUE; + private $borderWidth = 1; + private $backgroundColor = '#FCFFC5'; + private $shadow = TRUE; /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/ChartTitle.php b/modules/charts_highcharts/src/Settings/Highcharts/ChartTitle.php index bbe05e92a6776e72e4ed887a251d7e95e303167c..3a24d4814f79a2ad2cb5413dd9a48b9a5bff2ca2 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/ChartTitle.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/ChartTitle.php @@ -8,7 +8,9 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class ChartTitle implements \JsonSerializable { private $text; + private $y; + private $verticalAlign; /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/HighchartsOptions.php b/modules/charts_highcharts/src/Settings/Highcharts/HighchartsOptions.php index a2a358a81bd2fda42c82b0ee048a74b819cb8091..e6e2cae6a9a972e89222aee210775a19dc90857d 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/HighchartsOptions.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/HighchartsOptions.php @@ -8,15 +8,25 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class HighchartsOptions implements \JsonSerializable { private $chart; + private $title; + private $xAxis; + private $yAxis; + private $tooltip; + private $plotOptions; + private $legend; + private $credits; + private $innerSize = '%20'; + private $series; + private $exporting; /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php b/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php index 58252e97c57a3499a9b017c19b8c9a267fcff4a5..16cb92eace8d7cb843fec03b69b3bac8e7c9f356 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php @@ -8,6 +8,7 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class PlotOptionsStacking implements \JsonSerializable { private $dataLabels; + private $stacking = 'normal'; /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/ThreeDimensionalOptions.php b/modules/charts_highcharts/src/Settings/Highcharts/ThreeDimensionalOptions.php index 660ab2972249a60088294af598d8ffffe7ce5b12..7b7673ba6e2a08d208e49e1038dd7a292a30bd1e 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/ThreeDimensionalOptions.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/ThreeDimensionalOptions.php @@ -5,9 +5,11 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class ThreeDimensionalOptions implements \JsonSerializable { -private $enabled = TRUE; -private $alpha = 45; -private $beta = 0; + private $enabled = TRUE; + + private $alpha = 45; + + private $beta = 0; /** * Get enabled value. diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Tooltip.php b/modules/charts_highcharts/src/Settings/Highcharts/Tooltip.php index 1e34c9750f7d1b862b03fa3fbcbd95009197a679..f5beaffeaecd3f7e776d8f61fb3dfe32f9dc46ce 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Tooltip.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Tooltip.php @@ -8,6 +8,7 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class Tooltip implements \JsonSerializable { private $valueSuffix = ''; + private $enabled = FALSE; /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php b/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php index e846124a23a7c0aa8b6bdf46d417a2736c0fa62a..d77cfc89ad55596faf2e70b994d48cef1613aac6 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Xaxis.php @@ -8,7 +8,9 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class Xaxis implements \JsonSerializable { private $categories = []; + private $title; + private $labels; /** diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Yaxis.php b/modules/charts_highcharts/src/Settings/Highcharts/Yaxis.php index 90e2fa625f254a16fad07c694b6671a829ed816b..7eed04c7661d439790ee49a00f5bec078bd12672 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Yaxis.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Yaxis.php @@ -8,6 +8,7 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; class Yaxis implements \JsonSerializable { private $title; + private $labels = ''; /** diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php index 1d9d853298179fca5d99020da7f3a515d0e39bcf..37cf172c31d9895cc4e53f74a8c173c07f70951b 100644 --- a/src/Form/ChartsConfigForm.php +++ b/src/Form/ChartsConfigForm.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class ChartsConfigForm extends ConfigFormBase { protected $moduleHandler; + protected $config; /** @@ -64,13 +65,16 @@ class ChartsConfigForm extends ConfigFormBase { $field_options = []; $form['help'] = [ - '#type' => 'markup', + '#type' => 'markup', '#prefix' => '<p>', '#suffix' => '</p>', '#markup' => $this->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="@create">create a new view</a> and select - the display format of "Chart".', ['@create' => Url::fromRoute('views_ui.add')->toString()]), + the display format of "Chart".', [ + '@create' => Url::fromRoute('views_ui.add') + ->toString(), + ]), '#weight' => -100, ]; // Reuse the global settings form for defaults, but remove JS classes. @@ -86,10 +90,10 @@ class ChartsConfigForm extends ConfigFormBase { $form['defaults'] = ['#type' => 'vertical_tabs']; // Add submit buttons and normal saving behavior. $form['actions'] = [ - '#type' => 'actions', + '#type' => 'actions', 'submit' => [ - '#type' => 'submit', - '#value' => $this->t('Save defaults'), + '#type' => 'submit', + '#value' => $this->t('Save defaults'), '#button_type' => 'primary', ], ]; @@ -104,30 +108,30 @@ class ChartsConfigForm extends ConfigFormBase { */ public function chartsDefaultSettings() { $defaults = [ - 'type' => 'line', - 'library' => NULL, - 'label_field' => NULL, - 'data_fields' => NULL, - 'field_colors' => NULL, - 'title' => '', - 'title_position' => 'out', - 'legend' => TRUE, - 'legend_position' => 'right', - 'colors' => $this->chartsDefaultColors(), - 'background' => '', - 'three_dimensional' => FALSE, - 'tooltips' => TRUE, - 'tooltips_use_html' => FALSE, - 'width' => NULL, - 'height' => NULL, - 'xaxis_title' => '', + 'type' => 'line', + 'library' => NULL, + 'label_field' => NULL, + 'data_fields' => NULL, + 'field_colors' => NULL, + 'title' => '', + 'title_position' => 'out', + 'legend' => TRUE, + 'legend_position' => 'right', + 'colors' => $this->chartsDefaultColors(), + 'background' => '', + 'three_dimensional' => FALSE, + 'tooltips' => TRUE, + 'tooltips_use_html' => FALSE, + 'width' => NULL, + 'height' => NULL, + 'xaxis_title' => '', 'xaxis_labels_rotation' => 0, - 'yaxis_title' => '', - 'yaxis_min' => '', - 'yaxis_max' => '', - 'yaxis_prefix' => '', - 'yaxis_suffix' => '', - 'yaxis_decimal_count' => '', + 'yaxis_title' => '', + 'yaxis_min' => '', + 'yaxis_max' => '', + 'yaxis_prefix' => '', + 'yaxis_suffix' => '', + 'yaxis_decimal_count' => '', 'yaxis_labels_rotation' => 0, ]; @@ -188,15 +192,15 @@ class ChartsConfigForm extends ConfigFormBase { drupal_set_message($this->t('There are no enabled charting libraries. Please enable a Charts sub-module.')); } $form['library'] = [ - '#title' => $this->t('Charting library'), - '#type' => 'select', - '#options' => $library_options, + '#title' => $this->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']), ]; // This is a work around will need to revisit this. @@ -207,13 +211,13 @@ class ChartsConfigForm extends ConfigFormBase { } $form['type'] = [ - '#title' => $this->t('Chart type'), - '#type' => 'radios', + '#title' => $this->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', @@ -236,31 +240,31 @@ class ChartsConfigForm extends ConfigFormBase { $first_field = key($field_options); /* $form['fields']['#theme'] = 'charts_settings_fields'; */ $form['fields']['label_field'] = [ - '#type' => 'radios', - '#title' => $this->t('Label field'), - '#options' => $field_options + ['' => $this->t('No label field')], + '#type' => 'radios', + '#title' => $this->t('Label field'), + '#options' => $field_options + ['' => $this->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']['data_fields'] = [ - '#type' => 'checkboxes', - '#title' => $this->t('Data fields'), - '#options' => $field_options, + '#type' => 'checkboxes', + '#title' => $this->t('Data fields'), + '#options' => $field_options, '#default_value' => isset($options['data_fields']) ? $options['data_fields'] : array_diff(array_keys($field_options), [$first_field]), - '#weight' => -9, - '#parents' => array_merge($parents, ['data_fields']), + '#weight' => -9, + '#parents' => array_merge($parents, ['data_fields']), ]; $color_count = 0; foreach ($field_options as $field_name => $field_label) { $form['fields']['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'][$color_count], - '#parents' => array_merge($parents, [ + '#default_value' => !empty($options['field_colors'][$field_name]) ? $options['field_colors'][$field_name] : $options['colors'][$color_count], + '#parents' => array_merge($parents, [ 'field_colors', $field_name, ]), @@ -271,92 +275,92 @@ class ChartsConfigForm extends ConfigFormBase { // Enable stacking. $form['grouping'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Stacking'), - '#description' => $this->t('Enable stacking'), + '#type' => 'checkbox', + '#title' => $this->t('Stacking'), + '#description' => $this->t('Enable stacking'), '#default_value' => $options['grouping'], - '#weight' => '-15', - '#parents' => array_merge($parents, ['grouping']), + '#weight' => '-15', + '#parents' => array_merge($parents, ['grouping']), ]; $form['display'] = [ - '#title' => $this->t('Display'), - '#type' => 'details', + '#title' => $this->t('Display'), + '#type' => 'details', '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#collapsed' => TRUE, ]; $form['display']['title'] = [ - '#title' => $this->t('Chart title'), - '#type' => 'textfield', + '#title' => $this->t('Chart title'), + '#type' => 'textfield', '#default_value' => $options['title'], - '#parents' => array_merge($parents, ['title']), + '#parents' => array_merge($parents, ['title']), ]; $form['display']['title_position'] = [ - '#title' => $this->t('Title position'), - '#type' => 'select', - '#options' => [ - '' => $this->t('None'), + '#title' => $this->t('Title position'), + '#type' => 'select', + '#options' => [ + '' => $this->t('None'), 'out' => $this->t('Outside'), - 'in' => $this->t('Inside'), + 'in' => $this->t('Inside'), ], '#default_value' => $options['title_position'], - '#parents' => array_merge($parents, ['title_position']), + '#parents' => array_merge($parents, ['title_position']), ]; $form['display']['legend_position'] = [ - '#title' => $this->t('Legend position'), - '#type' => 'select', - '#options' => [ - '' => $this->t('None'), - 'top' => $this->t('Top'), - 'right' => $this->t('Right'), + '#title' => $this->t('Legend position'), + '#type' => 'select', + '#options' => [ + '' => $this->t('None'), + 'top' => $this->t('Top'), + 'right' => $this->t('Right'), 'bottom' => $this->t('Bottom'), - 'left' => $this->t('Left'), + 'left' => $this->t('Left'), ], '#default_value' => $options['legend_position'], - '#parents' => array_merge($parents, ['legend_position']), + '#parents' => array_merge($parents, ['legend_position']), ]; $form['display']['colors'] = [ - '#title' => $this->t('Chart colors'), + '#title' => $this->t('Chart colors'), '#theme_wrappers' => ['form_element'], - '#prefix' => '<div class="chart-colors">', - '#suffix' => '</div>', + '#prefix' => '<div class="chart-colors">', + '#suffix' => '</div>', ]; for ($color_count = 0; $color_count < 10; $color_count++) { $form['display']['colors'][$color_count] = [ - '#type' => 'textfield', - '#attributes' => ['TYPE' => 'color'], - '#size' => 10, - '#maxlength' => 7, + '#type' => 'textfield', + '#attributes' => ['TYPE' => 'color'], + '#size' => 10, + '#maxlength' => 7, '#theme_wrappers' => [], - '#suffix' => ' ', - '#default_value' => $options['colors'][$color_count], - '#parents' => array_merge($parents, ['colors', $color_count]), + '#suffix' => ' ', + '#default_value' => $options['colors'][$color_count], + '#parents' => array_merge($parents, ['colors', $color_count]), ]; } $form['display']['background'] = [ - '#title' => $this->t('Background color'), - '#type' => 'textfield', - '#size' => 10, - '#maxlength' => 7, - '#attributes' => ['placeholder' => $this->t('transparent')], - '#description' => $this->t('Leave blank for a transparent background.'), + '#title' => $this->t('Background color'), + '#type' => 'textfield', + '#size' => 10, + '#maxlength' => 7, + '#attributes' => ['placeholder' => $this->t('transparent')], + '#description' => $this->t('Leave blank for a transparent background.'), '#default_value' => $options['background'], - '#parents' => array_merge($parents, ['background']), + '#parents' => array_merge($parents, ['background']), ]; $form['display']['three_dimensional'] = [ - '#title' => t('Make chart three-dimensional (3D)'), - '#type' => 'checkbox', + '#title' => t('Make chart three-dimensional (3D)'), + '#type' => 'checkbox', '#default_value' => $options['three_dimensional'], - '#parents' => array_merge($parents, ['three_dimensional']), - '#attributes' => [ - 'class' => [ + '#parents' => array_merge($parents, ['three_dimensional']), + '#attributes' => [ + 'class' => [ 'chart-type-checkbox', 'container-inline', ], @@ -364,12 +368,12 @@ class ChartsConfigForm extends ConfigFormBase { ]; $form['display']['polar'] = [ - '#title' => t('Transform cartesian charts into the polar coordinate system'), - '#type' => 'checkbox', + '#title' => t('Transform cartesian charts into the polar coordinate system'), + '#type' => 'checkbox', '#default_value' => $options['polar'], - '#parents' => array_merge($parents, ['polar']), - '#attributes' => [ - 'class' => [ + '#parents' => array_merge($parents, ['polar']), + '#attributes' => [ + 'class' => [ 'chart-type-checkbox', 'container-inline', ], @@ -377,168 +381,168 @@ class ChartsConfigForm extends ConfigFormBase { ]; $form['display']['dimensions'] = [ - '#title' => $this->t('Dimensions'), + '#title' => $this->t('Dimensions'), '#theme_wrappers' => ['form_element'], - '#description' => $this->t('If dimensions are left empty, the chart will fill its containing element.'), + '#description' => $this->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, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 9999, 'placeholder' => $this->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' => $this->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' => $this->t('Horizontal axis'), - '#type' => 'details', + '#title' => $this->t('Horizontal axis'), + '#type' => 'details', '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#attributes' => ['class' => ['chart-xaxis']], + '#collapsed' => TRUE, + '#attributes' => ['class' => ['chart-xaxis']], ]; $form['xaxis']['title'] = [ - '#title' => $this->t('Custom title'), - '#type' => 'textfield', + '#title' => $this->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' => $this->t('Labels rotation'), - '#type' => 'select', - '#options' => [ - 0 => $this->t('0°'), + '#title' => $this->t('Labels rotation'), + '#type' => 'select', + '#options' => [ + 0 => $this->t('0°'), 30 => $this->t('30°'), 45 => $this->t('45°'), 60 => $this->t('60°'), 90 => $this->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' => $this->t('Vertical axis'), - '#type' => 'details', + '#title' => $this->t('Vertical axis'), + '#type' => 'details', '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#attributes' => ['class' => ['chart-yaxis']], + '#collapsed' => TRUE, + '#attributes' => ['class' => ['chart-yaxis']], ]; $form['yaxis']['title'] = [ - '#title' => $this->t('Custom title'), - '#type' => 'textfield', + '#title' => $this->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' => $this->t('Value range'), + '#title' => $this->t('Value range'), '#theme_wrappers' => ['form_element'], ]; $form['yaxis']['minmax']['min'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'max' => 999999, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'max' => 999999, 'placeholder' => $this->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, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'max' => 999999, 'placeholder' => $this->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' => $this->t('Value prefix'), - '#type' => 'textfield', + '#title' => $this->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' => $this->t('Value suffix'), - '#type' => 'textfield', + '#title' => $this->t('Value suffix'), + '#type' => 'textfield', '#default_value' => $options['yaxis_suffix'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_suffix']), + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_suffix']), ]; $form['yaxis']['decimal_count'] = [ - '#title' => $this->t('Decimal count'), - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 20, + '#title' => $this->t('Decimal count'), + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 20, 'placeholder' => $this->t('auto'), ], '#default_value' => $options['yaxis_decimal_count'], - '#size' => 5, - '#description' => $this->t('Enforce a certain number of decimal-place digits in displayed values.'), - '#parents' => array_merge($parents, ['yaxis_decimal_count']), + '#size' => 5, + '#description' => $this->t('Enforce a certain number of decimal-place digits in displayed values.'), + '#parents' => array_merge($parents, ['yaxis_decimal_count']), ]; $form['yaxis']['labels_rotation'] = [ - '#title' => $this->t('Labels rotation'), - '#type' => 'select', - '#options' => [ - 0 => $this->t('0°'), + '#title' => $this->t('Labels rotation'), + '#type' => 'select', + '#options' => [ + 0 => $this->t('0°'), 30 => $this->t('30°'), 45 => $this->t('45°'), 60 => $this->t('60°'), 90 => $this->t('90°'), ], - '#attributes' => [ + '#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; diff --git a/src/Plugin/chart/AbstractChart.php b/src/Plugin/chart/AbstractChart.php index 226f69e1431608b81b14fbb494506eea578d3be5..a2ea81c519a734c6b74b845438d039c078a1beb9 100644 --- a/src/Plugin/chart/AbstractChart.php +++ b/src/Plugin/chart/AbstractChart.php @@ -19,7 +19,7 @@ abstract class AbstractChart extends PluginBase implements ChartInterface, Conta */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( - $configuration, $plugin_id, $plugin_definition + $configuration, $plugin_id, $plugin_definition ); } diff --git a/src/Plugin/views/display/ChartsPluginDisplayChart.php b/src/Plugin/views/display/ChartsPluginDisplayChart.php index b532418dcf266d6ae85d5990fbd973a0e3c8774f..a24b2dca15040880ecfa34ff8db2122475343123 100644 --- a/src/Plugin/views/display/ChartsPluginDisplayChart.php +++ b/src/Plugin/views/display/ChartsPluginDisplayChart.php @@ -46,9 +46,9 @@ class ChartsPluginDisplayChart extends Attachment { parent::optionsSummary($categories, $options); $categories['attachment'] = [ - 'title' => t('Chart settings'), + 'title' => t('Chart settings'), 'column' => 'second', - 'build' => ['#weight' => -10], + 'build' => ['#weight' => -10], ]; $displays = array_filter($this->getOption('displays')); if (count($displays) > 1) { @@ -65,14 +65,14 @@ class ChartsPluginDisplayChart extends Attachment { } $options['displays'] = [ 'category' => 'attachment', - 'title' => $this->t('Parent display'), - 'value' => $attach_to, + 'title' => $this->t('Parent display'), + 'value' => $attach_to, ]; $options['inherit_yaxis'] = [ 'category' => 'attachment', - 'title' => $this->t('Axis settings'), - 'value' => $this->getOption('inherit_yaxis') ? t('Use primary Y-axis') : t('Create secondary axis'), + 'title' => $this->t('Axis settings'), + 'value' => $this->getOption('inherit_yaxis') ? t('Use primary Y-axis') : t('Create secondary axis'), ]; unset($options['attachment_position']); @@ -93,14 +93,14 @@ class ChartsPluginDisplayChart extends Attachment { case 'inherit_yaxis': $form['#title'] .= t('Axis settings'); $form['inherit_yaxis'] = [ - '#title' => t('Y-Axis settings'), - '#type' => 'radios', - '#options' => [ + '#title' => t('Y-Axis settings'), + '#type' => 'radios', + '#options' => [ 1 => t('Inherit primary of parent display'), 0 => t('Create a secondary axis'), ], '#default_value' => $this->getOption('inherit_yaxis'), - '#description' => t('In most charts, the X and Y axis from the parent display are both shared with each attached child chart. However, if this chart is going to use a different unit of measurement, a secondary axis may be added on the opposite side of the normal Y-axis.'), + '#description' => t('In most charts, the X and Y axis from the parent display are both shared with each attached child chart. However, if this chart is going to use a different unit of measurement, a secondary axis may be added on the opposite side of the normal Y-axis.'), ]; break; } diff --git a/src/Plugin/views/style/ChartsPluginStyleChart.php b/src/Plugin/views/style/ChartsPluginStyleChart.php index 91d4ebe0991fae358d7b6d5e863e741057be15df..9b1e1295de5b8afc0b0777f5f761041633502b10 100644 --- a/src/Plugin/views/style/ChartsPluginStyleChart.php +++ b/src/Plugin/views/style/ChartsPluginStyleChart.php @@ -29,7 +29,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactoryPluginInterface { protected $usesFields = TRUE; + protected $usesRowPlugin = TRUE; + protected $attachmentService; /** @@ -69,12 +71,12 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('charts.charts_attachment'), - $container->get('plugin.manager.charts') + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('charts.charts_attachment'), + $container->get('plugin.manager.charts') ); } @@ -196,24 +198,24 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory } $chart_id = $this->view->id() . '__' . $this->view->current_display; $chart = [ - '#type' => 'chart', - '#chart_type' => $this->options['type'], - '#chart_library' => $this->options['library'], - '#chart_id' => $chart_id, - '#id' => ('chart_' . $chart_id), - '#title' => $this->options['title_position'] ? $this->options['title'] : FALSE, - '#title_position' => $this->options['title_position'], - '#tooltips' => $this->options['tooltips'], - '#data_labels' => $this->options['data_labels'], - '#colors' => $this->options['colors'], - '#background' => $this->options['background'] ? $this->options['background'] : 'transparent', - '#legend' => $this->options['legend_position'] ? TRUE : FALSE, + '#type' => 'chart', + '#chart_type' => $this->options['type'], + '#chart_library' => $this->options['library'], + '#chart_id' => $chart_id, + '#id' => ('chart_' . $chart_id), + '#title' => $this->options['title_position'] ? $this->options['title'] : FALSE, + '#title_position' => $this->options['title_position'], + '#tooltips' => $this->options['tooltips'], + '#data_labels' => $this->options['data_labels'], + '#colors' => $this->options['colors'], + '#background' => $this->options['background'] ? $this->options['background'] : 'transparent', + '#legend' => $this->options['legend_position'] ? TRUE : FALSE, '#legend_position' => $this->options['legend_position'] ? $this->options['legend_position'] : NULL, - '#width' => $this->options['width'], - '#height' => $this->options['height'], - '#view' => $this->view, + '#width' => $this->options['width'], + '#height' => $this->options['height'], + '#view' => $this->view, // Pass info about the actual view results to allow further processing. - '#theme' => 'views_view_charts', + '#theme' => 'views_view_charts', ]; $chart_type_info = charts_get_type($this->options['type']); if ($chart_type_info['axis'] === ChartsInterface::CHARTS_SINGLE_AXIS) { @@ -247,40 +249,40 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory } $chart[$this->view->current_display . '_series'] = [ - '#type' => 'chart_data', - '#data' => $data, + '#type' => 'chart_data', + '#data' => $data, '#title' => $data_field['label'], ]; } else { $chart['xaxis'] = [ - '#type' => 'chart_xaxis', - '#title' => $this->options['xaxis_title'] ? $this->options['xaxis_title'] : FALSE, + '#type' => 'chart_xaxis', + '#title' => $this->options['xaxis_title'] ? $this->options['xaxis_title'] : FALSE, '#labels_rotation' => $this->options['xaxis_labels_rotation'], ]; $chart['yaxis'] = [ - '#type' => 'chart_yaxis', - '#title' => $this->options['yaxis_title'] ? $this->options['yaxis_title'] : FALSE, + '#type' => 'chart_yaxis', + '#title' => $this->options['yaxis_title'] ? $this->options['yaxis_title'] : FALSE, '#labels_rotation' => $this->options['yaxis_labels_rotation'], - '#max' => $this->options['yaxis_max'], - '#min' => $this->options['yaxis_min'], + '#max' => $this->options['yaxis_max'], + '#min' => $this->options['yaxis_min'], ]; $sets = $this->renderGrouping($this->view->result, $this->options['grouping'], TRUE); $series_index = -1; foreach ($sets as $series_label => $data_set) { $series_index++; - // $series_key = $this->view->current_display . '__' . $field_key . '_' . $series_index; + // $series_key = $this->view->current_display . '__' . $field_key . '_' . $series_index; foreach ($data_fields as $field_key => $field_handler) { $chart[$this->view->current_display . '__' . $field_key . '_' . $series_index] = [ - '#type' => 'chart_data', - '#data' => [], + '#type' => 'chart_data', + '#data' => [], // If using a grouping field, inherit from the chart level colors. - '#color' => ($series_label === '' && isset($this->options['field_colors'][$field_key])) ? $this->options['field_colors'][$field_key] : NULL, - '#title' => $series_label ? $series_label : $field_handler['label'], - '#prefix' => $this->options['yaxis_prefix'] ? $this->options['yaxis_prefix'] : NULL, - '#suffix' => $this->options['yaxis_suffix'] ? $this->options['yaxis_suffix'] : NULL, + '#color' => ($series_label === '' && isset($this->options['field_colors'][$field_key])) ? $this->options['field_colors'][$field_key] : NULL, + '#title' => $series_label ? $series_label : $field_handler['label'], + '#prefix' => $this->options['yaxis_prefix'] ? $this->options['yaxis_prefix'] : NULL, + '#suffix' => $this->options['yaxis_suffix'] ? $this->options['yaxis_suffix'] : NULL, '#decimal_count' => $this->options['yaxis_decimal_count'] ? $this->options['yaxis_decimal_count'] : NULL, ]; } @@ -420,12 +422,12 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory * {@inheritdoc} */ public function calculateDependencies() { - $dependencies = []; + $dependencies = []; - if (!empty($this->options['library'])) { - $plugin_definition = $this->chartManager->getDefinition($this->options['library']); - $dependencies['module'] = [$plugin_definition['provider']]; - } + if (!empty($this->options['library'])) { + $plugin_definition = $this->chartManager->getDefinition($this->options['library']); + $dependencies['module'] = [$plugin_definition['provider']]; + } return $dependencies; } diff --git a/src/Services/ChartsSettingsService.php b/src/Services/ChartsSettingsService.php index 08522474ac72cf852472cbe9c8d0e7d2952227a8..3aed61ce0dd8777b7736adb89229ed18e496bb65 100644 --- a/src/Services/ChartsSettingsService.php +++ b/src/Services/ChartsSettingsService.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\ConfigFactory; class ChartsSettingsService implements ChartsSettingsServiceInterface { private $configFactory; + /* private $editableConfigName = 'charts.settings'; */ /** diff --git a/src/Util/Util.php b/src/Util/Util.php index 450d890a67f9620c20d08921f9501b8620001fd3..5ddaca0bbca8cb6bafdc327189786f7e8ac6d4ab 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -38,11 +38,11 @@ class Util { $tokenized_text = trim(str_replace("\n", '', strip_tags($view->field[$labelField]->tokenizeValue($text, $row_number)))); } $rowData[$numberFields] = [ - 'value' => $view->field[$fieldId]->getValue($row), + 'value' => $view->field[$fieldId]->getValue($row), 'label_field' => ($alter_text) ? $tokenized_text : $view->field[$labelField]->getValue($row), - 'label' => $view->field[$fieldId]->label(), - 'color' => $color[$fieldId], - 'type' => $attachmentChartTypeOption, + 'label' => $view->field[$fieldId]->label(), + 'color' => $color[$fieldId], + 'type' => $attachmentChartTypeOption, ]; $numberFields++; } @@ -87,7 +87,12 @@ class Util { for ($i = 0; $i < count($data[0]); $i++) { - $seriesRowData = ['name' => '', 'color' => '', 'type' => '', 'data' => []]; + $seriesRowData = [ + 'name' => '', + 'color' => '', + 'type' => '', + 'data' => [], + ]; for ($j = 0; $j < count($data); $j++) { $categories[$j] = $data[$j][$i]['label_field']; $seriesRowData['name'] = $data[$j][$i]['label']; diff --git a/templates/views-view-charts.html.twig b/templates/views-view-charts.html.twig index 4d1a1135a0c5b2a5bb997c7befd73b6d80791fdb..24734d4941c5b518caa7b93788ca0bec48f2f0ba 100644 --- a/templates/views-view-charts.html.twig +++ b/templates/views-view-charts.html.twig @@ -1,3 +1,4 @@ {% set library, height, width = 'charts_' ~ chart_type ~ '/' ~ chart_type, height, width %} {{ attach_library("#{ library }") }} -<div {{ attributes }} {{ content_attributes }} style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div> +<div {{ attributes }} {{ content_attributes }} + style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div>