‪TYPO3CMS  ‪main
BarChartWidget.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
23 
36 {
37  private ServerRequestInterface ‪$request;
38 
39  public function ‪__construct(
40  private readonly ‪WidgetConfigurationInterface $configuration,
41  private readonly ‪ChartDataProviderInterface $dataProvider,
42  private readonly ‪BackendViewFactory $backendViewFactory,
43  private readonly ?‪ButtonProviderInterface $buttonProvider = null,
44  private readonly array $options = [],
45  ) {}
46 
47  public function ‪setRequest(ServerRequestInterface ‪$request): void
48  {
49  $this->request = ‪$request;
50  }
51 
52  public function ‪renderWidgetContent(): string
53  {
54  $view = $this->backendViewFactory->create($this->request);
55  $view->assignMultiple([
56  'button' => $this->buttonProvider,
57  'options' => $this->options,
58  'configuration' => $this->configuration,
59  ]);
60  return $view->render('Widget/ChartWidget');
61  }
62 
63  public function ‪getEventData(): array
64  {
65  return [
66  'graphConfig' => [
67  'type' => 'bar',
68  'options' => [
69  'maintainAspectRatio' => false,
70  'plugins' => [
71  'legend' => [
72  'display' => false,
73  ],
74  ],
75  'scales' => [
76  'y' => [
77  'ticks' => [
78  'beginAtZero' => true,
79  ],
80  ],
81  'x' => [
82  'ticks' => [
83  'maxTicksLimit' => 15,
84  ],
85  ],
86  ],
87  ],
88  'data' => $this->dataProvider->getChartData(),
89  ],
90  ];
91  }
92 
93  public function ‪getCssFiles(): array
94  {
95  return [];
96  }
97 
98  public function ‪getJavaScriptModuleInstructions(): array
99  {
100  return [
101  ‪JavaScriptModuleInstruction::create('@typo3/dashboard/contrib/chartjs.js'),
102  ‪JavaScriptModuleInstruction::create('@typo3/dashboard/chart-initializer.js'),
103  ];
104  }
105 
106  public function ‪getOptions(): array
107  {
108  return $this->options;
109  }
110 }
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\getOptions
‪getOptions()
Definition: BarChartWidget.php:106
‪TYPO3\CMS\Dashboard\Widgets\AdditionalCssInterface
Definition: AdditionalCssInterface.php:24
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Dashboard\Widgets\RequestAwareWidgetInterface
Definition: RequestAwareWidgetInterface.php:29
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Dashboard\Widgets\WidgetInterface
Definition: WidgetInterface.php:26
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\renderWidgetContent
‪renderWidgetContent()
Definition: BarChartWidget.php:52
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\getEventData
‪getEventData()
Definition: BarChartWidget.php:63
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: BarChartWidget.php:47
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget
Definition: BarChartWidget.php:36
‪TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface
Definition: ChartDataProviderInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\getJavaScriptModuleInstructions
‪getJavaScriptModuleInstructions()
Definition: BarChartWidget.php:98
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\__construct
‪__construct(private readonly WidgetConfigurationInterface $configuration, private readonly ChartDataProviderInterface $dataProvider, private readonly BackendViewFactory $backendViewFactory, private readonly ?ButtonProviderInterface $buttonProvider=null, private readonly array $options=[],)
Definition: BarChartWidget.php:39
‪TYPO3\CMS\Dashboard\Widgets\EventDataInterface
Definition: EventDataInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\JavaScriptInterface
Definition: JavaScriptInterface.php:26
‪TYPO3\CMS\Dashboard\Widgets
Definition: AdditionalCssInterface.php:18
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\$request
‪ServerRequestInterface $request
Definition: BarChartWidget.php:37
‪TYPO3\CMS\Dashboard\Widgets\ButtonProviderInterface
Definition: ButtonProviderInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface
Definition: WidgetConfigurationInterface.php:26
‪TYPO3\CMS\Dashboard\Widgets\BarChartWidget\getCssFiles
‪getCssFiles()
Definition: BarChartWidget.php:93