forked from remp2020/crm-application-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleLineGraph.php
70 lines (57 loc) · 1.81 KB
/
GoogleLineGraph.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
<?php
namespace Crm\ApplicationModule\Components\Graphs;
/**
* Google line graph component
*
* Component for rendering line graph using google graph library.
*
* @package Crm\ApplicationModule\Components\Graphs
*/
class GoogleLineGraph extends BaseGraphControl
{
private $view = 'google_line_graph';
private $yLabel = '[Y label]';
private $xAxis = [];
private $graphTitle = '[Názov grafu]';
private $graphHelp = 'Help';
private $height = 300;
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);
}
return $this;
}
public function render($redraw, $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->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();
}
}