-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChart.php
177 lines (163 loc) · 3.58 KB
/
Chart.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* Google_Chart
* Class to setup chart objects
*/
/**
* Google_Chart
* @desc Class to setup chart objects
* @package Google
* @author Thomas Schäfer
* @link [email protected]
* @desc
*/
class Google_Chart {
/**
* @var string $provider
*/
private $provider = 'google';
/**
* @var string $scope
*/
private $scope = 'visualization';
/**
* @var string $type
*/
private $type = '';
/**
* @var array $data
*/
private $data;
/**
* @var string $version
*/
private $version;
/**
* @var array $properties
*/
private $properties=null;
/**
* @var array $options
*/
private $options=null;
/**
* @var string $dataTable
*/
private $dataTable='';
/**
* constructor
* @param string $type
* @param array $data
* @param string $version
* @return void
*/
public function __construct($type, $data, $version=null) {
$this->type = $type;
$this->data = $data;
$this->version = $version;
}
/**
* getDataTable
* @desc getter for data table name
* @return string
*/
public function getDataTable() {
return $this->dataTable;
}
/**
* setDataTable
* @param srting $name
* @return void
*/
public function setDataTable($name) {
$this->dataTable = $name;
}
/**
* draw
* @desc php method to simulate Google's default draw method
* @param array|Google_Data_View $data
* @param array $options
* @return void
*/
public function draw($data, $options=null) {
$this->options = $options;
$arr = array();
if($data instanceof Google_Data_View) {
$arr[] = $data->getViewTable();
} else {
$this->dataTable = $data;
$arr[] = $data;
}
if($options) {
$_options = $options->getProperties();
if($_options instanceof Google_Config_Default or $_options instanceof stdClass) {
$arr[] = Google_Base::toJSON($_options);
} else {
$arr[] = $options->getProperties();
}
} else {
$arr[] = 'null';
}
$this->properties[__FUNCTION__][] = $arr;
}
/**
* render
* @desc prints out the rendered chart object
* @return string
*/
public function render() {
$string = $this->getDataTable().'=new ';
$string .= $this->provider;
$string .= '.';
$string .= $this->scope;
$string .= '.';
if($this->options instanceof Google_Config_Default) {
$string .= $this->options->getConfigObject()->type;
} else {
$string .= $this->type;
}
$string .= '(';
if($this->data) $string .= $this->data;
if($this->version) $string .= ','.$this->version;
$string .= ');';
$string .= "\n";
if(is_array($this->properties)){
foreach($this->properties as $method => $parameters) {
foreach($parameters as $signature) {
$string .= ' '.$this->getDataTable().'.'.$method.'('.(is_array($signature)?implode(',',$signature):$signature).');'."\n";
}
}
}
return $string;
}
/**
* __toString
* @return string
*/
public function __toString() {
$string = 'var chart_'.$this->data.'=new ';
$string .= $this->provider;
$string .= '.';
$string .= $this->scope;
$string .= '.';
if($this->options instanceof Google_Config_Default) {
$string .= $this->options->getConfigObject()->type;
} else {
$string .= $this->type;
}
$string .= '(';
if($this->data) $string .= $this->data;
if($this->version) $string .= ','.$this->version;
$string .= ');';
$string .= "\n";
if(is_array($this->properties)){
foreach($this->properties as $method => $parameters) {
foreach($parameters as $signature) {
$string .= 'chart_'.$this->data.'.'.$method.'('.(is_array($signature)?implode(',',$signature):$signature).');'."\n";
}
}
}
$string .= "\n";
return $string;
}
}