rgraph-rails 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/rgraph-rails/version.rb +1 -1
- data/license.txt +4 -16
- data/vendor/assets/javascripts/RGraph.bar.js +3734 -241
- data/vendor/assets/javascripts/RGraph.bipolar.js +2005 -115
- data/vendor/assets/javascripts/RGraph.common.annotate.js +395 -35
- data/vendor/assets/javascripts/RGraph.common.context.js +595 -30
- data/vendor/assets/javascripts/RGraph.common.core.js +5282 -405
- data/vendor/assets/javascripts/RGraph.common.csv.js +276 -19
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +450 -35
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +1395 -86
- data/vendor/assets/javascripts/RGraph.common.effects.js +1545 -90
- data/vendor/assets/javascripts/RGraph.common.key.js +753 -54
- data/vendor/assets/javascripts/RGraph.common.resizing.js +563 -37
- data/vendor/assets/javascripts/RGraph.common.sheets.js +352 -29
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +450 -32
- data/vendor/assets/javascripts/RGraph.common.zoom.js +219 -14
- data/vendor/assets/javascripts/RGraph.drawing.background.js +570 -35
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +544 -35
- data/vendor/assets/javascripts/RGraph.drawing.image.js +755 -52
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +645 -41
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +633 -37
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +514 -36
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +559 -39
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +548 -35
- data/vendor/assets/javascripts/RGraph.drawing.text.js +664 -36
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +812 -50
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +856 -51
- data/vendor/assets/javascripts/RGraph.fuel.js +964 -58
- data/vendor/assets/javascripts/RGraph.funnel.js +984 -55
- data/vendor/assets/javascripts/RGraph.gantt.js +1354 -77
- data/vendor/assets/javascripts/RGraph.gauge.js +1421 -87
- data/vendor/assets/javascripts/RGraph.hbar.js +2562 -146
- data/vendor/assets/javascripts/RGraph.hprogress.js +1401 -80
- data/vendor/assets/javascripts/RGraph.line.js +4226 -244
- data/vendor/assets/javascripts/RGraph.meter.js +1280 -74
- data/vendor/assets/javascripts/RGraph.modaldialog.js +301 -19
- data/vendor/assets/javascripts/RGraph.odo.js +1264 -71
- data/vendor/assets/javascripts/RGraph.pie.js +2288 -137
- data/vendor/assets/javascripts/RGraph.radar.js +1847 -110
- data/vendor/assets/javascripts/RGraph.rose.js +1977 -108
- data/vendor/assets/javascripts/RGraph.rscatter.js +1432 -80
- data/vendor/assets/javascripts/RGraph.scatter.js +3036 -168
- data/vendor/assets/javascripts/RGraph.semicircularprogress.js +1120 -60
- data/vendor/assets/javascripts/RGraph.svg.bar.js +1067 -0
- data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +247 -0
- data/vendor/assets/javascripts/RGraph.svg.common.core.js +3363 -0
- data/vendor/assets/javascripts/RGraph.svg.common.csv.js +277 -0
- data/vendor/assets/javascripts/RGraph.svg.common.fx.js +1304 -0
- data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +353 -0
- data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +233 -0
- data/vendor/assets/javascripts/RGraph.svg.hbar.js +1141 -0
- data/vendor/assets/javascripts/RGraph.svg.line.js +1486 -0
- data/vendor/assets/javascripts/RGraph.svg.pie.js +781 -0
- data/vendor/assets/javascripts/RGraph.svg.radar.js +1326 -0
- data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +817 -0
- data/vendor/assets/javascripts/RGraph.thermometer.js +1135 -62
- data/vendor/assets/javascripts/RGraph.vprogress.js +1470 -83
- data/vendor/assets/javascripts/RGraph.waterfall.js +1347 -80
- metadata +15 -3
@@ -1,30 +1,353 @@
|
|
1
|
+
// version: 2017-01-02
|
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
|
+
*/
|
1
12
|
|
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
|
-
|
13
|
+
/**
|
14
|
+
* Initialise the various objects
|
15
|
+
*/
|
16
|
+
RGraph = window.RGraph || {isRGraph: true};
|
17
|
+
|
18
|
+
// Module pattern
|
19
|
+
(function (win, doc, undefined)
|
20
|
+
{
|
21
|
+
RGraph.Sheets = function (key)
|
22
|
+
{
|
23
|
+
var worksheet,
|
24
|
+
callback,
|
25
|
+
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
26
|
+
|
27
|
+
// 3 arguments
|
28
|
+
if (arguments.length === 3) {
|
29
|
+
worksheet = Number(arguments[1]);
|
30
|
+
callback = arguments[2];
|
31
|
+
|
32
|
+
// 2 arguments
|
33
|
+
} else {
|
34
|
+
worksheet = 1;
|
35
|
+
callback = arguments[1];
|
36
|
+
}
|
37
|
+
|
38
|
+
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);
|
39
|
+
|
40
|
+
/*
|
41
|
+
* https://spreadsheets.google.com/feeds/cells/1q_BMjvKO_kKbAO3VjoaITSDyrLAk8f0SK5UFMmE3oRs/2/public/full?alt=json-in-script
|
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
|
+
//$('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.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.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.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);
|
@@ -1,33 +1,451 @@
|
|
1
|
+
// version: 2017-01-02
|
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
|
+
*/
|
1
12
|
|
2
|
-
RGraph=window.RGraph||{isRGraph:true};
|
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
|
-
|
13
|
+
RGraph = window.RGraph || {isRGraph: true};
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
// Module pattern
|
19
|
+
(function (win, doc, undefined)
|
20
|
+
{
|
21
|
+
var RG = RGraph,
|
22
|
+
ua = navigator.userAgent,
|
23
|
+
ma = Math;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
/**
|
29
|
+
* This is used in two functions, hence it's here
|
30
|
+
*/
|
31
|
+
RG.tooltips = {};
|
32
|
+
RG.tooltips.style = {
|
33
|
+
display: 'inline-block',
|
34
|
+
position: 'absolute',
|
35
|
+
padding: '6px',
|
36
|
+
fontFamily: 'Arial',
|
37
|
+
fontSize: '10pt',
|
38
|
+
fontWeight: 'normal',
|
39
|
+
textAlign: 'center',
|
40
|
+
left: 0,
|
41
|
+
top: 0,
|
42
|
+
backgroundColor: 'rgb(255,255,239)',
|
43
|
+
color: 'black',
|
44
|
+
visibility: 'visible',
|
45
|
+
zIndex: 3,
|
46
|
+
borderRadius: '5px',
|
47
|
+
boxShadow: 'rgba(96,96,96,0.5) 0 0 5px',
|
48
|
+
opacity: 0
|
49
|
+
};
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Shows a tooltip next to the mouse pointer
|
55
|
+
*
|
56
|
+
* @param canvas object The canvas element object
|
57
|
+
* @param text string The tooltip text
|
58
|
+
* @param int x The X position that the tooltip should appear at. Combined with the canvases offsetLeft
|
59
|
+
* gives the absolute X position
|
60
|
+
* @param int y The Y position the tooltip should appear at. Combined with the canvases offsetTop
|
61
|
+
* gives the absolute Y position
|
62
|
+
* @param int idx The index of the tooltip in the graph objects tooltip array
|
63
|
+
* @param object e The event object
|
64
|
+
*/
|
65
|
+
RG.tooltip =
|
66
|
+
RG.Tooltip = function (obj, text, x, y, idx, e)
|
67
|
+
{
|
68
|
+
if (RG.trim(text).length === 0) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Fire the beforetooltip event
|
76
|
+
*/
|
77
|
+
RG.fireCustomEvent(obj, 'onbeforetooltip');
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
/**
|
82
|
+
* chart.tooltip.override allows you to totally take control of rendering the tooltip yourself
|
83
|
+
*/
|
84
|
+
if (typeof(obj.get('chart.tooltips.override')) == 'function') {
|
85
|
+
return obj.get('chart.tooltips.override')(obj, text, x, y, idx);
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Save the X/Y coords
|
93
|
+
*/
|
94
|
+
var originalX = x;
|
95
|
+
var originalY = y;
|
96
|
+
|
97
|
+
/**
|
98
|
+
* This facilitates the "id:xxx" format
|
99
|
+
*/
|
100
|
+
text = RG.getTooltipTextFromDIV(text);
|
101
|
+
|
102
|
+
/**
|
103
|
+
* First clear any exising timers
|
104
|
+
*/
|
105
|
+
var timers = RG.Registry.Get('chart.tooltip.timers');
|
106
|
+
|
107
|
+
if (timers && timers.length) {
|
108
|
+
for (i=0; i<timers.length; ++i) {
|
109
|
+
clearTimeout(timers[i]);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
RG.Registry.Set('chart.tooltip.timers', []);
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Hide the context menu if it's currently shown
|
116
|
+
*/
|
117
|
+
if (obj.get('chart.contextmenu')) {
|
118
|
+
RG.hideContext();
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Show a tool tip
|
125
|
+
*/
|
126
|
+
var tooltipObj = document.createElement('DIV');
|
127
|
+
tooltipObj.className = obj.get('chart.tooltips.css.class');
|
128
|
+
|
129
|
+
// Add the default CSS to the tooltip
|
130
|
+
for (var i in RGraph.tooltips.style) {
|
131
|
+
if (typeof i === 'string') {
|
132
|
+
tooltipObj.style[i] = RGraph.tooltips.style[i];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
tooltipObj.innerHTML = text;
|
137
|
+
tooltipObj.__text__ = text; // This is set because the innerHTML can change when it's set
|
138
|
+
tooltipObj.__canvas__ = obj.canvas;
|
139
|
+
tooltipObj.id = '__rgraph_tooltip_' + obj.canvas.id + '_' + obj.uid + '_'+ idx;
|
140
|
+
tooltipObj.__event__ = obj.Get('chart.tooltips.event') || 'click';
|
141
|
+
tooltipObj.__object__ = obj;
|
142
|
+
|
143
|
+
if (typeof idx === 'number') {
|
144
|
+
tooltipObj.__index__ = idx;
|
145
|
+
origIdx = idx;
|
146
|
+
}
|
147
|
+
|
148
|
+
if (obj.type === 'line' || obj.type === 'radar') {
|
149
|
+
for (var ds=0; ds<obj.data.length; ++ds) {
|
150
|
+
if (idx >= obj.data[ds].length) {
|
151
|
+
idx -= obj.data[ds].length;
|
152
|
+
} else {
|
153
|
+
break;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
tooltipObj.__dataset__ = ds;
|
158
|
+
tooltipObj.__index2__ = idx;
|
159
|
+
}
|
160
|
+
|
161
|
+
document.body.appendChild(tooltipObj);
|
162
|
+
//obj.canvas.parentNode.appendChild(tooltipObj);
|
163
|
+
|
164
|
+
var width = tooltipObj.offsetWidth;
|
165
|
+
var height = tooltipObj.offsetHeight;
|
166
|
+
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Set the width on the tooltip so it doesn't resize if the window is resized
|
170
|
+
*/
|
171
|
+
tooltipObj.style.width = width + 'px';
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
//
|
182
|
+
// position the tooltip on the mouse pointers position
|
183
|
+
//
|
184
|
+
var mouseXY = RG.getMouseXY(e);
|
185
|
+
var canvasXY = RG.getCanvasXY(obj.canvas);
|
186
|
+
|
187
|
+
// Position based on the mouse pointer coords on the page
|
188
|
+
tooltipObj.style.left = e.pageX - (parseFloat(tooltipObj.style.paddingLeft) + (width / 2)) + 'px';
|
189
|
+
tooltipObj.style.top = e.pageY - height - 10 + 'px';
|
190
|
+
|
191
|
+
// If the left is less than zero - set it to 5
|
192
|
+
if (parseFloat(tooltipObj.style.left) <= 5) {
|
193
|
+
tooltipObj.style.left = '5px';
|
194
|
+
}
|
195
|
+
|
196
|
+
// If the tooltip goes over the right hand edge then
|
197
|
+
// adjust the positioning
|
198
|
+
if (parseFloat(tooltipObj.style.left) + parseFloat(tooltipObj.style.width) > window.innerWidth) {
|
199
|
+
tooltipObj.style.left = ''
|
200
|
+
tooltipObj.style.right = '5px'
|
201
|
+
}
|
202
|
+
|
203
|
+
// If the canvas has fixed positioning then set the tooltip position to
|
204
|
+
// fixed too
|
205
|
+
if (RG.isFixed(obj.canvas)) {
|
206
|
+
var scrollTop = window.scrollY || document.documentElement.scrollTop;
|
207
|
+
|
208
|
+
tooltipObj.style.position = 'fixed';
|
209
|
+
tooltipObj.style.top = e.pageY - scrollTop - height - 10 + 'px';
|
210
|
+
}
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
// If the effect is fade:
|
218
|
+
// Increase the opacity from its default 0 up to 1 - fading the tooltip in
|
219
|
+
if (obj.get('chart.tooltips.effect') === 'fade') {
|
220
|
+
for (var i=1; i<=10; ++i) {
|
221
|
+
(function (index)
|
222
|
+
{
|
223
|
+
setTimeout(function ()
|
224
|
+
{
|
225
|
+
tooltipObj.style.opacity = index / 10;
|
226
|
+
}, index * 25);
|
227
|
+
})(i);
|
228
|
+
}
|
229
|
+
} else {
|
230
|
+
tooltipObj.style.opacity = 1;
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
/**
|
244
|
+
* If the tooltip it self is clicked, cancel it
|
245
|
+
*/
|
246
|
+
tooltipObj.onmousedown = function (e){e.stopPropagation();}
|
247
|
+
tooltipObj.onmouseup = function (e){e.stopPropagation();}
|
248
|
+
tooltipObj.onclick = function (e){if (e.button == 0) {e.stopPropagation();}}
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Keep a reference to the tooltip in the registry
|
258
|
+
*/
|
259
|
+
RG.Registry.Set('chart.tooltip', tooltipObj);
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Fire the tooltip event
|
263
|
+
*/
|
264
|
+
RG.fireCustomEvent(obj, 'ontooltip');
|
265
|
+
};
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
/**
|
271
|
+
*
|
272
|
+
*/
|
273
|
+
RG.getTooltipTextFromDIV = function (text)
|
274
|
+
{
|
275
|
+
// This regex is duplicated firher down on roughly line 888
|
276
|
+
var result = /^id:(.*)/.exec(text);
|
277
|
+
|
278
|
+
if (result && result[1] && document.getElementById(result[1])) {
|
279
|
+
text = document.getElementById(result[1]).innerHTML;
|
280
|
+
} else if (result && result[1]) {
|
281
|
+
text = '';
|
282
|
+
}
|
283
|
+
|
284
|
+
return text;
|
285
|
+
};
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
/**
|
291
|
+
*
|
292
|
+
*/
|
293
|
+
RG.getTooltipWidth = function (text, obj)
|
294
|
+
{
|
295
|
+
var div = document.createElement('DIV');
|
296
|
+
div.className = obj.Get('chart.tooltips.css.class');
|
297
|
+
div.style.paddingLeft = RG.tooltips.padding;
|
298
|
+
div.style.paddingRight = RG.tooltips.padding;
|
299
|
+
div.style.fontFamily = RG.tooltips.font_face;
|
300
|
+
div.style.fontSize = RG.tooltips.font_size;
|
301
|
+
div.style.visibility = 'hidden';
|
302
|
+
div.style.position = 'absolute';
|
303
|
+
div.style.top = '300px';
|
304
|
+
div.style.left = 0;
|
305
|
+
div.style.display = 'inline';
|
306
|
+
div.innerHTML = RG.getTooltipTextFromDIV(text);
|
307
|
+
document.body.appendChild(div);
|
308
|
+
|
309
|
+
return div.offsetWidth;
|
310
|
+
};
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Hides the currently shown tooltip
|
317
|
+
*/
|
318
|
+
RG.hideTooltip =
|
319
|
+
RG.HideTooltip = function ()
|
320
|
+
{
|
321
|
+
var tooltip = RG.Registry.Get('chart.tooltip');
|
322
|
+
var uid = arguments[0] && arguments[0].uid ? arguments[0].uid : null;
|
323
|
+
|
324
|
+
if (tooltip && tooltip.parentNode && (!uid || uid == tooltip.__canvas__.uid)) {
|
325
|
+
tooltip.parentNode.removeChild(tooltip);
|
326
|
+
tooltip.style.display = 'none';
|
327
|
+
tooltip.style.visibility = 'hidden';
|
328
|
+
RG.Registry.Set('chart.tooltip', null);
|
329
|
+
}
|
330
|
+
};
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
/**
|
336
|
+
* This (as the name suggests preloads any images it can find in the tooltip text
|
337
|
+
*
|
338
|
+
* @param object obj The chart object
|
339
|
+
*/
|
340
|
+
RG.preLoadTooltipImages =
|
341
|
+
RG.PreLoadTooltipImages = function (obj)
|
342
|
+
{
|
343
|
+
var tooltips = obj.Get('chart.tooltips');
|
344
|
+
|
345
|
+
if (RG.hasTooltips(obj)) {
|
346
|
+
|
347
|
+
if (obj.type == 'rscatter') {
|
348
|
+
tooltips = [];
|
349
|
+
for (var i=0; i<obj.data.length; ++i) {
|
350
|
+
tooltips.push(obj.data[3]);
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
for (var i=0; i<tooltips.length; ++i) {
|
355
|
+
// Add the text to an offscreen DIV tag
|
356
|
+
var div = document.createElement('DIV');
|
357
|
+
div.style.position = 'absolute';
|
358
|
+
div.style.opacity = 0;
|
359
|
+
div.style.top = '-100px';
|
360
|
+
div.style.left = '-100px';
|
361
|
+
div.innerHTML = tooltips[i];
|
362
|
+
document.body.appendChild(div);
|
363
|
+
|
364
|
+
// Now get the IMG tags and create them
|
365
|
+
var img_tags = div.getElementsByTagName('IMG');
|
366
|
+
|
367
|
+
// Create the image in an off-screen image tag
|
368
|
+
for (var j=0; j<img_tags.length; ++j) {
|
369
|
+
if (img_tags && img_tags[i]) {
|
370
|
+
var img = document.createElement('IMG');
|
371
|
+
img.style.position = 'absolute';
|
372
|
+
img.style.opacity = 0;
|
373
|
+
img.style.top = '-100px';
|
374
|
+
img.style.left = '-100px';
|
375
|
+
img.src = img_tags[i].src
|
376
|
+
document.body.appendChild(img);
|
377
|
+
|
378
|
+
setTimeout(function () {document.body.removeChild(img);}, 250);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
|
382
|
+
// Now remove the div
|
383
|
+
document.body.removeChild(div);
|
384
|
+
}
|
385
|
+
}
|
386
|
+
};
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
/**
|
392
|
+
* This is the tooltips canvas onmousemove listener
|
393
|
+
*/
|
394
|
+
RG.tooltips_mousemove =
|
395
|
+
RG.Tooltips_mousemove = function (obj, e)
|
396
|
+
{
|
397
|
+
var shape = obj.getShape(e);
|
398
|
+
var changeCursor_tooltips = false
|
399
|
+
|
400
|
+
if ( shape
|
401
|
+
&& typeof(shape['index']) == 'number'
|
402
|
+
&& obj.Get('chart.tooltips')[shape['index']]
|
403
|
+
) {
|
404
|
+
|
405
|
+
var text = RG.parseTooltipText(obj.Get('chart.tooltips'), shape['index']);
|
406
|
+
|
407
|
+
if (text) {
|
408
|
+
|
409
|
+
/**
|
410
|
+
* Change the cursor
|
411
|
+
*/
|
412
|
+
changeCursor_tooltips = true;
|
413
|
+
|
414
|
+
if (obj.Get('chart.tooltips.event') == 'onmousemove') {
|
415
|
+
|
416
|
+
// Show the tooltip if it's not the same as the one already visible
|
417
|
+
if (
|
418
|
+
!RG.Registry.Get('chart.tooltip')
|
419
|
+
|| RG.Registry.Get('chart.tooltip').__object__.uid != obj.uid
|
420
|
+
|| RG.Registry.Get('chart.tooltip').__index__ != shape['index']
|
421
|
+
) {
|
422
|
+
|
423
|
+
RG.hideTooltip();
|
424
|
+
RG.Clear(obj.canvas);
|
425
|
+
RG.redraw();
|
426
|
+
RG.tooltip(obj, text, e.pageX, e.pageY, shape['index']);
|
427
|
+
obj.Highlight(shape);
|
428
|
+
}
|
429
|
+
}
|
430
|
+
}
|
431
|
+
|
432
|
+
/**
|
433
|
+
* More highlighting
|
434
|
+
*/
|
435
|
+
} else if (shape && typeof(shape['index']) == 'number') {
|
436
|
+
|
437
|
+
var text = RG.parseTooltipText(obj.Get('chart.tooltips'), shape['index']);
|
438
|
+
|
439
|
+
if (text) {
|
440
|
+
changeCursor_tooltips = true
|
441
|
+
}
|
442
|
+
}
|
443
|
+
|
444
|
+
return changeCursor_tooltips;
|
445
|
+
};
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
// End module pattern
|
451
|
+
})(window, document);
|