|
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
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Dashboard\Widgets; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Concrete Doughnut Chart widget implementation |
|
24
|
|
|
* |
|
25
|
|
|
* Shows a widget with a doughnut chart. The data for this chart will be provided by the data provider you will set. |
|
26
|
|
|
* You can add a button to the widget by defining a button provider. |
|
27
|
|
|
* |
|
28
|
|
|
* There are no options available for this widget |
|
29
|
|
|
* |
|
30
|
|
|
* @see ChartDataProviderInterface |
|
31
|
|
|
* @see ButtonProviderInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
class DoughnutChartWidget implements WidgetInterface, EventDataInterface, AdditionalCssInterface, RequireJsModuleInterface |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var WidgetConfigurationInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $configuration; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var ChartDataProviderInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
private $dataProvider; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var StandaloneView |
|
47
|
|
|
*/ |
|
48
|
|
|
private $view; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var ButtonProviderInterface|null |
|
52
|
|
|
*/ |
|
53
|
|
|
private $buttonProvider; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var array |
|
57
|
|
|
*/ |
|
58
|
|
|
private $options; |
|
59
|
|
|
|
|
60
|
|
|
public function __construct( |
|
61
|
|
|
WidgetConfigurationInterface $configuration, |
|
62
|
|
|
ChartDataProviderInterface $dataProvider, |
|
63
|
|
|
StandaloneView $view, |
|
64
|
|
|
$buttonProvider = null, |
|
65
|
|
|
array $options = [] |
|
66
|
|
|
) { |
|
67
|
|
|
$this->configuration = $configuration; |
|
68
|
|
|
$this->dataProvider = $dataProvider; |
|
69
|
|
|
$this->view = $view; |
|
70
|
|
|
$this->options = $options; |
|
71
|
|
|
$this->buttonProvider = $buttonProvider; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function renderWidgetContent(): string |
|
75
|
|
|
{ |
|
76
|
|
|
$this->view->setTemplate('Widget/ChartWidget'); |
|
77
|
|
|
$this->view->assignMultiple([ |
|
78
|
|
|
'button' => $this->buttonProvider, |
|
79
|
|
|
'options' => $this->options, |
|
80
|
|
|
'configuration' => $this->configuration, |
|
81
|
|
|
]); |
|
82
|
|
|
return $this->view->render(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getEventData(): array |
|
86
|
|
|
{ |
|
87
|
|
|
return [ |
|
88
|
|
|
'graphConfig' => [ |
|
89
|
|
|
'type' => 'doughnut', |
|
90
|
|
|
'options' => [ |
|
91
|
|
|
'maintainAspectRatio' => false, |
|
92
|
|
|
'legend' => [ |
|
93
|
|
|
'display' => true, |
|
94
|
|
|
'position' => 'bottom' |
|
95
|
|
|
], |
|
96
|
|
|
'cutoutPercentage' => 60 |
|
97
|
|
|
], |
|
98
|
|
|
'data' => $this->dataProvider->getChartData(), |
|
99
|
|
|
], |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getCssFiles(): array |
|
104
|
|
|
{ |
|
105
|
|
|
return ['EXT:dashboard/Resources/Public/Css/Contrib/chart.css']; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getRequireJsModules(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return [ |
|
111
|
|
|
'TYPO3/CMS/Dashboard/Contrib/chartjs', |
|
112
|
|
|
'TYPO3/CMS/Dashboard/ChartInitializer', |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return array |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getOptions(): array |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->options; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|