rgraph-rails 4.62 → 4.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +3 -4
- data/lib/rgraph-rails/version.rb +1 -1
- data/vendor/assets/javascripts/RGraph.bar.js +240 -3742
- data/vendor/assets/javascripts/RGraph.bipolar.js +165 -2005
- data/vendor/assets/javascripts/RGraph.common.annotate.js +35 -395
- data/vendor/assets/javascripts/RGraph.common.context.js +30 -595
- data/vendor/assets/javascripts/RGraph.common.core.js +418 -5359
- data/vendor/assets/javascripts/RGraph.common.csv.js +20 -276
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +35 -450
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +88 -1395
- data/vendor/assets/javascripts/RGraph.common.effects.js +90 -1545
- data/vendor/assets/javascripts/RGraph.common.key.js +52 -753
- data/vendor/assets/javascripts/RGraph.common.resizing.js +37 -563
- data/vendor/assets/javascripts/RGraph.common.sheets.js +29 -352
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +32 -450
- data/vendor/assets/javascripts/RGraph.common.zoom.js +14 -219
- data/vendor/assets/javascripts/RGraph.cornergauge.js +71 -0
- data/vendor/assets/javascripts/RGraph.drawing.background.js +34 -570
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +33 -544
- data/vendor/assets/javascripts/RGraph.drawing.image.js +51 -755
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +37 -645
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +36 -633
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +35 -514
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +37 -559
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +33 -548
- data/vendor/assets/javascripts/RGraph.drawing.text.js +36 -664
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +50 -812
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +51 -856
- data/vendor/assets/javascripts/RGraph.fuel.js +58 -964
- data/vendor/assets/javascripts/RGraph.funnel.js +55 -984
- data/vendor/assets/javascripts/RGraph.gantt.js +77 -1354
- data/vendor/assets/javascripts/RGraph.gauge.js +85 -1421
- data/vendor/assets/javascripts/RGraph.hbar.js +162 -2788
- data/vendor/assets/javascripts/RGraph.hprogress.js +80 -1401
- data/vendor/assets/javascripts/RGraph.line.js +249 -4248
- data/vendor/assets/javascripts/RGraph.meter.js +74 -1280
- data/vendor/assets/javascripts/RGraph.modaldialog.js +19 -301
- data/vendor/assets/javascripts/RGraph.odo.js +71 -1264
- data/vendor/assets/javascripts/RGraph.pie.js +137 -2288
- data/vendor/assets/javascripts/RGraph.radar.js +110 -1847
- data/vendor/assets/javascripts/RGraph.rose.js +108 -1977
- data/vendor/assets/javascripts/RGraph.rscatter.js +80 -1432
- data/vendor/assets/javascripts/RGraph.scatter.js +172 -3163
- data/vendor/assets/javascripts/RGraph.semicircularprogress.js +60 -1120
- data/vendor/assets/javascripts/RGraph.svg.bar.js +66 -1735
- data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +21 -246
- data/vendor/assets/javascripts/RGraph.svg.common.core.js +255 -3937
- data/vendor/assets/javascripts/RGraph.svg.common.csv.js +20 -276
- data/vendor/assets/javascripts/RGraph.svg.common.fx.js +68 -1303
- data/vendor/assets/javascripts/RGraph.svg.common.key.js +19 -205
- data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +29 -352
- data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +22 -273
- data/vendor/assets/javascripts/RGraph.svg.funnel.js +32 -0
- data/vendor/assets/javascripts/RGraph.svg.hbar.js +59 -1400
- data/vendor/assets/javascripts/RGraph.svg.line.js +70 -1580
- data/vendor/assets/javascripts/RGraph.svg.pie.js +55 -1131
- data/vendor/assets/javascripts/RGraph.svg.radar.js +57 -1502
- data/vendor/assets/javascripts/RGraph.svg.rose.js +66 -1817
- data/vendor/assets/javascripts/RGraph.svg.scatter.js +58 -1261
- data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +28 -865
- data/vendor/assets/javascripts/RGraph.svg.waterfall.js +45 -1252
- data/vendor/assets/javascripts/RGraph.thermometer.js +63 -1136
- data/vendor/assets/javascripts/RGraph.vprogress.js +83 -1470
- data/vendor/assets/javascripts/RGraph.waterfall.js +83 -1347
- metadata +5 -4
- data/vendor/assets/javascripts/financial-data.js +0 -1067
@@ -1,206 +1,20 @@
|
|
1
|
-
// version: 2017-05-08
|
2
|
-
/**
|
3
|
-
* o--------------------------------------------------------------------------------o
|
4
|
-
* | This file is part of the RGraph package - you can learn more at: |
|
5
|
-
* | |
|
6
|
-
* | http://www.rgraph.net |
|
7
|
-
* | |
|
8
|
-
* | RGraph is licensed under the Open Source MIT license. That means that it's |
|
9
|
-
* | totally free to use! |
|
10
|
-
* o--------------------------------------------------------------------------------o
|
11
|
-
*/
|
12
1
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
(
|
19
|
-
{
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
* @param colors An array of the colors to be used
|
33
|
-
*/
|
34
|
-
RG.SVG.drawKey = function (obj)
|
35
|
-
{
|
36
|
-
var prop = obj.properties,
|
37
|
-
key = prop.key,
|
38
|
-
colors = prop.keyColors || prop.colors,
|
39
|
-
defaultFont = 'Arial',
|
40
|
-
blobSize = 0,
|
41
|
-
width = 0;
|
42
|
-
|
43
|
-
// Work out the center point of the SVG tag
|
44
|
-
var centerx = obj.svg.getAttribute('width') / 2;
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
// First measure the length so that the key can be centered
|
50
|
-
for (var i=0,length = 0; i<key.length; i++) {
|
51
|
-
|
52
|
-
// First measure the text
|
53
|
-
var textDimensions = RG.SVG.measureText({
|
54
|
-
text: key[i],
|
55
|
-
bold: prop.keyTextBold || false,
|
56
|
-
font: prop.keyTextFont || prop.textFont || defaultFont,
|
57
|
-
size: prop.keyTextSize || prop.textSize
|
58
|
-
});
|
59
|
-
|
60
|
-
blobSize = ma.max(blobSize, textDimensions[1]);
|
61
|
-
|
62
|
-
width = width + 10 + blobSize + 5 + textDimensions[0];
|
63
|
-
}
|
64
|
-
|
65
|
-
// Center the key
|
66
|
-
x = centerx - width / 2;
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
// Loop thru the key and draw them
|
75
|
-
for (var i=0,y=prop.gutterTop - 5; i<key.length; ++i) {
|
76
|
-
|
77
|
-
// First measure the text
|
78
|
-
var textDimensions = RG.SVG.measureText({
|
79
|
-
text: key[i],
|
80
|
-
bold: prop.keyTextBold || false,
|
81
|
-
font: prop.keyTextFont || prop.textFont || defaultFont,
|
82
|
-
size: prop.keyTextSize || prop.textSize
|
83
|
-
});
|
84
|
-
|
85
|
-
|
86
|
-
RG.SVG.create({
|
87
|
-
svg: obj.svg,
|
88
|
-
type: 'rect',
|
89
|
-
parent: obj.svg.all,
|
90
|
-
attr: {
|
91
|
-
x: x + prop.keyOffsetx,
|
92
|
-
y: y - blobSize + prop.keyOffsety,
|
93
|
-
width: blobSize,
|
94
|
-
height: blobSize,
|
95
|
-
fill: colors[i]
|
96
|
-
}
|
97
|
-
});
|
98
|
-
|
99
|
-
RGraph.SVG.text({
|
100
|
-
object: obj,
|
101
|
-
parent: obj.svg.all,
|
102
|
-
size: prop.keyTextSize || prop.textSize,
|
103
|
-
bold: prop.keyTextBold || false,
|
104
|
-
font: 'Arial',
|
105
|
-
italic: prop.keyTextItalic|| false,
|
106
|
-
halign: 'left',
|
107
|
-
valign: 'bottom',
|
108
|
-
text: key[i],
|
109
|
-
x: x + blobSize + 5 + prop.keyTextOffsetx + prop.keyOffsetx,
|
110
|
-
y: y + prop.keyTextOffsety + prop.keyOffsety,
|
111
|
-
color: 'black',
|
112
|
-
background: 'white',
|
113
|
-
padding: 0
|
114
|
-
})
|
115
|
-
|
116
|
-
x += 10 + blobSize + 5 + textDimensions[0];
|
117
|
-
}
|
118
|
-
};
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
/**
|
128
|
-
* Create a TABLE based HTML key. There's lots of options so it's
|
129
|
-
* suggested that you consult the documentation page
|
130
|
-
*
|
131
|
-
* @param mixed id This should be a string consisting of the ID of the container
|
132
|
-
* @param object prop An object map of the various properties that you can use to
|
133
|
-
* configure the key. See the documentation page for a list.
|
134
|
-
*/
|
135
|
-
RG.SVG.HTML.key = function (id, prop)
|
136
|
-
{
|
137
|
-
var div = doc.getElementById(id);
|
138
|
-
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Create the table that becomes the key
|
142
|
-
*/
|
143
|
-
var str = '<table border="0" cellspacing="0" cellpadding="0" id="rgraph_key" style="display: inline;' + (function ()
|
144
|
-
{
|
145
|
-
var style = ''
|
146
|
-
for (i in prop.tableCss) {
|
147
|
-
if (typeof i === 'string') {
|
148
|
-
style = style + i + ': ' + prop.tableCss[i] + ';';
|
149
|
-
}
|
150
|
-
}
|
151
|
-
return style;
|
152
|
-
})() + '" ' + (prop.tableClass ? 'class="' + prop.tableClass + '"' : '') + '>';
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Add the individual key elements
|
158
|
-
*/
|
159
|
-
for (var i=0; i<prop.labels.length; i+=1) {
|
160
|
-
str += '<tr><td><div style="' + (function ()
|
161
|
-
{
|
162
|
-
var style = '';
|
163
|
-
|
164
|
-
for (var j in prop.blobCss) {
|
165
|
-
if (typeof j === 'string') {
|
166
|
-
style = style + j + ': ' + prop.blobCss[j] + ';';
|
167
|
-
}
|
168
|
-
}
|
169
|
-
|
170
|
-
return style;
|
171
|
-
})() + 'display: inline-block; margin-right: 5px; margin-top: 4px; width: 15px; height: 15px; background-color: ' + prop.colors[i] + '"' + (prop.blobClass ? 'class="' + prop.blobClass + '"' : '') + '> </div><td>' + (prop.links && prop.links[i] ? '<a href="' + prop.links[i] + '">' : '') + '<span ' + (prop.labelClass ? 'class="' + prop.labelClass + '"' : '') + '" style="' + (function ()
|
172
|
-
{
|
173
|
-
var style = '';
|
174
|
-
|
175
|
-
for (var j in prop.labelCss) {
|
176
|
-
if (typeof j === 'string') {
|
177
|
-
style = style + j + ': ' + prop.labelCss[j] + ';';
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
return style;
|
182
|
-
})() + '" ' + (function ()
|
183
|
-
{
|
184
|
-
var style = '';
|
185
|
-
|
186
|
-
if (prop['labelCss_' + i]) {
|
187
|
-
for (var j in prop['labelCss_' + i]) {
|
188
|
-
style = style + j + ': ' + prop['labelCss_' + i][j] + ';';
|
189
|
-
}
|
190
|
-
}
|
191
|
-
|
192
|
-
return style ? 'style="' + style + '"' : '';
|
193
|
-
})() + '>' + prop.labels[i] + '</span>' + (prop.links && prop.links[i] ? '</a>' : '') + '</td></tr>';
|
194
|
-
}
|
195
|
-
|
196
|
-
div.innerHTML += (str + '</table>');
|
197
|
-
|
198
|
-
// Return the TABLE object that is the HTML key
|
199
|
-
return doc.getElementById('rgraph_key');
|
200
|
-
};
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
// End module pattern
|
206
|
-
})(window, document);
|
2
|
+
RGraph=window.RGraph||{isRGraph:true};RGraph.SVG=RGraph.SVG||{};RGraph.SVG.HTML=RGraph.SVG.HTML||{};(function(win,doc,undefined)
|
3
|
+
{var RG=RGraph,ua=navigator.userAgent,ma=Math;RG.SVG.drawKey=function(obj)
|
4
|
+
{var prop=obj.properties,key=prop.key,colors=prop.keyColors||prop.colors,defaultFont='Arial',blobSize=0,width=0,keyColorShape=prop.keyColorShape;var centerx=obj.svg.getAttribute('width')/2;if(obj.type==='funnel'){centerx=(obj.graphWidth/2)+prop.gutterLeft;}
|
5
|
+
if(key&&key.length){for(var i=0,length=0;i<key.length;i++){var textDimensions=RG.SVG.measureText({text:key[i],bold:prop.keyTextBold||false,font:prop.keyTextFont||prop.textFont||defaultFont,size:prop.keyTextSize||prop.textSize});blobSize=ma.max(blobSize,textDimensions[1]);width=width+10+blobSize+5+textDimensions[0];}
|
6
|
+
x=centerx-width/2;for(var i=0,y=prop.gutterTop-5;i<key.length;++i){var textDimensions=RG.SVG.measureText({text:key[i],bold:prop.keyTextBold||false,font:prop.keyTextFont||prop.textFont||defaultFont,size:prop.keyTextSize||prop.textSize});var shape=prop.keyColorShape;if(typeof shape==='object'){shape=prop.keyColorShape[i];}
|
7
|
+
if(shape==='circle'){RG.SVG.create({svg:obj.svg,type:'circle',parent:obj.svg.all,attr:{cx:x+(blobSize/2)+prop.keyOffsety,cy:y-(blobSize/2)+prop.keyOffsety,r:blobSize/2,fill:colors[i]}});}else if(shape==='triangle'){RG.SVG.create({svg:obj.svg,type:'path',parent:obj.svg.all,attr:{d:'M {1} {2} L {3} {4} L {5} {6} z'.format(x+prop.keyOffsetx+(blobSize/2),y-blobSize+prop.keyOffsety,x+prop.keyOffsetx+blobSize,y+prop.keyOffsety,x+prop.keyOffsetx,y+prop.keyOffsety),fill:colors[i]}});}else if(shape==='line'){RG.SVG.create({svg:obj.svg,type:'path',parent:obj.svg.all,attr:{d:'M {1} {2} L {3} {4}'.format(x+prop.keyOffsetx,y-(blobSize/2)+prop.keyOffsety,x+prop.keyOffsetx+blobSize,y-(blobSize/2)+prop.keyOffsety),stroke:colors[i],'stroke-width':2,'stroke-linecap':'round'}});}else if(shape==='dot'){RG.SVG.create({svg:obj.svg,type:'path',parent:obj.svg.all,attr:{d:'M {1} {2} L {3} {4}'.format(x+prop.keyOffsetx,y-(blobSize/2)+prop.keyOffsety,x+prop.keyOffsetx+blobSize,y-(blobSize/2)+prop.keyOffsety),stroke:colors[i],'stroke-width':2,'stroke-linecap':'round'}});RG.SVG.create({svg:obj.svg,type:'circle',parent:obj.svg.all,attr:{cx:x+(blobSize/2)+prop.keyOffsety,cy:y-(blobSize/2)+prop.keyOffsety,r:blobSize/4,fill:colors[i]}});}else if(typeof shape==='function'){RG.SVG.create({svg:obj.svg,type:'path',parent:obj.svg.all,attr:{d:'M {1} {2} L {3} {4}'.format(x+prop.keyOffsetx,y-(blobSize/2)+prop.keyOffsety,x+prop.keyOffsetx+blobSize,y-(blobSize/2)+prop.keyOffsety),stroke:colors[i],'stroke-width':2,'stroke-linecap':'round'}});}else{RG.SVG.create({svg:obj.svg,type:'rect',parent:obj.svg.all,attr:{x:x+prop.keyOffsetx,y:y-blobSize+prop.keyOffsety,width:blobSize,height:blobSize,fill:colors[i]}});}
|
8
|
+
RGraph.SVG.text({object:obj,parent:obj.svg.all,size:prop.keyTextSize||prop.textSize,bold:prop.keyTextBold||false,font:'Arial',italic:prop.keyTextItalic||false,halign:'left',valign:'bottom',text:key[i],x:x+blobSize+5+prop.keyTextOffsetx+prop.keyOffsetx,y:y+prop.keyTextOffsety+prop.keyOffsety,color:'black',background:'white',padding:0})
|
9
|
+
x+=10+blobSize+5+textDimensions[0];}}};RG.SVG.HTML.key=function(id,prop)
|
10
|
+
{var div=doc.getElementById(id);var str='<table border="0" cellspacing="0" cellpadding="0" id="rgraph_key" style="display: inline;'+(function()
|
11
|
+
{var style=''
|
12
|
+
for(i in prop.tableCss){if(typeof i==='string'){style=style+i+': '+prop.tableCss[i]+';';}}
|
13
|
+
return style;})()+'" '+(prop.tableClass?'class="'+prop.tableClass+'"':'')+'>';for(var i=0;i<prop.labels.length;i+=1){str+='<tr><td><div style="'+(function()
|
14
|
+
{var style='';for(var j in prop.blobCss){if(typeof j==='string'){style=style+j+': '+prop.blobCss[j]+';';}}
|
15
|
+
return style;})()+'display: inline-block; margin-right: 5px; margin-top: 4px; width: 15px; height: 15px; background-color: '+prop.colors[i]+'"'+(prop.blobClass?'class="'+prop.blobClass+'"':'')+'> </div><td>'+(prop.links&&prop.links[i]?'<a href="'+prop.links[i]+'">':'')+'<span '+(prop.labelClass?'class="'+prop.labelClass+'"':'')+'" style="'+(function()
|
16
|
+
{var style='';for(var j in prop.labelCss){if(typeof j==='string'){style=style+j+': '+prop.labelCss[j]+';';}}
|
17
|
+
return style;})()+'" '+(function()
|
18
|
+
{var style='';if(prop['labelCss_'+i]){for(var j in prop['labelCss_'+i]){style=style+j+': '+prop['labelCss_'+i][j]+';';}}
|
19
|
+
return style?'style="'+style+'"':'';})()+'>'+prop.labels[i]+'</span>'+(prop.links&&prop.links[i]?'</a>':'')+'</td></tr>';}
|
20
|
+
div.innerHTML+=(str+'</table>');return doc.getElementById('rgraph_key');};})(window,document);
|
@@ -1,353 +1,30 @@
|
|
1
|
-
// version: 2017-05-08
|
2
|
-
/**
|
3
|
-
* o--------------------------------------------------------------------------------o
|
4
|
-
* | This file is part of the RGraph package - you can learn more at: |
|
5
|
-
* | |
|
6
|
-
* | http://www.rgraph.net |
|
7
|
-
* | |
|
8
|
-
* | RGraph is licensed under the Open Source MIT license. That means that it's |
|
9
|
-
* | totally free to use! |
|
10
|
-
* o--------------------------------------------------------------------------------o
|
11
|
-
*/
|
12
1
|
|
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
|
-
// Loads the spreadsheet
|
50
|
-
//
|
51
|
-
this.load = function(url, userCallback)
|
52
|
-
{
|
53
|
-
var obj = this;
|
54
|
-
|
55
|
-
// A global on purpose
|
56
|
-
__rgraph_JSONPCallback = function (json)
|
57
|
-
{
|
58
|
-
// Save the JSON on the RGraph.Sheets object
|
59
|
-
obj.json = json;
|
60
|
-
|
61
|
-
//
|
62
|
-
// Put the entries in the JSON feed into a grid
|
63
|
-
//
|
64
|
-
var grid = [], row = 0, col = 0;
|
65
|
-
|
66
|
-
for (var i=0; i<json.feed.entry.length; ++i) {
|
67
|
-
|
68
|
-
row = json.feed.entry[i].gs$cell.row - 1;
|
69
|
-
col = json.feed.entry[i].gs$cell.col - 1;
|
70
|
-
|
71
|
-
if (!grid[row]) {
|
72
|
-
grid[row] = [];
|
73
|
-
}
|
74
|
-
|
75
|
-
grid[row][col] = json.feed.entry[i].content.$t;
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
|
-
//
|
80
|
-
// Determine the longest row
|
81
|
-
//
|
82
|
-
var maxcols = 0; // The max length of the rows
|
83
|
-
|
84
|
-
for (var i=0; i<grid.length; ++i) {
|
85
|
-
maxcols = grid[i] ? Math.max(maxcols, grid[i].length) : maxcols;
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
//
|
91
|
-
// Now go through the array and fill in any blank holes.
|
92
|
-
//
|
93
|
-
for (var i=0; i<grid.length; ++i) {
|
94
|
-
|
95
|
-
if (typeof grid[i] === 'undefined') {
|
96
|
-
grid[i] = new Array(maxcols);
|
97
|
-
}
|
98
|
-
|
99
|
-
for (var j=0; j<maxcols; j++) {
|
100
|
-
if (typeof grid[i][j] === 'undefined') {
|
101
|
-
grid[i][j] = '';
|
102
|
-
}
|
103
|
-
|
104
|
-
// Convert numbers to real numbers and floats here too
|
105
|
-
if (grid[i][j].match(/^[0-9]+$/)) {
|
106
|
-
grid[i][j] = parseInt(grid[i][j]);
|
107
|
-
} else if (grid[i][j].match(/^[0-9.]+$/)) {
|
108
|
-
grid[i][j] = parseFloat(grid[i][j]);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
}
|
112
|
-
|
113
|
-
//
|
114
|
-
// Save the grid on the object
|
115
|
-
//
|
116
|
-
obj.data = grid;
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
//
|
121
|
-
// Call the users callback function. Users can access the raw data if
|
122
|
-
// they want with the obj.data property or by using the accessor
|
123
|
-
// methods (better)
|
124
|
-
//
|
125
|
-
userCallback(obj);
|
126
|
-
};
|
127
|
-
|
128
|
-
// Add the new script tag to the document that pulls in the JSON
|
129
|
-
//
|
130
|
-
// With jQuery...
|
131
|
-
//
|
132
|
-
//jQuery('body').append("<script src='" + url + "'></script>");
|
133
|
-
//
|
134
|
-
// And without jQuery...
|
135
|
-
|
136
|
-
var scriptNode = document.createElement('SCRIPT');
|
137
|
-
scriptNode.src = url;
|
138
|
-
document.body.appendChild(scriptNode);
|
139
|
-
};
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
//
|
145
|
-
// Fetches a row of data and returns it
|
146
|
-
//
|
147
|
-
// @param id number The numeric index of the column to fetch (starts at 1)
|
148
|
-
// @param start number The index to start fetching/returning at. The first
|
149
|
-
// character is 1
|
150
|
-
// @param opt An option object containing options
|
151
|
-
//
|
152
|
-
this.row = function (index, start)
|
153
|
-
{
|
154
|
-
var opt = {}, row;
|
155
|
-
|
156
|
-
// Default for start is 1
|
157
|
-
start = start || 1;
|
158
|
-
|
159
|
-
//
|
160
|
-
// Parse the .trim argument
|
161
|
-
//
|
162
|
-
|
163
|
-
if (arguments && typeof arguments[2] === 'object' && typeof arguments[2].trim === 'boolean') {
|
164
|
-
opt.trim = arguments[2].trim;
|
165
|
-
} else {
|
166
|
-
opt.trim = true;
|
167
|
-
}
|
168
|
-
|
169
|
-
row = this.data[index - 1].slice(start - 1);
|
170
|
-
|
171
|
-
// Trim the array if required
|
172
|
-
if (opt.trim) {
|
173
|
-
row = RGraph.SVG.arrayTrim(row);
|
174
|
-
}
|
175
|
-
|
176
|
-
return row;
|
177
|
-
};
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
//
|
182
|
-
// Fetches a column of data and returns it
|
183
|
-
//
|
184
|
-
// @param id number The letter that corresponds to the column
|
185
|
-
// @param start number The index to start fetching/returning at. The first
|
186
|
-
// character is 1
|
187
|
-
// @param opt An option object containing options
|
188
|
-
//
|
189
|
-
this.col = function (index, start)
|
190
|
-
{
|
191
|
-
var opt = {},
|
192
|
-
col = [];
|
193
|
-
|
194
|
-
// Default for start is 1
|
195
|
-
start = start || 1;
|
196
|
-
|
197
|
-
if (arguments && typeof arguments[2] === 'object' && typeof arguments[2].trim === 'boolean') {
|
198
|
-
opt.trim = arguments[2].trim;
|
199
|
-
} else {
|
200
|
-
opt.trim = true;
|
201
|
-
}
|
202
|
-
|
203
|
-
for (var i=0; i<this.data.length; ++i) {
|
204
|
-
col.push(this.data[i][index - 1]);
|
205
|
-
}
|
206
|
-
|
207
|
-
// Trim the array if required
|
208
|
-
if (opt.trim) {
|
209
|
-
col = RGraph.SVG.arrayTrim(col);
|
210
|
-
}
|
211
|
-
|
212
|
-
// Now account for the start index
|
213
|
-
|
214
|
-
col = col.slice(start - 1);
|
215
|
-
|
216
|
-
return col;
|
217
|
-
};
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
//
|
222
|
-
// Returns the index (zero index) of the given letters
|
223
|
-
//
|
224
|
-
this.getIndexOfLetters = function (l)
|
225
|
-
{
|
226
|
-
var parts = l.split('');
|
227
|
-
|
228
|
-
if (parts.length === 1) {
|
229
|
-
return letters.indexOf(l) + 1;
|
230
|
-
} else if (parts.length === 2){
|
231
|
-
var idx = ((letters.indexOf(parts[0]) + 1) * 26) + (letters.indexOf(parts[1]) + 1);
|
232
|
-
return idx;
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
//
|
241
|
-
// The get method makes retrieving cells very straightforward,
|
242
|
-
// for example: obj.get('B1');
|
243
|
-
//
|
244
|
-
// @param str string The cells(s) to fetch
|
245
|
-
// @param string Optional set of options that are passed
|
246
|
-
// to the relevant row/col function
|
247
|
-
//
|
248
|
-
this.get = function (str)
|
249
|
-
{
|
250
|
-
// Uppercase letters please!
|
251
|
-
str = str.toUpperCase();
|
252
|
-
|
253
|
-
//
|
254
|
-
// Handle the style of .get('C') or .get('AA'
|
255
|
-
//
|
256
|
-
if (str.match(/^[a-z]+$/i)) {
|
257
|
-
if (str.length === 1) {
|
258
|
-
var index = letters.indexOf(str) + 1;
|
259
|
-
return this.col(index, 1, arguments[1]);
|
260
|
-
|
261
|
-
} else if (str.length === 2) {
|
262
|
-
var index = ((letters.indexOf(str[0]) + 1) * 26) + letters.indexOf(str[1]) + 1;
|
263
|
-
return this.col(index, 1, arguments[1]);
|
264
|
-
}
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
//
|
271
|
-
// Handle the style of .get('2');
|
272
|
-
//(fetching a whole row
|
273
|
-
//
|
274
|
-
if (str.match(/^[0-9]+$/i)) {
|
275
|
-
return this.row(str, null, arguments[1]);
|
276
|
-
}
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
//
|
282
|
-
// Handle the style of .get('E2');
|
283
|
-
//(fetching a single cell)
|
284
|
-
//
|
285
|
-
if (str.match(/^([a-z]{1,2})([0-9]+)$/i)) {
|
286
|
-
|
287
|
-
var letter = RegExp.$1,
|
288
|
-
number = RegExp.$2,
|
289
|
-
col = this.get(letter, {trim: false});
|
290
|
-
|
291
|
-
|
292
|
-
return col[number - 1];
|
293
|
-
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
//
|
299
|
-
// Handle the style of .get('B2:E2');
|
300
|
-
//(fetching the E2 cell to the E2 cell)
|
301
|
-
//
|
302
|
-
if (str.match(/^([a-z]{1,2})([0-9]+):([a-z]{1,2})([0-9]+)$/i)) {
|
303
|
-
|
304
|
-
var letter1 = RegExp.$1,
|
305
|
-
number1 = RegExp.$2,
|
306
|
-
letter2 = RegExp.$3,
|
307
|
-
number2 = RegExp.$4
|
308
|
-
|
309
|
-
|
310
|
-
if (letter1 === letter2) {
|
311
|
-
var cells = [],
|
312
|
-
index = this.getIndexOfLetters(letter1),
|
313
|
-
col = this.col(index, null, {trim: false});
|
314
|
-
|
315
|
-
for (var i=(number1 - 1); i<=(number2 - 1); ++i) {
|
316
|
-
cells.push(col[i]);
|
317
|
-
}
|
318
|
-
|
319
|
-
} else if (number1 === number2) {
|
320
|
-
|
321
|
-
var cells = [],
|
322
|
-
row = this.row(number1, null, {trim: false}),
|
323
|
-
index1 = this.getIndexOfLetters(letter1),
|
324
|
-
index2 = this.getIndexOfLetters(letter2)
|
325
|
-
|
326
|
-
for (var i=(index1 - 1); i<=(index2 - 1); ++i) {
|
327
|
-
cells.push(row[i]);
|
328
|
-
}
|
329
|
-
}
|
330
|
-
|
331
|
-
// Trim the results
|
332
|
-
if (arguments[1] && arguments[1].trim === false) {
|
333
|
-
// Nada
|
334
|
-
} else {
|
335
|
-
cells = RGraph.SVG.arrayTrim(cells);
|
336
|
-
}
|
337
|
-
|
338
|
-
return cells;
|
339
|
-
|
340
|
-
}
|
341
|
-
};
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
//
|
347
|
-
// Load the data
|
348
|
-
//
|
349
|
-
this.load(url, callback);
|
350
|
-
};
|
351
|
-
|
352
|
-
// End module pattern
|
353
|
-
})(window, document);
|
2
|
+
RGraph=window.RGraph||{isRGraph:true};(function(win,doc,undefined)
|
3
|
+
{RGraph.Sheets=function(key)
|
4
|
+
{var worksheet,callback,letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ';if(arguments.length===3){worksheet=Number(arguments[1]);callback=arguments[2];}else{worksheet=1;callback=arguments[1];}
|
5
|
+
var url='https://spreadsheets.google.com/feeds/cells/[KEY]/[WORKSHEET]/public/full?alt=json-in-script&callback=__rgraph_JSONPCallback'.replace(/\[KEY\]/,key).replace(/\[WORKSHEET\]/,worksheet);this.load=function(url,userCallback)
|
6
|
+
{var obj=this;__rgraph_JSONPCallback=function(json)
|
7
|
+
{obj.json=json;var grid=[],row=0,col=0;for(var i=0;i<json.feed.entry.length;++i){row=json.feed.entry[i].gs$cell.row-1;col=json.feed.entry[i].gs$cell.col-1;if(!grid[row]){grid[row]=[];}
|
8
|
+
grid[row][col]=json.feed.entry[i].content.$t;}
|
9
|
+
var maxcols=0;for(var i=0;i<grid.length;++i){maxcols=grid[i]?Math.max(maxcols,grid[i].length):maxcols;}
|
10
|
+
for(var i=0;i<grid.length;++i){if(typeof grid[i]==='undefined'){grid[i]=new Array(maxcols);}
|
11
|
+
for(var j=0;j<maxcols;j++){if(typeof grid[i][j]==='undefined'){grid[i][j]='';}
|
12
|
+
if(grid[i][j].match(/^[0-9]+$/)){grid[i][j]=parseInt(grid[i][j]);}else if(grid[i][j].match(/^[0-9.]+$/)){grid[i][j]=parseFloat(grid[i][j]);}}}
|
13
|
+
obj.data=grid;userCallback(obj);};var scriptNode=document.createElement('SCRIPT');scriptNode.src=url;document.body.appendChild(scriptNode);};this.row=function(index,start)
|
14
|
+
{var opt={},row;start=start||1;if(arguments&&typeof arguments[2]==='object'&&typeof arguments[2].trim==='boolean'){opt.trim=arguments[2].trim;}else{opt.trim=true;}
|
15
|
+
row=this.data[index-1].slice(start-1);if(opt.trim){row=RGraph.SVG.arrayTrim(row);}
|
16
|
+
return row;};this.col=function(index,start)
|
17
|
+
{var opt={},col=[];start=start||1;if(arguments&&typeof arguments[2]==='object'&&typeof arguments[2].trim==='boolean'){opt.trim=arguments[2].trim;}else{opt.trim=true;}
|
18
|
+
for(var i=0;i<this.data.length;++i){col.push(this.data[i][index-1]);}
|
19
|
+
if(opt.trim){col=RGraph.SVG.arrayTrim(col);}
|
20
|
+
col=col.slice(start-1);return col;};this.getIndexOfLetters=function(l)
|
21
|
+
{var parts=l.split('');if(parts.length===1){return letters.indexOf(l)+1;}else if(parts.length===2){var idx=((letters.indexOf(parts[0])+1)*26)+(letters.indexOf(parts[1])+1);return idx;}}
|
22
|
+
this.get=function(str)
|
23
|
+
{str=str.toUpperCase();if(str.match(/^[a-z]+$/i)){if(str.length===1){var index=letters.indexOf(str)+1;return this.col(index,1,arguments[1]);}else if(str.length===2){var index=((letters.indexOf(str[0])+1)*26)+letters.indexOf(str[1])+1;return this.col(index,1,arguments[1]);}}
|
24
|
+
if(str.match(/^[0-9]+$/i)){return this.row(str,null,arguments[1]);}
|
25
|
+
if(str.match(/^([a-z]{1,2})([0-9]+)$/i)){var letter=RegExp.$1,number=RegExp.$2,col=this.get(letter,{trim:false});return col[number-1];}
|
26
|
+
if(str.match(/^([a-z]{1,2})([0-9]+):([a-z]{1,2})([0-9]+)$/i)){var letter1=RegExp.$1,number1=RegExp.$2,letter2=RegExp.$3,number2=RegExp.$4
|
27
|
+
if(letter1===letter2){var cells=[],index=this.getIndexOfLetters(letter1),col=this.col(index,null,{trim:false});for(var i=(number1-1);i<=(number2-1);++i){cells.push(col[i]);}}else if(number1===number2){var cells=[],row=this.row(number1,null,{trim:false}),index1=this.getIndexOfLetters(letter1),index2=this.getIndexOfLetters(letter2)
|
28
|
+
for(var i=(index1-1);i<=(index2-1);++i){cells.push(row[i]);}}
|
29
|
+
if(arguments[1]&&arguments[1].trim===false){}else{cells=RGraph.SVG.arrayTrim(cells);}
|
30
|
+
return cells;}};this.load(url,callback);};})(window,document);
|