1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Muspelheim\C3ChartsBundle\C3; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class AbstractChart |
7
|
|
|
* @package Muspelheim\C3ChartsBundle\C3 |
8
|
|
|
*/ |
9
|
|
|
abstract class AbstractChart |
10
|
|
|
{ |
11
|
|
|
protected static $chartOptions = [ |
12
|
|
|
'bindto', 'area', 'size', 'data', 'padding', 'color', 'interaction', 'transition', 'axis', 'gauge', |
13
|
|
|
'grid', 'region', 'legend', 'tootip', 'subchart', 'zoom', 'point', 'line', 'bar', 'pie', 'donut', 'tooltip', |
14
|
|
|
'title', |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
// Default options |
18
|
|
|
public $bindto; |
19
|
|
|
public $area; |
20
|
|
|
public $size; |
21
|
|
|
public $data; |
22
|
|
|
public $padding; |
23
|
|
|
public $color; |
24
|
|
|
public $interaction; |
25
|
|
|
public $transition; |
26
|
|
|
public $axis; |
27
|
|
|
public $grid; |
28
|
|
|
public $region; |
29
|
|
|
public $legend; |
30
|
|
|
public $tooltip; |
31
|
|
|
public $subchart; |
32
|
|
|
public $zoom; |
33
|
|
|
public $point; |
34
|
|
|
public $line; |
35
|
|
|
public $bar; |
36
|
|
|
public $pie; |
37
|
|
|
public $donut; |
38
|
|
|
public $gauge; |
39
|
|
|
public $title; |
40
|
|
|
|
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
foreach (static::$chartOptions as $option) { |
44
|
|
|
$this->initChartOption($option); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
abstract public function render(); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $name |
52
|
|
|
* @param array $args |
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function __call(string $name, array $args) |
57
|
|
|
{ |
58
|
|
|
$this->$name = $args[0]; |
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $name |
65
|
|
|
*/ |
66
|
|
|
protected function initChartOption(string $name) |
67
|
|
|
{ |
68
|
|
|
$this->{$name} = new ChartOption($name); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
protected function renderBindTo(): string |
75
|
|
|
{ |
76
|
|
|
if ($this->bindto) { |
77
|
|
|
return 'bindto: ' . json_encode('#'.$this->bindto) . ",\n"; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return ''; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
protected function renderArea(): string |
87
|
|
|
{ |
88
|
|
|
if (get_object_vars($this->area->area)) { |
89
|
|
|
return 'area: ' . json_encode($this->area->area) . ",\n"; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return ''; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
protected function renderSize(): string |
99
|
|
|
{ |
100
|
|
|
if (get_object_vars($this->size->size)) { |
101
|
|
|
return 'size: ' . json_encode($this->size->size) . ",\n"; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return ''; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
protected function renderData(): string |
111
|
|
|
{ |
112
|
|
|
if (get_object_vars($this->data->data)) { |
113
|
|
|
return 'data: ' . json_encode($this->data->data) . ",\n"; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return ''; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
protected function renderPadding(): string |
123
|
|
|
{ |
124
|
|
|
if (get_object_vars($this->padding->padding)) { |
125
|
|
|
return 'padding: ' . json_encode($this->padding->padding) . ",\n"; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return ''; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
protected function renderColor(): string |
135
|
|
|
{ |
136
|
|
|
if (get_object_vars($this->color->color)) { |
137
|
|
|
return 'color: ' . json_encode($this->color->color) . ",\n"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return ''; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
protected function renderInteraction(): string |
147
|
|
|
{ |
148
|
|
|
if (get_object_vars($this->interaction->interaction)) { |
149
|
|
|
return 'interaction: ' . json_encode($this->interaction->interaction) . ",\n"; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return ''; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
protected function renderTransition(): string |
159
|
|
|
{ |
160
|
|
|
if (get_object_vars($this->transition->transition)) { |
161
|
|
|
return 'transition: ' . json_encode($this->transition->transition) . ",\n"; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return ''; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
protected function renderAxis(): string |
171
|
|
|
{ |
172
|
|
|
if (get_object_vars($this->axis->axis)) { |
173
|
|
|
return 'axis: ' . json_encode($this->axis->axis) . ",\n"; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return ''; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return string |
181
|
|
|
*/ |
182
|
|
|
protected function renderGrid(): string |
183
|
|
|
{ |
184
|
|
|
if (get_object_vars($this->grid->grid)) { |
185
|
|
|
return 'grid: ' . json_encode($this->grid->grid) . ",\n"; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return ''; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
protected function renderRegion(): string |
195
|
|
|
{ |
196
|
|
|
if (get_object_vars($this->region->region)) { |
197
|
|
|
return 'region: ' . json_encode($this->region->region) . ",\n"; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
return ''; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
|
|
protected function renderLegend(): string |
207
|
|
|
{ |
208
|
|
|
if (get_object_vars($this->legend->legend)) { |
209
|
|
|
return 'legend: ' . json_encode($this->legend->legend) . ",\n"; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return ''; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
protected function renderTooltip(): string |
219
|
|
|
{ |
220
|
|
|
if (get_object_vars($this->tooltip->tooltip)) { |
221
|
|
|
return 'tooltip: ' . json_encode($this->tooltip->tooltip) . ",\n"; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
return ''; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return string |
229
|
|
|
*/ |
230
|
|
|
protected function renderSubchart(): string |
231
|
|
|
{ |
232
|
|
|
if (get_object_vars($this->subchart->subchart)) { |
233
|
|
|
return 'subchart: ' . json_encode($this->subchart->subchart) . ",\n"; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
return ''; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @return string |
241
|
|
|
*/ |
242
|
|
|
protected function renderZoom(): string |
243
|
|
|
{ |
244
|
|
|
if (get_object_vars($this->zoom->zoom)) { |
245
|
|
|
return 'zoom: ' . json_encode($this->zoom->zoom) . ",\n"; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
return ''; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return string |
253
|
|
|
*/ |
254
|
|
|
protected function renderPoint(): string |
255
|
|
|
{ |
256
|
|
|
if (get_object_vars($this->point->point)) { |
257
|
|
|
return 'point: ' . json_encode($this->point->point) . ",\n"; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
return ''; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return string |
265
|
|
|
*/ |
266
|
|
|
protected function renderLine(): string |
267
|
|
|
{ |
268
|
|
|
if (get_object_vars($this->line->line)) { |
269
|
|
|
return 'line: ' . json_encode($this->line->line) . ",\n"; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
return ''; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @return string |
277
|
|
|
*/ |
278
|
|
|
protected function renderBar(): string |
279
|
|
|
{ |
280
|
|
|
if (get_object_vars($this->bar->bar)) { |
281
|
|
|
return 'bar: ' . json_encode($this->bar->bar) . ",\n"; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return ''; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return string |
289
|
|
|
*/ |
290
|
|
|
protected function renderPie(): string |
291
|
|
|
{ |
292
|
|
|
if (get_object_vars($this->pie->pie)) { |
293
|
|
|
return 'pie: ' . json_encode($this->pie->pie) . ",\n"; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
return ''; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @return string |
301
|
|
|
*/ |
302
|
|
|
protected function renderDonut(): string |
303
|
|
|
{ |
304
|
|
|
if (get_object_vars($this->donut->donut)) { |
305
|
|
|
return 'donut: ' . json_encode($this->donut->donut) . ",\n"; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
return ''; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @return string |
313
|
|
|
*/ |
314
|
|
|
protected function renderGauge(): string |
315
|
|
|
{ |
316
|
|
|
if (get_object_vars($this->gauge->gauge)) { |
317
|
|
|
return 'gauge: ' . json_encode($this->gauge->gauge) . ",\n"; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
return ''; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return string |
325
|
|
|
*/ |
326
|
|
|
protected function renderTitle(): string |
327
|
|
|
{ |
328
|
|
|
if (get_object_vars($this->title->title)) { |
329
|
|
|
return 'title: ' . json_encode($this->title->title) . ",\n"; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
return ''; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
|