Skip to content
Snippets Groups Projects
Commit 9f8abe6d authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #2936607 by andileco: [Plan] Further develop blocks integration

parent 0330f6f5
No related branches found
No related tags found
No related merge requests found
...@@ -93,19 +93,9 @@ function template_preprocess_views_view_charts(&$variables) { ...@@ -93,19 +93,9 @@ function template_preprocess_views_view_charts(&$variables) {
$seriesData = array_merge($seriesData, $seriesDataAttachment); $seriesData = array_merge($seriesData, $seriesDataAttachment);
$plugin_manager = \Drupal::service('plugin.manager.charts'); $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);
}
} }
...@@ -686,6 +686,7 @@ function charts_default_settings() { ...@@ -686,6 +686,7 @@ function charts_default_settings() {
$defaults = [ $defaults = [
'type' => 'line', 'type' => 'line',
'library' => NULL, 'library' => NULL,
'grouping' => FALSE,
'label_field' => NULL, 'label_field' => NULL,
'data_fields' => NULL, 'data_fields' => NULL,
'field_colors' => NULL, 'field_colors' => NULL,
...@@ -697,6 +698,7 @@ function charts_default_settings() { ...@@ -697,6 +698,7 @@ function charts_default_settings() {
'colors' => charts_default_colors(), 'colors' => charts_default_colors(),
'background' => '', 'background' => '',
'three_dimensional' => FALSE, 'three_dimensional' => FALSE,
'polar' => FALSE,
'tooltips' => TRUE, 'tooltips' => TRUE,
'tooltips_use_html' => FALSE, 'tooltips_use_html' => FALSE,
'width' => NULL, 'width' => NULL,
......
...@@ -47,5 +47,5 @@ function charts_api_example_theme() { ...@@ -47,5 +47,5 @@ function charts_api_example_theme() {
function template_preprocess_charts_api_example(&$variables) { function template_preprocess_charts_api_example(&$variables) {
$plugin_manager = \Drupal::service('plugin.manager.charts'); $plugin_manager = \Drupal::service('plugin.manager.charts');
$plugin = $plugin_manager->createInstance($variables['library']); $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']);
} }
...@@ -71,18 +71,22 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter ...@@ -71,18 +71,22 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
'type' => 'area', 'type' => 'area',
'data' => [0, 0, 60, 90], 'data' => [0, 0, 60, 90],
]; ];
// If using C3, comment out the following two cases.
case 'pie': case 'pie':
case 'donut': case 'donut':
} }
// Creates a UUID for the chart ID.
$uuid_service = \Drupal::service('uuid');
$chartId = 'chart-' . $uuid_service->generate();
$build = [ $build = [
'#theme' => 'charts_api_example', '#theme' => 'charts_api_example',
'#library' => (string) $library, '#library' => (string) $library,
'#categories' => $categories, '#categories' => $categories,
'#seriesData' => $seriesData, '#seriesData' => $seriesData,
'#options' => $options, '#options' => $options,
'#id' => $chartId,
]; ];
return $build; return $build;
......
...@@ -54,16 +54,3 @@ function template_preprocess_charts_blocks(&$variables) { ...@@ -54,16 +54,3 @@ function template_preprocess_charts_blocks(&$variables) {
$plugin = $plugin_manager->createInstance($variables['library']); $plugin = $plugin_manager->createInstance($variables['library']);
$plugin->buildVariables($variables['options'], $variables['categories'], $variables['seriesData'], [], $variables, $variables['id']); $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
...@@ -109,6 +109,14 @@ class ChartsBlock extends BlockBase { ...@@ -109,6 +109,14 @@ class ChartsBlock extends BlockBase {
'#default_value' => $this->configuration['categories'], '#default_value' => $this->configuration['categories'],
'#weight' => '-16', '#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 * Unset the #parents element from default form, then set the
...@@ -152,9 +160,32 @@ class ChartsBlock extends BlockBase { ...@@ -152,9 +160,32 @@ class ChartsBlock extends BlockBase {
unset($form['display']['dimensions']['width']['#parents']); unset($form['display']['dimensions']['width']['#parents']);
$form['display']['dimensions']['width']['#default_value'] = $this->configuration['width']; $form['display']['dimensions']['width']['#default_value'] = $this->configuration['width'];
/** unset($form['xaxis']['xaxis_title']['#parents']);
* @todo: complete this for the remaining form elements. $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; return $form;
} }
...@@ -171,6 +202,7 @@ class ChartsBlock extends BlockBase { ...@@ -171,6 +202,7 @@ class ChartsBlock extends BlockBase {
$this->configuration['data_series'] = $form_state->getValue('data_series'); $this->configuration['data_series'] = $form_state->getValue('data_series');
$this->configuration['series_label'] = $form_state->getValue('series_label'); $this->configuration['series_label'] = $form_state->getValue('series_label');
$this->configuration['categories'] = $form_state->getValue('categories'); $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['field_colors'] = $form_state->getValue('field_colors');
$this->configuration['title'] = $form_state->getValue(['display','title']); $this->configuration['title'] = $form_state->getValue(['display','title']);
$this->configuration['title_position'] = $form_state->getValue(['display','title_position']); $this->configuration['title_position'] = $form_state->getValue(['display','title_position']);
...@@ -185,15 +217,15 @@ class ChartsBlock extends BlockBase { ...@@ -185,15 +217,15 @@ class ChartsBlock extends BlockBase {
$this->configuration['tooltips_use_html'] = $form_state->getValue('tooltips_use_html'); $this->configuration['tooltips_use_html'] = $form_state->getValue('tooltips_use_html');
$this->configuration['width'] = $form_state->getValue(['display','dimensions','width']); $this->configuration['width'] = $form_state->getValue(['display','dimensions','width']);
$this->configuration['height'] = $form_state->getValue(['display','dimensions','height']); $this->configuration['height'] = $form_state->getValue(['display','dimensions','height']);
$this->configuration['xaxis_title'] = $form_state->getValue('xaxis_title'); $this->configuration['xaxis_title'] = $form_state->getValue(['xaxis', 'xaxis_title']);
$this->configuration['xaxis_labels_rotation'] = $form_state->getValue('xaxis_labels_rotation'); $this->configuration['xaxis_labels_rotation'] = $form_state->getValue(['xaxis', 'xaxis_labels_rotation']);
$this->configuration['yaxis_title'] = $form_state->getValue('yaxis_title'); $this->configuration['yaxis_title'] = $form_state->getValue(['yaxis', 'yaxis_title']);
$this->configuration['yaxis_min'] = $form_state->getValue('yaxis_min'); $this->configuration['yaxis_min'] = $form_state->getValue(['yaxis', 'yaxis_min']);
$this->configuration['yaxis_max'] = $form_state->getValue('yaxis_max'); $this->configuration['yaxis_max'] = $form_state->getValue(['yaxis', 'yaxis_max']);
$this->configuration['yaxis_prefix'] = $form_state->getValue('yaxis_prefix'); $this->configuration['yaxis_prefix'] = $form_state->getValue(['yaxis', 'yaxis_prefix']);
$this->configuration['yaxis_suffix'] = $form_state->getValue('yaxis_suffix'); $this->configuration['yaxis_suffix'] = $form_state->getValue(['yaxis', 'yaxis_suffix']);
$this->configuration['yaxis_decimal_count'] = $form_state->getValue('yaxis_decimal_count'); $this->configuration['yaxis_decimal_count'] = $form_state->getValue(['yaxis', 'yaxis_decimal_count']);
$this->configuration['yaxis_labels_rotation'] = $form_state->getValue('yaxis_labels_rotation'); $this->configuration['yaxis_labels_rotation'] = $form_state->getValue(['yaxis', 'yaxis_labels_rotation']);
} }
...@@ -205,6 +237,7 @@ class ChartsBlock extends BlockBase { ...@@ -205,6 +237,7 @@ class ChartsBlock extends BlockBase {
$options = [ $options = [
'library' => $this->configuration['library'], 'library' => $this->configuration['library'],
'type' => $this->configuration['type'], 'type' => $this->configuration['type'],
'grouping' => $this->configuration['grouping'],
'field_colors'=>$this->configuration['field_colors'], 'field_colors'=>$this->configuration['field_colors'],
'title'=>$this->configuration['title'], 'title'=>$this->configuration['title'],
'title_position'=>$this->configuration['title_position'], 'title_position'=>$this->configuration['title_position'],
......
...@@ -83,7 +83,7 @@ class C3 extends AbstractChart { ...@@ -83,7 +83,7 @@ class C3 extends AbstractChart {
array_push($c3Data, $c3DataTemp); array_push($c3Data, $c3DataTemp);
} }
} }
$c3Chart = new ChartType(); $c3Chart = new ChartType();
$c3Chart->setType($options['type']); $c3Chart->setType($options['type']);
$c3ChartTitle = new ChartTitle(); $c3ChartTitle = new ChartTitle();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment