diff --git a/charts.links.menu.yml b/charts.links.menu.yml new file mode 100644 index 0000000000000000000000000000000000000000..edaa52103dbcc4fa36291bcc96abfdc66f69d942 --- /dev/null +++ b/charts.links.menu.yml @@ -0,0 +1,5 @@ +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 diff --git a/charts.module b/charts.module index 846363ba5c49055914aa3f03175b934913e339fe..1c2b192df5df68a362cec47fbd87e186fc317760 100644 --- a/charts.module +++ b/charts.module @@ -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) { } } - - diff --git a/charts.routing.yml b/charts.routing.yml index bc4056be378fc031a37b61b574727fe10f960cff..4830d22cd223ac8aebf16de95a586e9d987caa01 100644 --- a/charts.routing.yml +++ b/charts.routing.yml @@ -1,4 +1,4 @@ -charts.form: +charts.settings: path: '/admin/config/content/charts' defaults: _form: 'Drupal\charts\Form\ChartsConfigForm' diff --git a/modules/charts_google/charts_google.inc b/modules/charts_google/charts_google.inc index 3cc36abb55ffaa55b2c85d760ab76cd8e08d93da..3310ed21255c9a73e2307e2a3b4ee531893bd405 100644 --- a/modules/charts_google/charts_google.inc +++ b/modules/charts_google/charts_google.inc @@ -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; } diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php index 7bf544fcf23df51756eeb3e334f7d2e6ef0b9501..d57ba92a3ef7194d5d9ee9901af0631a59c6f98e 100644 --- a/src/Form/ChartsConfigForm.php +++ b/src/Form/ChartsConfigForm.php @@ -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, ];