Skip to content
Snippets Groups Projects
Commit 0d3873f1 authored by andileco's avatar andileco
Browse files

add default configuration form to Config page, fix the link to add a new view,...

add default configuration form to Config page, fix the link to add a new view, and minor pareview fixes, particularly short syntax for arrays
parent 0995f44b
No related branches found
No related tags found
No related merge requests found
charts.settings:
title: 'Charts default configuration'
description: 'Set the default library, behavior, and style of charts.'
parent: system.admin_config_content
route_name: charts.settings
......@@ -5,21 +5,21 @@
* Charts module file that provides hook_theme.
*/
use \Drupal\charts\Util\Util;
use Drupal\charts\Util\Util;
/**
* {@inheritdoc}
*/
function charts_theme($existing, $type, $theme, $path) {
return array(
'views_view_charts' => array(
'variables' => array(
return [
'views_view_charts' => [
'variables' => [
'view' => NULL,
'row' => NULL,
),
),
);
],
],
];
}
/**
......@@ -37,9 +37,9 @@ function template_preprocess_views_view_charts(&$variables) {
$viewId = $view->id();
$displayId = $view->display_handler->display['id'];
$chartId = $viewId . '__' . $displayId;
$categoriesAttachment = array();
$seriesDataAttachment = array();
$attachmentChartTypeOption = array();
$categoriesAttachment = [];
$seriesDataAttachment = [];
$attachmentChartTypeOption = [];
for ($i = 0; $i < count($attachmentView); $i++) {
......@@ -65,15 +65,16 @@ function template_preprocess_views_view_charts(&$variables) {
}
}
$library = $view->style_plugin->options['library'];
$variables['data'] = array();
$variables['data'] = [];
$labelField = $view->style_plugin->options['label_field'];
$valueField = $view->style_plugin->options['data_fields'];
$valueField = Util::removeUnselectedFields($valueField);
$color = $view->style_plugin->options['field_colors'];
if (0 < count($attachmentView)){
if (0 < count($attachmentView)) {
$data = Util::viewsData($view, $valueField, $labelField, $color, $attachmentChartTypeOption[$i]);
} else {
}
else {
$data = Util::viewsData($view, $valueField, $labelField, $color, $attachmentChartTypeOption[$i] = NULL);
}
......@@ -83,7 +84,7 @@ function template_preprocess_views_view_charts(&$variables) {
$categories = array_merge($categories, $categoriesAttachment);
$categories = array_unique($categories);
for ($i =0; $i < count($attachmentView); $i++){
for ($i = 0; $i < count($attachmentView); $i++) {
$attachmentId = $attachmentView[$i]->display_handler->display['id'];
$attachmentDisplay = $view->storage->getDisplay($attachmentId);
$attachmentDisplayOptions[$i] = $attachmentDisplay['display_options'];
......@@ -130,5 +131,3 @@ function template_preprocess_views_view_charts(&$variables) {
}
}
charts.form:
charts.settings:
path: '/admin/config/content/charts'
defaults:
_form: 'Drupal\charts\Form\ChartsConfigForm'
......
......@@ -32,7 +32,7 @@ function _charts_google_render($chart) {
// Trim out empty options.
charts_trim_array($chart_definition['options']);
$chart['#attached']['library'][] = array('charts_google', 'charts_google');
$chart['#attached']['library'][] = ['charts_google', 'charts_google'];
$chart['#attributes']['class'][] = 'charts-google';
$chart['#chart_definition'] = $chart_definition;
......@@ -43,14 +43,14 @@ function _charts_google_render($chart) {
* Utility to convert a Drupal renderable type to a Google visualization type.
*/
function _charts_google_visualization_type($renderable_type) {
$types = array(
$types = [
'area' => 'AreaChart',
'bar' => 'BarChart',
'column' => 'ColumnChart',
'line' => 'LineChart',
'pie' => 'PieChart',
'scatter' => 'ScatterChart',
);
];
drupal_alter('charts_google_visualization_types', $types);
return isset($types[$renderable_type]) ? $types[$renderable_type] : FALSE;
}
......@@ -107,7 +107,7 @@ function _charts_google_populate_chart_axes($chart, $chart_definition) {
}
// Populate the chart data.
$axis = array();
$axis = [];
$axis['title'] = $chart[$key]['#title'] ? $chart[$key]['#title'] : '';
$axis['titleTextStyle']['color'] = $chart[$key]['#title_color'];
$axis['titleTextStyle']['bold'] = $chart[$key]['#title_font_weight'] === 'bold' ? TRUE : FALSE;
......@@ -129,23 +129,22 @@ function _charts_google_populate_chart_axes($chart, $chart_definition) {
$axis['baselineColor'] = $chart[$key]['#base_line_color'];
$axis['minorGridlines']['color'] = $chart[$key]['#minor_grid_line_color'];
$axis['viewWindowMode'] = isset($chart[$key]['#max']) ? 'explicit' : NULL;
$axis['viewWindow']['max'] = strlen($chart[$key]['#max']) ? (int) $chart[$key]['#max'] : NULL;
$axis['viewWindow']['min'] = strlen($chart[$key]['#min']) ? (int) $chart[$key]['#min'] : NULL;
$axis['viewWindow']['max'] = strlen($chart[$key]['#max']) ? (int)$chart[$key]['#max'] : NULL;
$axis['viewWindow']['min'] = strlen($chart[$key]['#min']) ? (int)$chart[$key]['#min'] : NULL;
// Multi-axis support only applies to the major axis in Google charts.
$chart_type_info = charts_get_type($chart['#chart_type']);
$axis_index = $chart[$key]['#opposite'] ? 1 : 0;
if ($chart[$key]['#type'] === 'chart_xaxis') {
$axis_keys = !$chart_type_info['axis_inverted'] ? array('hAxis') : array(
$axis_keys = !$chart_type_info['axis_inverted'] ? ['hAxis'] : [
'vAxes',
$axis_index,
);
}
else {
$axis_keys = !$chart_type_info['axis_inverted'] ? array(
];
} else {
$axis_keys = !$chart_type_info['axis_inverted'] ? [
'vAxes',
$axis_index,
) : array('hAxis');
] : ['hAxis'];
}
$axis_drilldown = &$chart_definition['options'];
foreach ($axis_keys as $key) {
......@@ -162,12 +161,12 @@ function _charts_google_populate_chart_axes($chart, $chart_definition) {
* Utility to populate chart data.
*/
function _charts_google_populate_chart_data(&$chart, $chart_definition) {
$chart_definition['options']['series'] = array();
$chart_definition['options']['series'] = [];
$chart_type_info = charts_get_type($chart['#chart_type']);
$series_number = 0;
foreach (element_children($chart) as $key) {
if ($chart[$key]['#type'] === 'chart_data') {
$series = array();
$series = [];
// Make sure defaults are loaded.
if (empty($chart[$key]['#defaults_loaded'])) {
......@@ -205,12 +204,11 @@ function _charts_google_populate_chart_data(&$chart, $chart_definition) {
// approach leaves columns empty in order to make arbitrary pairings.
// See https://developers.google.com/chart/interactive/docs/gallery/scatterchart#Data_Format
if (is_array($data_value)) {
$chart_definition['data'][] = array(
$chart_definition['data'][] = [
0 => $data_value[0],
$series_number + 1 => $data_value[1],
);
}
// Most charts provide a single-dimension array of values.
];
} // Most charts provide a single-dimension array of values.
else {
$chart_definition['data'][$index + 1][$series_number + 1] = $data_value;
}
......
......@@ -47,17 +47,12 @@ class ChartsConfigForm extends ConfigFormBase {
}
$field_options = [];
$url = Url::fromRoute('views_ui.add');
$link = Link::fromTextAndUrl($this->t('create a new view'), $url)
->toRenderable();
// Add help.
$form['help'] = [
'#type' => 'markup',
'#markup' => '<p>' . $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="!views">create a new view</a> and select
the display format of "Chart".', ['!views' => $link['url']])
'#markup' => '<p>' . $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()])
. '</p>',
'#weight' => -100,
];
......
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