1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created for IG Monitoring. |
4
|
|
|
* User: jakim <[email protected]> |
5
|
|
|
* Date: 2019-01-26 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace app\components\visualizations\traits; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use app\dictionaries\Color; |
12
|
|
|
use app\models\Account; |
13
|
|
|
use yii\base\InvalidConfigException; |
14
|
|
|
|
15
|
|
|
trait AccountDataProviderTrait |
16
|
|
|
{ |
17
|
|
|
public $colors = [ |
18
|
|
|
'followed_by' => Color::PRIMARY, |
19
|
|
|
'follows' => Color::PURPLE, |
20
|
|
|
'media' => Color::ORANGE, |
21
|
|
|
'er' => Color::SUCCESS, |
22
|
|
|
'avg_likes' => Color::INFO, |
23
|
|
|
'avg_comments' => Color::TEAL, |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
public $labelFormat = 'date'; |
27
|
|
|
|
28
|
|
|
public $dataSetsConfig = []; |
29
|
|
|
|
30
|
|
|
public $scalesConfig = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \app\models\Account |
34
|
|
|
*/ |
35
|
|
|
public $account; |
36
|
|
|
|
37
|
|
|
public function setAccount(Account $account) |
38
|
|
|
{ |
39
|
|
|
$this->account = $account; |
40
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function throwExceptionIfAccountIsNotSet() |
45
|
|
|
{ |
46
|
|
|
if (!$this->account) { |
47
|
|
|
throw new InvalidConfigException('Property \'account\' can not be empty.'); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private $labels; |
52
|
|
|
|
53
|
|
|
private $dataSets; |
54
|
|
|
|
55
|
|
|
private $scales; |
56
|
|
|
|
57
|
|
|
public function labels() |
58
|
|
|
{ |
59
|
|
|
if (!$this->labels) { |
60
|
|
|
$this->labels = $this->prepareLabels(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->labels; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function dataSets() |
67
|
|
|
{ |
68
|
|
|
if (!$this->dataSets) { |
69
|
|
|
$this->dataSets = $this->prepareDataSets(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->dataSets; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function scales() |
76
|
|
|
{ |
77
|
|
|
if (!$this->scales) { |
78
|
|
|
$this->scales = $this->prepareScales(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this->scales; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
abstract protected function prepareLabels(): array; |
85
|
|
|
|
86
|
|
|
abstract protected function prepareDataSets(): array; |
87
|
|
|
|
88
|
|
|
abstract protected function prepareScales(): array; |
89
|
|
|
} |