‪TYPO3CMS  ‪main
DoughnutChartWidget.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' => 'doughnut',
68  'options' => [
69  'maintainAspectRatio' => false,
70  'plugins' => [
71  'legend' => [
72  'display' => true,
73  'position' => 'bottom',
74  ],
75  ],
76  'cutoutPercentage' => 60,
77  ],
78  'data' => $this->dataProvider->getChartData(),
79  ],
80  ];
81  }
82 
83  public function ‪getCssFiles(): array
84  {
85  return [];
86  }
87 
88  public function ‪getJavaScriptModuleInstructions(): array
89  {
90  return [
91  ‪JavaScriptModuleInstruction::create('@typo3/dashboard/contrib/chartjs.js'),
92  ‪JavaScriptModuleInstruction::create('@typo3/dashboard/chart-initializer.js'),
93  ];
94  }
95 
96  public function ‪getOptions(): array
97  {
98  return $this->options;
99  }
100 }
‪TYPO3\CMS\Dashboard\Widgets\AdditionalCssInterface
Definition: AdditionalCssInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\__construct
‪__construct(private readonly WidgetConfigurationInterface $configuration, private readonly ChartDataProviderInterface $dataProvider, private readonly BackendViewFactory $backendViewFactory, private readonly ?ButtonProviderInterface $buttonProvider=null, private readonly array $options=[],)
Definition: DoughnutChartWidget.php:39
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\$request
‪ServerRequestInterface $request
Definition: DoughnutChartWidget.php:37
‪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\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\getEventData
‪getEventData()
Definition: DoughnutChartWidget.php:63
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\getOptions
‪getOptions()
Definition: DoughnutChartWidget.php:96
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: DoughnutChartWidget.php:47
‪TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface
Definition: ChartDataProviderInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\getJavaScriptModuleInstructions
‪getJavaScriptModuleInstructions()
Definition: DoughnutChartWidget.php:88
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget
Definition: DoughnutChartWidget.php:36
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\renderWidgetContent
‪renderWidgetContent()
Definition: DoughnutChartWidget.php:52
‪TYPO3\CMS\Dashboard\Widgets\EventDataInterface
Definition: EventDataInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\JavaScriptInterface
Definition: JavaScriptInterface.php:26
‪TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget\getCssFiles
‪getCssFiles()
Definition: DoughnutChartWidget.php:83
‪TYPO3\CMS\Dashboard\Widgets
Definition: AdditionalCssInterface.php:18
‪TYPO3\CMS\Dashboard\Widgets\ButtonProviderInterface
Definition: ButtonProviderInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface
Definition: WidgetConfigurationInterface.php:26