forked from remp2020/crm-application-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleBarGraph.php
80 lines (65 loc) · 2.03 KB
/
GoogleBarGraph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Crm\ApplicationModule\Components\Graphs;
/**
* Google bar graph component
*
* Component for rendering bar graph using google graph library.
*
* @package Crm\ApplicationModule\Components\Graphs
*/
class GoogleBarGraph extends BaseGraphControl
{
private $view = 'google_bar_graph';
private $yLabel = '[Y label]';
private $xAxis = [];
private $graphTitle = '[Názov grafu]';
private $graphHelp = 'help';
private $height = 300;
private $stacked = true;
public function setStacked($stacked)
{
$this->stacked = $stacked;
return $this;
}
public function setYLabel($ylabel)
{
$this->yLabel = $ylabel;
return $this;
}
public function setGraphTitle($graphTitle)
{
$this->graphTitle = $graphTitle;
return $this;
}
public function setGraphHelp($graphHelp)
{
$this->graphHelp = $graphHelp;
return $this;
}
public function addSerie($name, $data)
{
$this->series[$name] = $data;
if (!$this->xAxis) {
$this->xAxis = array_keys($data);
}
ksort($this->series);
return $this;
}
public function render($redraw = false, $asyncLoad = true)
{
$this->template->redraw = $redraw;
$this->template->graphId = $this->generateGraphId();
$this->template->graphTitle = $this->graphTitle;
$this->template->graphHelp = $this->graphHelp;
$this->template->xAxis = $this->xAxis;
$this->template->yLabel = $this->yLabel;
$this->template->series = $this->series;
$this->template->height = empty($this->series) ? 0 : $this->height;
$this->template->stacked = $this->stacked;
$this->template->graphDataJs = $this->getDataForJs();
$this->template->asyncLoad = $asyncLoad;
$this->template->loaded = !$asyncLoad || $this->getPresenter()->isAjax() ? true : false;
$this->template->setFile(__DIR__ . '/' . $this->view . '.latte');
$this->template->render();
}
}