1 | <?php |
||
15 | class PartitionResult extends Result |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Properties |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** |
||
23 | * The custom label names. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | public $labels = []; |
||
28 | |||
29 | /** |
||
30 | * The custom label colors. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | public $colors = []; |
||
35 | |||
36 | /** |
||
37 | * The sort direction [asc, desc]. |
||
38 | * |
||
39 | * @var string|null |
||
40 | */ |
||
41 | private $sort; |
||
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Setters |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Set the value. |
||
50 | * |
||
51 | * @param mixed $value |
||
52 | * |
||
53 | * @return $this|mixed |
||
54 | */ |
||
55 | 60 | public function value($value) |
|
61 | |||
62 | /* ----------------------------------------------------------------- |
||
63 | | Getters & Setters |
||
64 | | ----------------------------------------------------------------- |
||
65 | */ |
||
66 | |||
67 | /** |
||
68 | * Format the labels for the partition result. |
||
69 | * |
||
70 | * @param \Closure $callback |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | 4 | public function label(Closure $callback) |
|
80 | |||
81 | /** |
||
82 | * Set the labels for the partition result. |
||
83 | * |
||
84 | * @param array $labels |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | 8 | public function labels(array $labels) |
|
94 | |||
95 | /** |
||
96 | * Set the colors for the partition result. |
||
97 | * |
||
98 | * @param \Closure $callback |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | 4 | public function color(Closure $callback) |
|
108 | |||
109 | /** |
||
110 | * Set the custom label colors. |
||
111 | * |
||
112 | * @param array $colors |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | 8 | public function colors(array $colors) |
|
122 | |||
123 | /** |
||
124 | * Set the sort direction. |
||
125 | * |
||
126 | * @param string $direction |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | 4 | public function sort(string $direction = 'asc') |
|
139 | |||
140 | /* ----------------------------------------------------------------- |
||
141 | | Common Methods |
||
142 | | ----------------------------------------------------------------- |
||
143 | */ |
||
144 | |||
145 | /** |
||
146 | * Convert the metric object to array. |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | 40 | public function toArray(): array |
|
162 | |||
163 | /* ----------------------------------------------------------------- |
||
164 | | Other Methods |
||
165 | | ----------------------------------------------------------------- |
||
166 | */ |
||
167 | |||
168 | /** |
||
169 | * Transform the value by the given callback |
||
170 | * |
||
171 | * @param \Closure $callback |
||
172 | * |
||
173 | * @return \Illuminate\Support\Collection |
||
174 | */ |
||
175 | 40 | private function mapValue(Closure $callback) |
|
181 | |||
182 | /** |
||
183 | * Format the value. |
||
184 | * |
||
185 | * @param mixed $key |
||
186 | * @param mixed $value |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | 40 | protected function formatValue($key, $value): array |
|
198 | } |
||
199 |