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) {
$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);
}
}
......@@ -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,
......
......@@ -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']);
}
......@@ -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;
......
......@@ -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
......@@ -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'],
......
......@@ -83,7 +83,7 @@ class C3 extends AbstractChart {
array_push($c3Data, $c3DataTemp);
}
}
$c3Chart = new ChartType();
$c3Chart->setType($options['type']);
$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