diff --git a/charts.module b/charts.module index 0a01040b248f762d1a7447ab6b5aa576102e78a0..170bd40bee0f7115588f9c15cdaafa24c2f03f0c 100644 --- a/charts.module +++ b/charts.module @@ -93,19 +93,9 @@ function template_preprocess_views_view_charts(&$variables) { $seriesData = array_merge($seriesData, $seriesDataAttachment); $plugin_manager = \Drupal::service('plugin.manager.charts'); - $plugin_definitions = $plugin_manager->getDefinitions(); + $plugin = $plugin_manager->createInstance($library); + $variables['height'] = $options['height']; + $variables['width'] = $options['width']; + $plugin->buildVariables($options, $categories, $seriesData, $attachmentDisplayOptions, $variables, $chartId); - if (!isset($plugin_definitions)) { - // To be removed in drupal 9. - $moduleSelector = new ModuleSelector($library, $categories, $seriesData, $attachmentDisplayOptions, $options, $chartId); - if ($moduleSelector->moduleExists()) { - $moduleSelector->buildVariables($variables); - } - } - else { - $plugin = $plugin_manager->createInstance($library); - $variables['height'] = $options['height']; - $variables['width'] = $options['width']; - $plugin->buildVariables($options, $categories, $seriesData, $attachmentDisplayOptions, $variables, $chartId); - } } diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc index 081890a9407147bdded58dd9b3aa02be91b55638..f59e2e572a79d669b7af7851ffb74d2b1da9a1be 100644 --- a/includes/charts.pages.inc +++ b/includes/charts.pages.inc @@ -686,6 +686,7 @@ function charts_default_settings() { $defaults = [ 'type' => 'line', 'library' => NULL, + 'grouping' => FALSE, 'label_field' => NULL, 'data_fields' => NULL, 'field_colors' => NULL, @@ -697,6 +698,7 @@ function charts_default_settings() { 'colors' => charts_default_colors(), 'background' => '', 'three_dimensional' => FALSE, + 'polar' => FALSE, 'tooltips' => TRUE, 'tooltips_use_html' => FALSE, 'width' => NULL, diff --git a/modules/charts_api_example/charts_api_example.module b/modules/charts_api_example/charts_api_example.module index 1da3ee0d9819c57545d82bd6ca0edcff5bc6b87e..ee89730516bf90b8dd506329ef7215c3d3b8c9df 100644 --- a/modules/charts_api_example/charts_api_example.module +++ b/modules/charts_api_example/charts_api_example.module @@ -47,5 +47,5 @@ function charts_api_example_theme() { function template_preprocess_charts_api_example(&$variables) { $plugin_manager = \Drupal::service('plugin.manager.charts'); $plugin = $plugin_manager->createInstance($variables['library']); - $plugin->buildVariables($variables['options'], $variables['categories'], $variables['seriesData'], [], $variables, 'xyz'); + $plugin->buildVariables($variables['options'], $variables['categories'], $variables['seriesData'], [], $variables, $variables['id']); } diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php index fe7e872d72d9a09fd75485c4c0885f08c5eb6f78..d646b6f363a475c7b8e9ba3707e23227e3ab3014 100644 --- a/modules/charts_api_example/src/Controller/ChartsApiExample.php +++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php @@ -71,18 +71,22 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter 'type' => 'area', 'data' => [0, 0, 60, 90], ]; - // If using C3, comment out the following two cases. case 'pie': case 'donut': } + // Creates a UUID for the chart ID. + $uuid_service = \Drupal::service('uuid'); + $chartId = 'chart-' . $uuid_service->generate(); + $build = [ '#theme' => 'charts_api_example', '#library' => (string) $library, '#categories' => $categories, '#seriesData' => $seriesData, '#options' => $options, + '#id' => $chartId, ]; return $build; diff --git a/modules/charts_blocks/charts_blocks.module b/modules/charts_blocks/charts_blocks.module index ac9f68180d8383c6c789f1c5f9b84c2ac5ee54d9..c7406a63ee72d45bc72b33bad578c2c8d7f9e009 100644 --- a/modules/charts_blocks/charts_blocks.module +++ b/modules/charts_blocks/charts_blocks.module @@ -54,16 +54,3 @@ function template_preprocess_charts_blocks(&$variables) { $plugin = $plugin_manager->createInstance($variables['library']); $plugin->buildVariables($variables['options'], $variables['categories'], $variables['seriesData'], [], $variables, $variables['id']); } - -///** -// * Implements template_preprocess_page -// * -// * @param $variables -// */ -//function charts_blocks_preprocess_block(&$variables) { -// if($variables['plugin_id'] == 'charts_block') { -// $plugin_manager = \Drupal::service('plugin.manager.charts'); -// $plugin = $plugin_manager->createInstance($variables['content']['#library']); -// $plugin->buildVariables($variables['content']['#options'], $variables['content']['#categories'], $variables['content']['#seriesData'], [], $variables['content']['#options'], 'id'); -// } -//} \ No newline at end of file diff --git a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php index d3876d249bc11d02ab1006c0619b3cee6d2cab84..b0df36f43e5a4602a605e7a0cde6a74dbcd764db 100644 --- a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php +++ b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php @@ -109,6 +109,14 @@ class ChartsBlock extends BlockBase { '#default_value' => $this->configuration['categories'], '#weight' => '-16', ]; + // Enable stacking. + $form['grouping'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Stacking'), + '#description' => $this->t('Enable stacking'), + '#default_value' => $this->configuration['grouping'], + '#weight' => '-15', + ]; /** * Unset the #parents element from default form, then set the @@ -152,9 +160,32 @@ class ChartsBlock extends BlockBase { unset($form['display']['dimensions']['width']['#parents']); $form['display']['dimensions']['width']['#default_value'] = $this->configuration['width']; - /** - * @todo: complete this for the remaining form elements. - */ + unset($form['xaxis']['xaxis_title']['#parents']); + $form['xaxis']['xaxis_title']['#default_value'] = $this->configuration['xaxis_title']; + + unset($form['xaxis']['xaxis_labels_rotation']['#parents']); + $form['xaxis']['xaxis_labels_rotation']['#default_value'] = $this->configuration['xaxis_labels_rotation']; + + unset($form['yaxis']['yaxis_title']['#parents']); + $form['yaxis']['yaxis_title']['#default_value'] = $this->configuration['yaxis_title']; + + unset($form['yaxis']['yaxis_min']['#parents']); + $form['yaxis']['yaxis_min']['#default_value'] = $this->configuration['yaxis_min']; + + unset($form['yaxis']['yaxis_max']['#parents']); + $form['yaxis']['yaxis_max']['#default_value'] = $this->configuration['yaxis_max']; + + unset($form['yaxis']['yaxis_prefix']['#parents']); + $form['yaxis']['yaxis_prefix']['#default_value'] = $this->configuration['yaxis_prefix']; + + unset($form['yaxis']['yaxis_suffix']['#parents']); + $form['yaxis']['yaxis_suffix']['#default_value'] = $this->configuration['yaxis_suffix']; + + unset($form['yaxis']['yaxis_decimal_count']['#parents']); + $form['yaxis']['yaxis_decimal_count']['#default_value'] = $this->configuration['yaxis_decimal_count']; + + unset($form['yaxis']['yaxis_labels_rotation']['#parents']); + $form['yaxis']['yaxis_labels_rotation']['#default_value'] = $this->configuration['yaxis_labels_rotation']; return $form; } @@ -171,6 +202,7 @@ class ChartsBlock extends BlockBase { $this->configuration['data_series'] = $form_state->getValue('data_series'); $this->configuration['series_label'] = $form_state->getValue('series_label'); $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']); @@ -185,15 +217,15 @@ class ChartsBlock extends BlockBase { $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_title'); - $this->configuration['xaxis_labels_rotation'] = $form_state->getValue('xaxis_labels_rotation'); - $this->configuration['yaxis_title'] = $form_state->getValue('yaxis_title'); - $this->configuration['yaxis_min'] = $form_state->getValue('yaxis_min'); - $this->configuration['yaxis_max'] = $form_state->getValue('yaxis_max'); - $this->configuration['yaxis_prefix'] = $form_state->getValue('yaxis_prefix'); - $this->configuration['yaxis_suffix'] = $form_state->getValue('yaxis_suffix'); - $this->configuration['yaxis_decimal_count'] = $form_state->getValue('yaxis_decimal_count'); - $this->configuration['yaxis_labels_rotation'] = $form_state->getValue('yaxis_labels_rotation'); + $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']); } @@ -205,6 +237,7 @@ class ChartsBlock extends BlockBase { $options = [ 'library' => $this->configuration['library'], 'type' => $this->configuration['type'], + 'grouping' => $this->configuration['grouping'], 'field_colors'=>$this->configuration['field_colors'], 'title'=>$this->configuration['title'], 'title_position'=>$this->configuration['title_position'], diff --git a/modules/charts_c3/src/Plugin/chart/C3.php b/modules/charts_c3/src/Plugin/chart/C3.php index 8007823522807019277b444959f2e37574cc07b9..d130c217e7446416785f48b0f09c6b736a06fec5 100644 --- a/modules/charts_c3/src/Plugin/chart/C3.php +++ b/modules/charts_c3/src/Plugin/chart/C3.php @@ -83,7 +83,7 @@ class C3 extends AbstractChart { array_push($c3Data, $c3DataTemp); } } - + $c3Chart = new ChartType(); $c3Chart->setType($options['type']); $c3ChartTitle = new ChartTitle();