forked from Koenster/php-graphs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PHPChart.php
101 lines (90 loc) · 2.18 KB
/
PHPChart.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php namespace koenster\PHPGraphs;
use koenster\PHPGraphs\contract\ChartContract;
use koenster\PHPGraphs\exceptions\GraphImplementationNotFoundException;
use koenster\PHPGraphs\implementation\ChartJSImplementation;
use koenster\PHPGraphs\implementation\MorrisJSImplementation;
class PHPChart {
const IMPLEMENTATION_CHART_JS = 'ChartJS';
const IMPLEMENTATION_MORRIS = 'Morris';
const TYPE_LINE = 'Line';
const TYPE_BAR = 'Bar';
const TYPE_RADAR = 'Radar';
const TYPE_AREA = 'Area';
const TYPE_PIE = 'Pie';
const TYPE_DOUGHNUT = 'Doughnut';
/**
* @var ChartContract
*/
protected $factory;
/**
* @var array
*/
protected $graphs = [];
/**
* El constructor
*
* Will construct the factory
*
* @param $implementation
*
* @param array $attributes
*
* @throws GraphImplementationNotFoundException
*/
public function __construct($implementation, array $attributes = [])
{
switch ($implementation) {
case "ChartJS" :
$this->factory = new ChartJSImplementation();
break;
case "MorrisJS" :
$this->factory = new MorrisJSImplementation();
break;
default :
throw new GraphImplementationNotFoundException();
}
return $this;
}
/**
* Will get the JS
*
* @author Koen Blokland Visser
*
* @param $id
* @param $type
* @param array $params
*
* @return ChartContract
*/
public function add($type, $id, array $params = [])
{
$factory = clone $this->factory;
$factory->setType($id, $type, $params);
$this->graphs[$id] = $factory;
return $factory;
}
/**
* Will get the JS
*
* @author Koen Blokland Visser
*
* @return ChartContract
*/
public function getFactory()
{
if ($this->factory) {
return $this->factory;
}
}
/**
* Will get the Graphs
*
* @author Koen Blokland Visser
*
* @return array
*/
public function getGraphs()
{
return $this->graphs;
}
}