-
Notifications
You must be signed in to change notification settings - Fork 7
/
GoogleLineGraph.php
73 lines (59 loc) · 1.95 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
71
72
73
<?php
namespace Crm\ApplicationModule\Components\Graphs\GoogleLineGraph;
use Crm\ApplicationModule\Components\Graphs\BaseGraphControl;
/**
* 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->chartViewWindowMin = $this->getChartViewWindowMin();
$this->template->asyncLoad = $asyncLoad;
$this->template->loaded = !$asyncLoad || $this->getPresenter()->isAjax();
$this->template->setFile(__DIR__ . '/' . $this->view . '.latte');
$this->template->render();
}
}