1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CarlosIO\Geckoboard\Widgets; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class LineChart. |
7
|
|
|
*/ |
8
|
|
|
class HighchartsChart extends Widget |
9
|
|
|
{ |
10
|
|
|
protected $type; |
11
|
|
|
|
12
|
|
|
protected $title; |
13
|
|
|
|
14
|
|
|
protected $subtitle; |
15
|
|
|
|
16
|
|
|
protected $series = array(); |
17
|
|
|
|
18
|
|
|
protected $xAxisTitle; |
19
|
|
|
|
20
|
|
|
protected $xAxisLabels = array(); |
21
|
|
|
|
22
|
|
|
protected $yAxisTitle; |
23
|
|
|
|
24
|
|
|
protected $yAxisLabels = array(); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
3 |
|
public function getSeries() |
30
|
|
|
{ |
31
|
3 |
|
return $this->series; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array $series |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
1 |
|
public function setSeries($series) |
40
|
|
|
{ |
41
|
1 |
|
$this->series = $series; |
42
|
|
|
|
43
|
1 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
3 |
|
public function getSubtitle() |
50
|
|
|
{ |
51
|
3 |
|
return $this->subtitle; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param mixed $subtitle |
56
|
|
|
* |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
3 |
|
public function setSubtitle($subtitle) |
60
|
|
|
{ |
61
|
3 |
|
$this->subtitle = $subtitle; |
62
|
|
|
|
63
|
3 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
3 |
|
public function getTitle() |
70
|
|
|
{ |
71
|
3 |
|
return $this->title; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param mixed $title |
76
|
|
|
* |
77
|
|
|
* @return $this |
78
|
|
|
*/ |
79
|
3 |
|
public function setTitle($title) |
80
|
|
|
{ |
81
|
3 |
|
$this->title = $title; |
82
|
|
|
|
83
|
3 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
3 |
|
public function getType() |
90
|
|
|
{ |
91
|
3 |
|
return $this->type; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param mixed $type |
96
|
|
|
* |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
3 |
|
public function setType($type) |
100
|
|
|
{ |
101
|
3 |
|
$this->type = $type; |
102
|
|
|
|
103
|
3 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
3 |
|
public function getXAxisLabels() |
110
|
|
|
{ |
111
|
3 |
|
return $this->xAxisLabels; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param array $xAxisLabels |
116
|
|
|
* |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
2 |
|
public function setXAxisLabels($xAxisLabels) |
120
|
|
|
{ |
121
|
2 |
|
$this->xAxisLabels = $xAxisLabels; |
122
|
|
|
|
123
|
2 |
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return mixed |
128
|
|
|
*/ |
129
|
3 |
|
public function getXAxisTitle() |
130
|
|
|
{ |
131
|
3 |
|
return $this->xAxisTitle; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param mixed $xAxisTitle |
136
|
|
|
* |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
1 |
|
public function setXAxisTitle($xAxisTitle) |
140
|
|
|
{ |
141
|
1 |
|
$this->xAxisTitle = $xAxisTitle; |
142
|
|
|
|
143
|
1 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
3 |
|
public function getYAxisLabels() |
150
|
|
|
{ |
151
|
3 |
|
return $this->yAxisLabels; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param array $yAxisLabels |
156
|
|
|
* |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
1 |
|
public function setYAxisLabels($yAxisLabels) |
160
|
|
|
{ |
161
|
1 |
|
$this->yAxisLabels = $yAxisLabels; |
162
|
|
|
|
163
|
1 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return mixed |
168
|
|
|
*/ |
169
|
3 |
|
public function getYAxisTitle() |
170
|
|
|
{ |
171
|
3 |
|
return $this->yAxisTitle; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param mixed $yAxisTitle |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
2 |
|
public function setYAxisTitle($yAxisTitle) |
180
|
|
|
{ |
181
|
2 |
|
$this->yAxisTitle = $yAxisTitle; |
182
|
|
|
|
183
|
2 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
2 |
|
public function setSingleSerie($serieName, $serie) |
187
|
|
|
{ |
188
|
2 |
|
$this->series[$serieName] = $serie; |
189
|
2 |
|
} |
190
|
|
|
|
191
|
1 |
|
public function addItemSerie($serieName, $item) |
192
|
|
|
{ |
193
|
1 |
|
if (!isset($this->series[$serieName])) { |
194
|
1 |
|
$this->setSingleSerie($serieName, array()); |
195
|
1 |
|
} |
196
|
1 |
|
$this->series[$serieName][] = $item; |
197
|
1 |
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritdoc} |
201
|
|
|
*/ |
202
|
3 |
|
public function getData() |
203
|
|
|
{ |
204
|
|
|
$returnValues = array( |
205
|
|
|
'chart' => array( |
206
|
3 |
|
'type' => $this->getType(), |
207
|
3 |
|
), |
208
|
|
|
'title' => array( |
209
|
3 |
|
'text' => $this->getTitle(), |
210
|
3 |
|
), |
211
|
|
|
'subtitle' => array( |
212
|
3 |
|
'text' => $this->getSubtitle(), |
213
|
3 |
|
), |
214
|
3 |
|
); |
215
|
|
|
|
216
|
3 |
|
if ($this->getXAxisLabels()) { |
217
|
2 |
|
$returnValues['xAxis']['categories'] = $this->getXAxisLabels(); |
218
|
2 |
|
} |
219
|
|
|
|
220
|
3 |
|
if ($this->getYAxisLabels()) { |
221
|
1 |
|
$returnValues['yAxis']['categories'] = $this->getYAxisLabels(); |
222
|
1 |
|
} |
223
|
|
|
|
224
|
3 |
|
if ($this->getXAxisTitle()) { |
225
|
1 |
|
$returnValues['xAxis']['title']['text'] = $this->getXAxisTitle(); |
226
|
1 |
|
} |
227
|
|
|
|
228
|
3 |
|
if ($this->getYAxisTitle()) { |
229
|
2 |
|
$returnValues['yAxis']['title']['text'] = $this->getYAxisTitle(); |
230
|
2 |
|
} |
231
|
|
|
|
232
|
3 |
|
$returnValues['plotOptions'] = array( |
233
|
|
|
'line' => array( |
234
|
|
|
'dataLabels' => array( |
235
|
3 |
|
'enabled' => true, |
236
|
3 |
|
), |
237
|
3 |
|
'enableMouseTracking' => false, |
238
|
3 |
|
), |
239
|
|
|
); |
240
|
|
|
|
241
|
3 |
|
return array('highchart' => $this->addSeriesData($returnValues)); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param $returnValues |
246
|
|
|
* |
247
|
|
|
* @return mixed |
248
|
|
|
*/ |
249
|
3 |
|
private function addSeriesData($returnValues) |
250
|
|
|
{ |
251
|
3 |
|
foreach ($this->getSeries() as $serieName => $serieValues) { |
252
|
3 |
|
$returnValues['series'][] = array( |
253
|
3 |
|
'name' => (isset($serieValues['name']) && $serieValues['name']) ? $serieValues['name'] : $serieName, |
254
|
3 |
|
'data' => (isset($serieValues['data']) && $serieValues['data']) ? $serieValues['data'] : $serieValues, |
255
|
3 |
|
'type' => (isset($serieValues['type']) && $serieValues['type']) ? $serieValues['type'] : 'line', |
256
|
|
|
); |
257
|
3 |
|
} |
258
|
|
|
|
259
|
3 |
|
return $returnValues; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|