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

Issue #2926078 by lbaran: Charts API Example has issue with ModuleHandler.php...

Issue #2926078 by lbaran: Charts API Example has issue with ModuleHandler.php and issue #2926077 by lbaran: In Default chart configuration, get AttachedAssets.php notice. Also includes misc. changes to HighchartsChartsRender by andieco
parent 37908191
No related branches found
No related tags found
No related merge requests found
...@@ -2,33 +2,50 @@ ...@@ -2,33 +2,50 @@
namespace Drupal\charts_api_example\Controller; namespace Drupal\charts_api_example\Controller;
use Drupal\charts\Services\ChartsSettingsService; use Drupal\charts\Services\ChartsSettingsService;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Charts Api Example.
*/
class ChartsApiExample extends ControllerBase implements ContainerInjectionInterface { class ChartsApiExample extends ControllerBase implements ContainerInjectionInterface {
private $chartSettings; private $chartSettings;
/**
* Construct.
*
* @param \Drupal\charts\Services\ChartsSettingsService $chartSettings
* Service ChartsSettingsService.
*/
public function __construct(ChartsSettingsService $chartSettings) { public function __construct(ChartsSettingsService $chartSettings) {
$this->chartSettings = $chartSettings->getChartsSettings(); $this->chartSettings = $chartSettings->getChartsSettings();
} }
/**
* Display.
*
* @return array
* Array to render.
*/
public function display() { public function display() {
$library = $this->chartSettings['library']; $library = $this->chartSettings['library'];
if (!isset($library)) { if (empty($library)) {
drupal_set_message(t('You need to first configure Charts default drupal_set_message($this->t('You need to first configure Charts default settings'));
settings')); return [];
} }
$options = []; $options = [
$options['type'] = $this->chartSettings['type']; 'type' => $this->chartSettings['type'],
$options['title'] = $this->t('Chart title'); 'title' => $this->t('Chart title'),
$options['yaxis_title'] = $this->t('Y-Axis'); 'xaxis_title' => $this->t('X-Axis'),
$options['yaxis_min'] = ''; 'yaxis_title' => $this->t('Y-Axis'),
$options['yaxis_max'] = ''; 'yaxis_min' => '',
$options['xaxis_title'] = $this->t('X-Axis'); 'yaxis_max' => '',
];
// Sample data format. // Sample data format.
$categories = ["Category 1", "Category 2", "Category 3", "Category 4"]; $categories = ["Category 1", "Category 2", "Category 3", "Category 4"];
$seriesData = [ $seriesData = [
...@@ -37,16 +54,18 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter ...@@ -37,16 +54,18 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
["name" => "Series 3", "color" => "#910000", "type" => "area", "data" => [0, 0, 60, 90]] ["name" => "Series 3", "color" => "#910000", "type" => "area", "data" => [0, 0, 60, 90]]
]; ];
$element = [ return [
'#theme' => 'charts_api_example', '#theme' => 'charts_api_example',
'#library' => $this->t($library), '#library' => (string) $library,
'#categories' => $categories, '#categories' => $categories,
'#seriesData' => $seriesData, '#seriesData' => $seriesData,
'#options' => $options, '#options' => $options,
]; ];
return $element;
} }
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('charts.settings') $container->get('charts.settings')
......
...@@ -60,16 +60,38 @@ class HighchartsChartsRender implements ChartsRenderInterface { ...@@ -60,16 +60,38 @@ class HighchartsChartsRender implements ChartsRenderInterface {
} }
} }
$chart->setType($typeOptions); $chart->setType($typeOptions);
$chart->setWidth($options['width']);
$chart->setHeight($options['height']); // Set chart width.
if (isset($options['width'])) {
$chart->setWidth($options['width']);
}
// Set chart height.
if (isset($options['height'])) {
$chart->setHeight($options['height']);
}
// Set chart title.
$chartTitle = new ChartTitle(); $chartTitle = new ChartTitle();
$chartTitle->setText($options['title']); if (isset($options['title'])) {
$chartTitle->setText($options['title']);
}
$chartXaxis = new Xaxis(); $chartXaxis = new Xaxis();
$chartLabels = new ChartLabel(); $chartLabels = new ChartLabel();
$chartLabels->setRotation($options['xaxis_labels_rotation']);
// Set x-axis label rotation.
if (isset($options['xaxis_labels_rotation'])) {
$chartLabels->setRotation($options['xaxis_labels_rotation']);
}
$chartXaxis->setCategories($categories); $chartXaxis->setCategories($categories);
// Set x-axis title.
$xAxisTitle = new XaxisTitle(); $xAxisTitle = new XaxisTitle();
$xAxisTitle->setText($options['xaxis_title']); if (isset($options['xaxis_title'])) {
$xAxisTitle->setText($options['xaxis_title']);
}
$chartXaxis->setTitle($xAxisTitle); $chartXaxis->setTitle($xAxisTitle);
$chartXaxis->setLabels($chartLabels); $chartXaxis->setLabels($chartLabels);
$yaxisLabels = new YaxisLabel(); $yaxisLabels = new YaxisLabel();
...@@ -87,7 +109,8 @@ class HighchartsChartsRender implements ChartsRenderInterface { ...@@ -87,7 +109,8 @@ class HighchartsChartsRender implements ChartsRenderInterface {
$chartYaxis->setLabels($yaxisLabels); $chartYaxis->setLabels($yaxisLabels);
$chartYaxis->setTitle($yAxisTitle); $chartYaxis->setTitle($yAxisTitle);
array_push($yAxes, $chartYaxis); array_push($yAxes, $chartYaxis);
// Chart libraries tend to supports only one secondary axis.
// Chart libraries tend to support only one secondary axis.
if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) { if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) {
$chartYaxisSecondary = new Yaxis(); $chartYaxisSecondary = new Yaxis();
$yAxisTitleSecondary = new YaxisTitle(); $yAxisTitleSecondary = new YaxisTitle();
......
This diff is collapsed.
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