rgraph-rails 5.00 → 6.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish-geml.yaml +46 -0
- data/.gitignore +1 -0
- data/README.md +4 -5
- data/lib/rgraph-rails/version.rb +1 -1
- data/rgraph-rails.gemspec +4 -4
- data/vendor/assets/javascripts/RGraph.activity.js +1691 -0
- data/vendor/assets/javascripts/RGraph.bar.js +4253 -236
- data/vendor/assets/javascripts/RGraph.bipolar.js +3958 -162
- data/vendor/assets/javascripts/RGraph.common.annotate.js +414 -35
- data/vendor/assets/javascripts/RGraph.common.context.js +635 -30
- data/vendor/assets/javascripts/RGraph.common.core.js +10485 -419
- data/vendor/assets/javascripts/RGraph.common.csv.js +508 -27
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +1693 -90
- data/vendor/assets/javascripts/RGraph.common.effects.js +1629 -89
- data/vendor/assets/javascripts/RGraph.common.key.js +1003 -53
- data/vendor/assets/javascripts/RGraph.common.moment.js +5670 -0
- data/vendor/assets/javascripts/RGraph.common.sheets.js +541 -31
- data/vendor/assets/javascripts/RGraph.common.sheets.php +351 -0
- data/vendor/assets/javascripts/RGraph.common.starburst.js +382 -0
- data/vendor/assets/javascripts/RGraph.common.table.js +386 -0
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +1433 -32
- data/vendor/assets/javascripts/RGraph.drawing.background.js +660 -35
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +618 -34
- data/vendor/assets/javascripts/RGraph.drawing.image.js +857 -52
- data/vendor/assets/javascripts/RGraph.drawing.line.js +712 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +760 -38
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +740 -37
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +573 -36
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +667 -36
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +638 -34
- data/vendor/assets/javascripts/RGraph.drawing.text.js +672 -37
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +653 -52
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +714 -51
- data/vendor/assets/javascripts/RGraph.fuel.js +1149 -59
- data/vendor/assets/javascripts/RGraph.funnel.js +1277 -56
- data/vendor/assets/javascripts/RGraph.gantt.js +1646 -82
- data/vendor/assets/javascripts/RGraph.gauge.js +1773 -89
- data/vendor/assets/javascripts/RGraph.hbar.js +3869 -159
- data/vendor/assets/javascripts/RGraph.horseshoe.js +970 -0
- data/vendor/assets/javascripts/RGraph.hprogress.js +1829 -81
- data/vendor/assets/javascripts/RGraph.line.js +5293 -244
- data/vendor/assets/javascripts/RGraph.meter.js +1570 -77
- data/vendor/assets/javascripts/RGraph.modaldialog.js +300 -19
- data/vendor/assets/javascripts/RGraph.odo.js +1553 -68
- data/vendor/assets/javascripts/RGraph.pie.js +3273 -129
- data/vendor/assets/javascripts/RGraph.radar.js +2333 -108
- data/vendor/assets/javascripts/RGraph.rose.js +2685 -114
- data/vendor/assets/javascripts/RGraph.rscatter.js +1920 -80
- data/vendor/assets/javascripts/RGraph.scatter.js +4215 -171
- data/vendor/assets/javascripts/RGraph.segmented.js +1006 -0
- data/vendor/assets/javascripts/RGraph.semicircularprogress.js +1980 -59
- data/vendor/assets/javascripts/RGraph.svg.activity.js +1696 -0
- data/vendor/assets/javascripts/RGraph.svg.bar.js +2575 -77
- data/vendor/assets/javascripts/RGraph.svg.bipolar.js +3533 -106
- data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +240 -21
- data/vendor/assets/javascripts/RGraph.svg.common.core.js +7105 -299
- data/vendor/assets/javascripts/RGraph.svg.common.csv.js +408 -28
- data/vendor/assets/javascripts/RGraph.svg.common.fx.js +1291 -68
- data/vendor/assets/javascripts/RGraph.svg.common.key.js +451 -20
- data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +543 -31
- data/vendor/assets/javascripts/RGraph.svg.common.table.js +391 -0
- data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +1072 -23
- data/vendor/assets/javascripts/RGraph.svg.funnel.js +1151 -32
- data/vendor/assets/javascripts/RGraph.svg.gauge.js +1429 -34
- data/vendor/assets/javascripts/RGraph.svg.hbar.js +2692 -65
- data/vendor/assets/javascripts/RGraph.svg.horseshoe.js +969 -0
- data/vendor/assets/javascripts/RGraph.svg.line.js +2855 -86
- data/vendor/assets/javascripts/RGraph.svg.pie.js +1630 -58
- data/vendor/assets/javascripts/RGraph.svg.radar.js +1772 -58
- data/vendor/assets/javascripts/RGraph.svg.rose.js +2419 -83
- data/vendor/assets/javascripts/RGraph.svg.scatter.js +2280 -65
- data/vendor/assets/javascripts/RGraph.svg.segmented.js +930 -0
- data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +1612 -29
- data/vendor/assets/javascripts/RGraph.svg.waterfall.js +1525 -50
- data/vendor/assets/javascripts/RGraph.thermometer.js +1411 -64
- data/vendor/assets/javascripts/RGraph.vprogress.js +1915 -81
- data/vendor/assets/javascripts/RGraph.waterfall.js +1896 -89
- data/vendor/assets/javascripts/financial-data.js +1067 -0
- metadata +37 -16
- data/.travis.yml +0 -11
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +0 -35
- data/vendor/assets/javascripts/RGraph.common.resizing.js +0 -38
- data/vendor/assets/javascripts/RGraph.common.zoom.js +0 -15
- data/vendor/assets/javascripts/RGraph.cornergauge.js +0 -71
@@ -0,0 +1,351 @@
|
|
1
|
+
<?php
|
2
|
+
// o--------------------------------------------------------------------------------o
|
3
|
+
// | This file is part of the RGraph package - you can learn more at: |
|
4
|
+
// | |
|
5
|
+
// | https://www.rgraph.net |
|
6
|
+
// | |
|
7
|
+
// | RGraph is licensed under the Open Source MIT license. That means that it's |
|
8
|
+
// | totally free to use and there are no restrictions on what you can do with it! |
|
9
|
+
// o--------------------------------------------------------------------------------o
|
10
|
+
|
11
|
+
// Version 1.03
|
12
|
+
|
13
|
+
class RGraph_Sheets
|
14
|
+
{
|
15
|
+
// The key of the spreadsheet
|
16
|
+
public $key;
|
17
|
+
|
18
|
+
// The data of the spreadsheet
|
19
|
+
public $data;
|
20
|
+
|
21
|
+
// Your OAuth ID
|
22
|
+
public $oauth;
|
23
|
+
|
24
|
+
// The worksheet ID
|
25
|
+
public $worksheet = 'Sheet1';
|
26
|
+
|
27
|
+
// Used for the columnn names.
|
28
|
+
public $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
29
|
+
|
30
|
+
// The URL of the sheet
|
31
|
+
public $url = 'https://sheets.googleapis.com/v4/spreadsheets/[KEY]/values/[WORKSHEET]?alt=json&key=[OAUTH_KEY]';
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
//
|
37
|
+
// The constructor that creates the object
|
38
|
+
//
|
39
|
+
// @param string $key The identifier of the spreadsheet. You can get this
|
40
|
+
// out of the URL for the spreadsheetsheet.
|
41
|
+
//
|
42
|
+
public function __construct ($oauth, $key = '', $worksheet = 'Sheet1')
|
43
|
+
{
|
44
|
+
$this->oauth = $oauth;
|
45
|
+
$this->key = $key;
|
46
|
+
$this->worksheet = $worksheet;
|
47
|
+
|
48
|
+
// Do this if the key is a file: URL
|
49
|
+
if (substr($this->oauth, 0, 5) === 'file:') {
|
50
|
+
$filename = substr($this->oauth, 5);
|
51
|
+
$this->json_raw = file_get_contents($filename);
|
52
|
+
|
53
|
+
} else {
|
54
|
+
// Add the key and worksheet ID into the URL
|
55
|
+
$this->url = preg_replace('/\[OAUTH_KEY\]/', $this->oauth, $this->url);
|
56
|
+
$this->url = preg_replace('/\[KEY\]/', $this->key, $this->url);
|
57
|
+
$this->url = preg_replace('/\[WORKSHEET\]/', urlencode($this->worksheet), $this->url);
|
58
|
+
|
59
|
+
// Fetch the sheet
|
60
|
+
$this->json_raw = file_get_contents($this->url);
|
61
|
+
}
|
62
|
+
|
63
|
+
// Get rid of comments
|
64
|
+
//$this->json = trim(preg_replace('|// API callback|m','',$this->json_raw));
|
65
|
+
|
66
|
+
// Get rid of the JSONP function call
|
67
|
+
//$this->json = preg_replace('/^__callback__\(/','',$this->json);
|
68
|
+
//$this->json = preg_replace('/\);$/','',$this->json);
|
69
|
+
|
70
|
+
// Convert the JSON into a PHP object
|
71
|
+
$this->json = json_decode($this->json_raw);
|
72
|
+
|
73
|
+
|
74
|
+
// Pull the data out of the json variable
|
75
|
+
$grid = [];
|
76
|
+
$row = 0;
|
77
|
+
$col = 0;
|
78
|
+
|
79
|
+
for ($row=0; $row<count($this->json->values); ++$row) { // Loop thru each row
|
80
|
+
for ($col=0;$col<count($this->json->values[$row]); $col++) {
|
81
|
+
$grid[$row][$col] = $this->json->values[$row][$col];
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
//
|
86
|
+
// Determine the longest row
|
87
|
+
//
|
88
|
+
$maxcols = 0; // The max length of the rows
|
89
|
+
|
90
|
+
for ($i=0; $i<count($grid); ++$i) {
|
91
|
+
$maxcols = $grid[$i] ? max($maxcols, count($grid[$i]) ) : $maxcols;
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
//
|
96
|
+
// Go through the array and fill in any blank holes.
|
97
|
+
//
|
98
|
+
for ($i=0; $i<count($grid); ++$i) {
|
99
|
+
|
100
|
+
if (!$grid[$i]) {
|
101
|
+
$grid[$i] = array();
|
102
|
+
|
103
|
+
// TODO Might need to add a loop setting the $maxcols number of
|
104
|
+
// array elements to a blank string.
|
105
|
+
}
|
106
|
+
|
107
|
+
for ($j=0; $j<$maxcols; $j++) {
|
108
|
+
if (empty($grid[$i][$j])) {
|
109
|
+
$grid[$i][$j] = '';
|
110
|
+
}
|
111
|
+
|
112
|
+
ksort($grid[$i]);
|
113
|
+
|
114
|
+
// Convert numbers to real numbers and floats here too
|
115
|
+
if (is_numeric($grid[$i][$j])) {
|
116
|
+
$grid[$i][$j] = (float)$grid[$i][$j];
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
$this->numcols = $maxcols;
|
122
|
+
$this->numrows = count($grid);
|
123
|
+
$this->data = $grid;
|
124
|
+
ksort($this->data);
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
//
|
135
|
+
// Fetches a row of data and returns it
|
136
|
+
//
|
137
|
+
// @param $index number The numeric index of the row to fetch (starts at 1)
|
138
|
+
// @param $start number The number of columns that should be fetched
|
139
|
+
// @param $opt An option array containing options (optional)
|
140
|
+
//
|
141
|
+
public function row ($index, $start = 1)
|
142
|
+
{
|
143
|
+
$index = (int)$index;
|
144
|
+
$start = (int)$start;
|
145
|
+
|
146
|
+
if ($index === 0) {
|
147
|
+
$index = 1;
|
148
|
+
// 08/12/2020
|
149
|
+
// Removed due to PHP 8 upgrade
|
150
|
+
//
|
151
|
+
//trigger_error('The row number given was zero - however row numbers begin at 1');
|
152
|
+
}
|
153
|
+
|
154
|
+
if ($this->data[$index - 1]) {
|
155
|
+
$row = array_slice($this->data[$index - 1], $start - 1);
|
156
|
+
return $row;
|
157
|
+
} else {
|
158
|
+
return [];
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
//
|
169
|
+
// Fetches a column of data and returns it
|
170
|
+
//
|
171
|
+
// @param $index number The letter that pertains to the column to fetch
|
172
|
+
// @param $start number The number of rows that should be fetched
|
173
|
+
// @param $opt An option array containing options (optional)
|
174
|
+
//
|
175
|
+
public function col ($index, $start = 1)
|
176
|
+
{
|
177
|
+
|
178
|
+
for ($i=0,$col=[]; $i<count($this->data); ++$i) {
|
179
|
+
$col[] = $this->data[$i][$index - 1];
|
180
|
+
}
|
181
|
+
|
182
|
+
// Now account for the start index
|
183
|
+
$col = array_slice($col, $start - 1);
|
184
|
+
|
185
|
+
return $col;
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
//
|
196
|
+
// Returns the index (zero index) of the given letters
|
197
|
+
//
|
198
|
+
public function getIndexOfLetter ($letter)
|
199
|
+
{
|
200
|
+
$letter = strtoupper($letter);
|
201
|
+
|
202
|
+
if (strlen($letter) > 1) {
|
203
|
+
$parts = array_slice(preg_split('//', trim($letter)), 1, -1);
|
204
|
+
} else {
|
205
|
+
$parts = array($letter);
|
206
|
+
}
|
207
|
+
|
208
|
+
// Two letters are possible ie A -> ZZ
|
209
|
+
if (count($parts) === 1) {
|
210
|
+
return strpos($this->letters, $letter) + 1;
|
211
|
+
|
212
|
+
} else if (count($parts) === 2){
|
213
|
+
|
214
|
+
$idx = ((strpos($this->letters, $parts[0]) + 1) * 26)
|
215
|
+
+ (strpos($this->letters, $parts[1]) + 1);
|
216
|
+
|
217
|
+
return $idx;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
//
|
229
|
+
// The get() method makes retrieving cells very straightforward,
|
230
|
+
// for example: obj.get('B1');
|
231
|
+
//
|
232
|
+
// @param str string The cells(s) to fetch
|
233
|
+
// @param string Optional set of options that are passed
|
234
|
+
// to the relevant row/col function
|
235
|
+
//
|
236
|
+
function get ($str, $opt = [])
|
237
|
+
{
|
238
|
+
// Uppercase letters please!
|
239
|
+
$str = strtoupper(trim($str));
|
240
|
+
$ret = []; // This is the array that gets returned
|
241
|
+
|
242
|
+
//
|
243
|
+
// Handle the style of get('C') or get('AA'
|
244
|
+
//
|
245
|
+
if (preg_match('/^[A-Z]+$/', $str)) {
|
246
|
+
if (strlen($str) === 1) {
|
247
|
+
$index = strpos($this->letters, $str) + 1;
|
248
|
+
$ret = $this->col($index, 1, $opt);
|
249
|
+
|
250
|
+
} else if (strlen($str) === 2) {
|
251
|
+
|
252
|
+
$index = ((strpos($This->letters, $str[0]) + 1) * 26) + strpos($this->letters, $str[1]) + 1;
|
253
|
+
$ret = $this->col($index, 1, $opt);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
//
|
261
|
+
// Handle the style of get('2');
|
262
|
+
//(fetching a whole row
|
263
|
+
//
|
264
|
+
if (preg_match('/^[0-9]+$/i', $str)) {
|
265
|
+
$ret = $this->row($str, 1, $opt);
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
//
|
272
|
+
// Handle the style of get('E2');
|
273
|
+
//(fetching a single cell)
|
274
|
+
//
|
275
|
+
if (preg_match('/^([a-z]{1,2})([0-9]+)$/i', $str, $matches)) {
|
276
|
+
|
277
|
+
$letter = $matches[1];
|
278
|
+
$number = (int)$matches[2];
|
279
|
+
$col = $this->get($letter);
|
280
|
+
|
281
|
+
$ret = $col[$number - 1];
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
//
|
288
|
+
// Handle the style of .get('B2:E2');
|
289
|
+
//(fetching the B2 cell to the E2 cell)
|
290
|
+
//
|
291
|
+
if (preg_match('/^([a-z]{1,2})([0-9]+)\s*:\s*([a-z]{1,2})([0-9]+)$/i', $str, $matches)) {
|
292
|
+
|
293
|
+
$letter1 = $matches[1];
|
294
|
+
$number1 = $matches[2];
|
295
|
+
$letter2 = $matches[3];
|
296
|
+
$number2 = $matches[4];
|
297
|
+
|
298
|
+
// A column
|
299
|
+
if ($letter1 === $letter2) {
|
300
|
+
$cells = [];
|
301
|
+
$index = $this->getIndexOfLetter($letter1);
|
302
|
+
|
303
|
+
$col = $this->col($index, 1, $opt);
|
304
|
+
|
305
|
+
for ($i=($number1 - 1); $i<$number2; ++$i) {
|
306
|
+
$cells[] = !empty($col[$i]) ? $col[$i] : '';
|
307
|
+
}
|
308
|
+
|
309
|
+
// A row
|
310
|
+
} else if ($number1 === $number2) {
|
311
|
+
|
312
|
+
$cells = [];
|
313
|
+
$row = $this->row($number1, 1, $opt);
|
314
|
+
$index1 = $this->getIndexOfLetter($letter1);
|
315
|
+
$index2 = $this->getIndexOfLetter($letter2);
|
316
|
+
|
317
|
+
for ($i=($index1 - 1); $i<=($index2 - 1); ++$i) {
|
318
|
+
$cells[] = $row[$i];
|
319
|
+
}
|
320
|
+
|
321
|
+
// A matrix
|
322
|
+
} else if ($letter1 !== $letter2 AND $number1 !== $number2) {
|
323
|
+
|
324
|
+
$cells = [];
|
325
|
+
$row = [];
|
326
|
+
$index1 = $this->getIndexOfLetter($letter1);
|
327
|
+
$index2 = $this->getIndexOfLetter($letter2);
|
328
|
+
|
329
|
+
for ($i=$number1; $i<=$number2; ++$i) {
|
330
|
+
$row = $this->row($i);
|
331
|
+
$row = array_slice(
|
332
|
+
$row,
|
333
|
+
$index1 - 1,
|
334
|
+
$index2 - $index1 + 1
|
335
|
+
);
|
336
|
+
$cells[] = $row;
|
337
|
+
}
|
338
|
+
}
|
339
|
+
|
340
|
+
$ret = $cells;
|
341
|
+
}
|
342
|
+
|
343
|
+
// If the option has been specified then encode the array as a string
|
344
|
+
if (!empty($opt['string'])) {
|
345
|
+
$ret = json_encode($ret);
|
346
|
+
}
|
347
|
+
|
348
|
+
return $ret;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
?>
|