rgraph-rails 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rgraph-rails/version.rb +3 -0
- data/lib/rgraph-rails.rb +8 -0
- data/license.txt +19 -0
- data/rgraph-rails.gemspec +26 -0
- data/vendor/assets/images/bg.png +0 -0
- data/vendor/assets/images/bullet.png +0 -0
- data/vendor/assets/images/facebook-large.png +0 -0
- data/vendor/assets/images/google-plus-large.png +0 -0
- data/vendor/assets/images/logo.png +0 -0
- data/vendor/assets/images/meter-image-sd-needle.png +0 -0
- data/vendor/assets/images/meter-image-sd.png +0 -0
- data/vendor/assets/images/meter-sketch-needle.png +0 -0
- data/vendor/assets/images/meter-sketch.png +0 -0
- data/vendor/assets/images/odometer-background.png +0 -0
- data/vendor/assets/images/rgraph.jpg +0 -0
- data/vendor/assets/images/title.png +0 -0
- data/vendor/assets/images/twitter-large.png +0 -0
- data/vendor/assets/javascripts/RGraph.bar.js +3246 -0
- data/vendor/assets/javascripts/RGraph.bipolar.js +2003 -0
- data/vendor/assets/javascripts/RGraph.common.annotate.js +399 -0
- data/vendor/assets/javascripts/RGraph.common.context.js +600 -0
- data/vendor/assets/javascripts/RGraph.common.core.js +4751 -0
- data/vendor/assets/javascripts/RGraph.common.csv.js +275 -0
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +454 -0
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +1194 -0
- data/vendor/assets/javascripts/RGraph.common.effects.js +1524 -0
- data/vendor/assets/javascripts/RGraph.common.key.js +735 -0
- data/vendor/assets/javascripts/RGraph.common.resizing.js +550 -0
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +605 -0
- data/vendor/assets/javascripts/RGraph.common.zoom.js +223 -0
- data/vendor/assets/javascripts/RGraph.drawing.background.js +636 -0
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +579 -0
- data/vendor/assets/javascripts/RGraph.drawing.image.js +810 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +710 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +672 -0
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +568 -0
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +623 -0
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +603 -0
- data/vendor/assets/javascripts/RGraph.drawing.text.js +648 -0
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +815 -0
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +860 -0
- data/vendor/assets/javascripts/RGraph.fuel.js +965 -0
- data/vendor/assets/javascripts/RGraph.funnel.js +988 -0
- data/vendor/assets/javascripts/RGraph.gantt.js +1242 -0
- data/vendor/assets/javascripts/RGraph.gauge.js +1391 -0
- data/vendor/assets/javascripts/RGraph.hbar.js +1794 -0
- data/vendor/assets/javascripts/RGraph.hprogress.js +1307 -0
- data/vendor/assets/javascripts/RGraph.line.js +3940 -0
- data/vendor/assets/javascripts/RGraph.meter.js +1242 -0
- data/vendor/assets/javascripts/RGraph.modaldialog.js +292 -0
- data/vendor/assets/javascripts/RGraph.odo.js +1265 -0
- data/vendor/assets/javascripts/RGraph.pie.js +1979 -0
- data/vendor/assets/javascripts/RGraph.radar.js +1840 -0
- data/vendor/assets/javascripts/RGraph.rose.js +1860 -0
- data/vendor/assets/javascripts/RGraph.rscatter.js +1332 -0
- data/vendor/assets/javascripts/RGraph.scatter.js +3029 -0
- data/vendor/assets/javascripts/RGraph.thermometer.js +1131 -0
- data/vendor/assets/javascripts/RGraph.vprogress.js +1326 -0
- data/vendor/assets/javascripts/RGraph.waterfall.js +1252 -0
- data/vendor/assets/javascripts/financial-data.js +1067 -0
- data/vendor/assets/stylesheets/ModalDialog.css +90 -0
- data/vendor/assets/stylesheets/animations.css +3347 -0
- data/vendor/assets/stylesheets/website.css +402 -0
- metadata +175 -0
@@ -0,0 +1,605 @@
|
|
1
|
+
// version: 2015-11-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 dual licensed under the Open Source GPL (General Public License) |
|
9
|
+
* | v2.0 license and a commercial license which means that you're not bound by |
|
10
|
+
* | the terms of the GPL. The commercial license is just �99 (GBP) and you can |
|
11
|
+
* | read about it here: |
|
12
|
+
* | http://www.rgraph.net/license |
|
13
|
+
* o--------------------------------------------------------------------------------o
|
14
|
+
*/
|
15
|
+
|
16
|
+
RGraph = window.RGraph || {isRGraph: true};
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
// Module pattern
|
22
|
+
(function (win, doc, undefined)
|
23
|
+
{
|
24
|
+
var RG = RGraph,
|
25
|
+
ua = navigator.userAgent,
|
26
|
+
ma = Math;
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
/**
|
32
|
+
* This is used in two functions, hence it's here
|
33
|
+
*/
|
34
|
+
RG.tooltips = {};
|
35
|
+
RG.tooltips.padding = '3px';
|
36
|
+
RG.tooltips.font_face = 'Tahoma';
|
37
|
+
RG.tooltips.font_size = '10pt';
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Shows a tooltip next to the mouse pointer
|
44
|
+
*
|
45
|
+
* @param canvas object The canvas element object
|
46
|
+
* @param text string The tooltip text
|
47
|
+
* @param int x The X position that the tooltip should appear at. Combined with the canvases offsetLeft
|
48
|
+
* gives the absolute X position
|
49
|
+
* @param int y The Y position the tooltip should appear at. Combined with the canvases offsetTop
|
50
|
+
* gives the absolute Y position
|
51
|
+
* @param int idx The index of the tooltip in the graph objects tooltip array
|
52
|
+
* @param object e The event object
|
53
|
+
*/
|
54
|
+
RG.tooltip =
|
55
|
+
RG.Tooltip = function (obj, text, x, y, idx, e)
|
56
|
+
{
|
57
|
+
/**
|
58
|
+
* chart.tooltip.override allows you to totally take control of rendering the tooltip yourself
|
59
|
+
*/
|
60
|
+
if (typeof(obj.Get('chart.tooltips.override')) == 'function') {
|
61
|
+
return obj.Get('chart.tooltips.override')(obj, text, x, y, idx);
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Save the X/Y coords
|
66
|
+
*/
|
67
|
+
var originalX = x;
|
68
|
+
var originalY = y;
|
69
|
+
|
70
|
+
/**
|
71
|
+
* This facilitates the "id:xxx" format
|
72
|
+
*/
|
73
|
+
text = RGraph.getTooltipTextFromDIV(text);
|
74
|
+
|
75
|
+
/**
|
76
|
+
* First clear any exising timers
|
77
|
+
*/
|
78
|
+
var timers = RGraph.Registry.Get('chart.tooltip.timers');
|
79
|
+
|
80
|
+
if (timers && timers.length) {
|
81
|
+
for (i=0; i<timers.length; ++i) {
|
82
|
+
clearTimeout(timers[i]);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
RGraph.Registry.Set('chart.tooltip.timers', []);
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Hide the context menu if it's currently shown
|
89
|
+
*/
|
90
|
+
if (obj.Get('chart.contextmenu')) {
|
91
|
+
RGraph.HideContext();
|
92
|
+
}
|
93
|
+
|
94
|
+
var effect = obj.Get('chart.tooltips.effect') ? obj.Get('chart.tooltips.effect').toLowerCase() : 'fade';
|
95
|
+
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Show a tool tip
|
99
|
+
*/
|
100
|
+
var tooltipObj = document.createElement('DIV');
|
101
|
+
tooltipObj.className = obj.Get('chart.tooltips.css.class');
|
102
|
+
tooltipObj.style.display = 'none';
|
103
|
+
tooltipObj.style.position = RGraph.isFixed(obj.canvas) ? 'fixed' : 'absolute';
|
104
|
+
tooltipObj.style.left = 0;
|
105
|
+
tooltipObj.style.top = 0;
|
106
|
+
tooltipObj.style.backgroundColor = 'rgb(255,255,239)';
|
107
|
+
tooltipObj.style.color = 'black';
|
108
|
+
if (!document.all) tooltipObj.style.border = '';
|
109
|
+
tooltipObj.style.visibility = 'visible';
|
110
|
+
tooltipObj.style.paddingLeft = RGraph.tooltips.padding;
|
111
|
+
tooltipObj.style.paddingRight = RGraph.tooltips.padding;
|
112
|
+
tooltipObj.style.fontFamily = RGraph.tooltips.font_face;
|
113
|
+
tooltipObj.style.fontSize = RGraph.tooltips.font_size;
|
114
|
+
tooltipObj.style.zIndex = 3;
|
115
|
+
|
116
|
+
// Only apply a border if there's content
|
117
|
+
if (RGraph.trim(text).length > 0) {
|
118
|
+
tooltipObj.style.border = '1px #bbb solid';
|
119
|
+
}
|
120
|
+
|
121
|
+
tooltipObj.style.borderRadius = '5px';
|
122
|
+
tooltipObj.style.MozBorderRadius = '5px';
|
123
|
+
tooltipObj.style.WebkitBorderRadius = '5px';
|
124
|
+
tooltipObj.style.WebkitBoxShadow = 'rgba(96,96,96,0.5) 0 0 5px';
|
125
|
+
tooltipObj.style.MozBoxShadow = 'rgba(96,96,96,0.5) 0 0 5px';
|
126
|
+
tooltipObj.style.boxShadow = 'rgba(96,96,96,0.5) 0 0 5px';
|
127
|
+
tooltipObj.style.filter = 'progid:DXImageTransform.Microsoft.Shadow(color=#666666,direction=135)';
|
128
|
+
tooltipObj.style.opacity = 0;
|
129
|
+
//tooltipObj.style.overflow = 'hidden';
|
130
|
+
tooltipObj.innerHTML = text;
|
131
|
+
tooltipObj.__text__ = text; // This is set because the innerHTML can change when it's set
|
132
|
+
tooltipObj.__canvas__ = obj.canvas;
|
133
|
+
tooltipObj.style.display = 'inline';
|
134
|
+
tooltipObj.id = '__rgraph_tooltip_' + obj.canvas.id + '_' + obj.uid + '_'+ idx;
|
135
|
+
tooltipObj.__event__ = obj.Get('chart.tooltips.event') || 'click';
|
136
|
+
tooltipObj.__object__ = obj;
|
137
|
+
|
138
|
+
if (typeof(idx) == 'number') {
|
139
|
+
tooltipObj.__index__ = idx;
|
140
|
+
origIdx = idx;
|
141
|
+
}
|
142
|
+
|
143
|
+
if (obj.type == 'line' || obj.type == 'radar') {
|
144
|
+
for (var ds=0; ds<obj.data.length; ++ds) {
|
145
|
+
if (idx >= obj.data[ds].length) {
|
146
|
+
idx -= obj.data[ds].length;
|
147
|
+
} else {
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
tooltipObj.__dataset__ = ds;
|
153
|
+
tooltipObj.__index2__ = idx;
|
154
|
+
}
|
155
|
+
|
156
|
+
document.body.appendChild(tooltipObj);
|
157
|
+
|
158
|
+
var width = tooltipObj.offsetWidth;
|
159
|
+
var height = tooltipObj.offsetHeight;
|
160
|
+
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Set the width on the tooltip so it doesn't resize if the window is resized
|
164
|
+
*/
|
165
|
+
tooltipObj.style.width = width + 'px';
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
tooltipObj.style.top = (y - height - 2) + 'px';
|
170
|
+
|
171
|
+
/**
|
172
|
+
* If the function exists call the object specific tooltip positioning function
|
173
|
+
*/
|
174
|
+
if (typeof(obj.positionTooltip) == 'function') {
|
175
|
+
if (tooltipObj.innerHTML.length > 0) {
|
176
|
+
|
177
|
+
obj.positionTooltip(obj, x, y, tooltipObj, origIdx ? origIdx : idx);
|
178
|
+
|
179
|
+
if (obj.Get('chart.tooltips.coords.page')) {
|
180
|
+
|
181
|
+
tooltipObj.style.left = e.pageX - (width / 2) - 4.25 + 'px';
|
182
|
+
tooltipObj.style.top = e.pageY - height - 10 + 'px';
|
183
|
+
|
184
|
+
document.getElementById('__rgraph_tooltip_pointer__').style.left = (parseInt(tooltipObj.offsetWidth) / 2) - 8.5 + 'px';
|
185
|
+
}
|
186
|
+
}
|
187
|
+
} else {
|
188
|
+
tooltipObj.style.left = e.pageX - (width / 2) - 4.25 + 'px';
|
189
|
+
tooltipObj.style.top = e.pageY - height - 7 + 'px';
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
if (effect == 'fade' || effect == 'expand' || effect == 'contract' || effect == 'snap') {
|
194
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.1;}, 25);
|
195
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.2;}, 50);
|
196
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.3;}, 75);
|
197
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.4;}, 100);
|
198
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.5;}, 125);
|
199
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.6;}, 150);
|
200
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.7;}, 175);
|
201
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.8;}, 200);
|
202
|
+
setTimeout(function () {tooltipObj.style.opacity = 0.9;}, 225);
|
203
|
+
|
204
|
+
if (effect == 'expand' || effect == 'contract' || effect == 'snap') {
|
205
|
+
console.log('[RGRAPH] The snap, expand and contract tooltip effects are deprecated. Available effects now are fade and none');
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
setTimeout("if (RGraph.Registry.Get('chart.tooltip')) { RGraph.Registry.Get('chart.tooltip').style.opacity = 1;}", effect == 'none' ? 50 : 250);
|
210
|
+
|
211
|
+
/**
|
212
|
+
* If the tooltip it self is clicked, cancel it
|
213
|
+
*/
|
214
|
+
tooltipObj.onmousedown = function (e){e.stopPropagation();}
|
215
|
+
tooltipObj.onmouseup = function (e){e.stopPropagation();}
|
216
|
+
tooltipObj.onclick = function (e){if (e.button == 0) {e.stopPropagation();}}
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Keep a reference to the tooltip in the registry
|
226
|
+
*/
|
227
|
+
RGraph.Registry.Set('chart.tooltip', tooltipObj);
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Fire the tooltip event
|
231
|
+
*/
|
232
|
+
RG.FireCustomEvent(obj, 'ontooltip');
|
233
|
+
};
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
/**
|
240
|
+
*
|
241
|
+
*/
|
242
|
+
RG.getTooltipTextFromDIV = function (text)
|
243
|
+
{
|
244
|
+
// This regex is duplicated firher down on roughly line 888
|
245
|
+
var result = /^id:(.*)/.exec(text);
|
246
|
+
|
247
|
+
if (result && result[1] && document.getElementById(result[1])) {
|
248
|
+
text = document.getElementById(result[1]).innerHTML;
|
249
|
+
} else if (result && result[1]) {
|
250
|
+
text = '';
|
251
|
+
}
|
252
|
+
|
253
|
+
return text;
|
254
|
+
};
|
255
|
+
|
256
|
+
|
257
|
+
/**
|
258
|
+
*
|
259
|
+
*/
|
260
|
+
RG.getTooltipWidth = function (text, obj)
|
261
|
+
{
|
262
|
+
var div = document.createElement('DIV');
|
263
|
+
div.className = obj.Get('chart.tooltips.css.class');
|
264
|
+
div.style.paddingLeft = RGraph.tooltips.padding;
|
265
|
+
div.style.paddingRight = RGraph.tooltips.padding;
|
266
|
+
div.style.fontFamily = RGraph.tooltips.font_face;
|
267
|
+
div.style.fontSize = RGraph.tooltips.font_size;
|
268
|
+
div.style.visibility = 'hidden';
|
269
|
+
div.style.position = 'absolute';
|
270
|
+
div.style.top = '300px';
|
271
|
+
div.style.left = 0;
|
272
|
+
div.style.display = 'inline';
|
273
|
+
div.innerHTML = RGraph.getTooltipTextFromDIV(text);
|
274
|
+
document.body.appendChild(div);
|
275
|
+
|
276
|
+
return div.offsetWidth;
|
277
|
+
};
|
278
|
+
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Hides the currently shown tooltip
|
282
|
+
*/
|
283
|
+
RG.hideTooltip =
|
284
|
+
RG.HideTooltip = function ()
|
285
|
+
{
|
286
|
+
var tooltip = RGraph.Registry.Get('chart.tooltip');
|
287
|
+
var uid = arguments[0] && arguments[0].uid ? arguments[0].uid : null;
|
288
|
+
|
289
|
+
if (tooltip && tooltip.parentNode && (!uid || uid == tooltip.__canvas__.uid)) {
|
290
|
+
tooltip.parentNode.removeChild(tooltip);
|
291
|
+
tooltip.style.display = 'none';
|
292
|
+
tooltip.style.visibility = 'hidden';
|
293
|
+
RGraph.Registry.Set('chart.tooltip', null);
|
294
|
+
}
|
295
|
+
};
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
/**
|
300
|
+
* This installs the window mousedown event listener. It clears any highlight that may
|
301
|
+
* be present.
|
302
|
+
*
|
303
|
+
* @param object obj The chart object
|
304
|
+
*
|
305
|
+
RGraph.InstallWindowMousedownTooltipListener = function (obj)
|
306
|
+
{
|
307
|
+
if (RGraph.Registry.Get('__rgraph_event_listeners__')['window_mousedown']) {
|
308
|
+
return;
|
309
|
+
}
|
310
|
+
|
311
|
+
// When the canvas is cleared, reset this flag so that the event listener is installed again
|
312
|
+
RGraph.AddCustomEventListener(obj, 'onclear', function (obj) {RGraph.Registry.Get('__rgraph_event_listeners__')['window_mousedown'] = false;})
|
313
|
+
|
314
|
+
// NOTE: Global on purpose
|
315
|
+
rgraph_window_mousedown = function (e)
|
316
|
+
{
|
317
|
+
if (RGraph.Registry.Get('chart.tooltip')) {
|
318
|
+
|
319
|
+
var obj = RGraph.Registry.Get('chart.tooltip').__object__;
|
320
|
+
var canvas = obj.canvas;
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Get rid of the tooltip and redraw all canvases on the page
|
324
|
+
*
|
325
|
+
RGraph.HideTooltip();
|
326
|
+
|
327
|
+
/**
|
328
|
+
* No need to clear if highlighting is disabled
|
329
|
+
*
|
330
|
+
* TODO Really, need to check ALL of the pertinent objects that
|
331
|
+
* are drawing on the canvas using the ObjectRegistry -
|
332
|
+
* ie RGraph.ObjectRegistry.getObjectsByCanvasID()
|
333
|
+
*
|
334
|
+
if (obj.Get('chart.tooltips.highlight')) {
|
335
|
+
RGraph.RedrawCanvas(canvas);
|
336
|
+
}
|
337
|
+
}
|
338
|
+
}
|
339
|
+
window.addEventListener('mousedown', rgraph_window_mousedown, false);
|
340
|
+
RGraph.AddEventListener('window_' + obj.id, 'mousedown', rgraph_window_mousedown);
|
341
|
+
}
|
342
|
+
*/
|
343
|
+
|
344
|
+
|
345
|
+
/**
|
346
|
+
* This installs the canvas mouseup event listener. This is the function that
|
347
|
+
* actually shows the appropriate (if any) tooltip.
|
348
|
+
*
|
349
|
+
* @param object obj The chart object
|
350
|
+
*
|
351
|
+
RGraph.InstallCanvasMouseupTooltipListener = function (obj)
|
352
|
+
{
|
353
|
+
if (RGraph.Registry.Get('__rgraph_event_listeners__')[obj.canvas.id + '_mouseup']) {
|
354
|
+
return;
|
355
|
+
}
|
356
|
+
RGraph.Registry.Get('__rgraph_event_listeners__')[obj.canvas.id + '_mouseup'] = true;
|
357
|
+
|
358
|
+
// When the canvas is cleared, reset this flag so that the event listener is installed again
|
359
|
+
RGraph.AddCustomEventListener(obj, 'onclear', function (obj) {RGraph.Registry.Get('__rgraph_event_listeners__')[obj.canvas.id + '_mouseup'] = false});
|
360
|
+
|
361
|
+
// Install the onclick event handler for the tooltips
|
362
|
+
//
|
363
|
+
// // NOTE: Global on purpose
|
364
|
+
rgraph_canvas_mouseup_func = function (e)
|
365
|
+
{
|
366
|
+
var x = arguments[1] ? arguments[1] : e.pageX;
|
367
|
+
var y = arguments[2] ? arguments[2] : e.pageY;
|
368
|
+
|
369
|
+
var objects = RGraph.ObjectRegistry.getObjectsByCanvasID(e.target.id);
|
370
|
+
|
371
|
+
// It's important to go backwards through the array so that the front charts
|
372
|
+
// are checked first, then the charts at the back
|
373
|
+
for (var i=(objects.length - 1); i>=0; --i) {
|
374
|
+
|
375
|
+
var shape = objects[i].getShape(e);
|
376
|
+
|
377
|
+
if (shape && shape['object'] && !RGraph.Registry.Get('chart.tooltip')) {
|
378
|
+
|
379
|
+
/**
|
380
|
+
* This allows the Scatter chart funky tooltips style
|
381
|
+
*
|
382
|
+
if (objects[i].type == 'scatter' && shape['dataset'] > 0) {
|
383
|
+
for (var j=0; j<(objects[i].data.length - 1); ++j) {
|
384
|
+
shape['index'] += objects[i].data[j].length;
|
385
|
+
}
|
386
|
+
}
|
387
|
+
|
388
|
+
var text = RGraph.parseTooltipText(objects[i].Get('chart.tooltips'), shape['index']);
|
389
|
+
|
390
|
+
if (text) {
|
391
|
+
|
392
|
+
if (shape['object'].Get('chart.tooltips.hotspot.xonly')) {
|
393
|
+
var canvasXY = RGraph.getCanvasXY(objects[i].canvas);
|
394
|
+
x = canvasXY[0] + shape[1];
|
395
|
+
y = canvasXY[1] + shape[2];
|
396
|
+
}
|
397
|
+
|
398
|
+
RGraph.Tooltip(objects[i], text, x, y, shape['index']);
|
399
|
+
objects[i].Highlight(shape);
|
400
|
+
|
401
|
+
e.stopPropagation();
|
402
|
+
e.cancelBubble = true;
|
403
|
+
return false;
|
404
|
+
}
|
405
|
+
}
|
406
|
+
}
|
407
|
+
}
|
408
|
+
obj.canvas.addEventListener('mouseup', rgraph_canvas_mouseup_func, false);
|
409
|
+
RGraph.AddEventListener(obj.id, 'mouseup', rgraph_canvas_mouseup_func);
|
410
|
+
}
|
411
|
+
*/
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
/**
|
416
|
+
* This installs the canvas mousemove event listener. This is the function that
|
417
|
+
* changes the mouse pointer if need be.
|
418
|
+
*
|
419
|
+
* @param object obj The chart object
|
420
|
+
*
|
421
|
+
RGraph.InstallCanvasMousemoveTooltipListener = function (obj)
|
422
|
+
{
|
423
|
+
if (RGraph.Registry.Get('__rgraph_event_listeners__')[obj.canvas.id + '_mousemove']) {
|
424
|
+
return;
|
425
|
+
}
|
426
|
+
RGraph.Registry.Get('__rgraph_event_listeners__')[obj.canvas.id + '_mousemove'] = true;
|
427
|
+
|
428
|
+
// When the canvas is cleared, reset this flag so that the event listener is installed again
|
429
|
+
RGraph.AddCustomEventListener(obj, 'onclear', function (obj) {RGraph.Registry.Get('__rgraph_event_listeners__')[obj.canvas.id + '_mousemove'] = false})
|
430
|
+
|
431
|
+
// Install the mousemove event handler for the tooltips
|
432
|
+
//
|
433
|
+
// NOTE: Global on purpose
|
434
|
+
rgraph_canvas_mousemove_func = function (e)
|
435
|
+
{
|
436
|
+
var objects = RGraph.ObjectRegistry.getObjectsByCanvasID(e.target.id);
|
437
|
+
|
438
|
+
for (var i=0; i<objects.length; ++i) {
|
439
|
+
|
440
|
+
var shape = objects[i].getShape(e);
|
441
|
+
|
442
|
+
if (shape && shape['object']) {
|
443
|
+
|
444
|
+
/**
|
445
|
+
* This allows the Scatter chart funky tooltips style
|
446
|
+
*
|
447
|
+
if (objects[i].type == 'scatter' && shape['dataset'] > 0) {
|
448
|
+
for (var j=0; j<(objects[i].data.length - 1); ++j) {
|
449
|
+
shape['index'] += objects[i].data[j].length;
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
var text = RGraph.parseTooltipText(objects[i].Get('chart.tooltips'), shape['index']);
|
454
|
+
|
455
|
+
|
456
|
+
if (text) {
|
457
|
+
|
458
|
+
e.target.style.cursor = 'pointer';
|
459
|
+
|
460
|
+
/**
|
461
|
+
* This facilitates the event triggering the tooltips being mousemove
|
462
|
+
*
|
463
|
+
|
464
|
+
if ( typeof(objects[i].Get('chart.tooltips.event')) == 'string'
|
465
|
+
&& objects[i].Get('chart.tooltips.event') == 'onmousemove'
|
466
|
+
&& (!RGraph.Registry.Get('chart.tooltip') || shape['index'] != RGraph.Registry.Get('chart.tooltip').__index__ || shape['object'].uid != RGraph.Registry.Get('chart.tooltip').__object__.uid)
|
467
|
+
) {
|
468
|
+
|
469
|
+
// Hide any current tooltip
|
470
|
+
rgraph_window_mousedown(e);
|
471
|
+
|
472
|
+
rgraph_canvas_mouseup_func(e);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
478
|
+
obj.canvas.addEventListener('mousemove', rgraph_canvas_mousemove_func, false);
|
479
|
+
RGraph.AddEventListener(obj.id, 'mousemove', rgraph_canvas_mousemove_func);
|
480
|
+
}
|
481
|
+
*/
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
/**
|
490
|
+
* This (as the name suggests preloads any images it can find in the tooltip text
|
491
|
+
*
|
492
|
+
* @param object obj The chart object
|
493
|
+
*/
|
494
|
+
RG.preLoadTooltipImages =
|
495
|
+
RG.PreLoadTooltipImages = function (obj)
|
496
|
+
{
|
497
|
+
var tooltips = obj.Get('chart.tooltips');
|
498
|
+
|
499
|
+
if (RGraph.hasTooltips(obj)) {
|
500
|
+
|
501
|
+
if (obj.type == 'rscatter') {
|
502
|
+
tooltips = [];
|
503
|
+
for (var i=0; i<obj.data.length; ++i) {
|
504
|
+
tooltips.push(obj.data[3]);
|
505
|
+
}
|
506
|
+
}
|
507
|
+
|
508
|
+
for (var i=0; i<tooltips.length; ++i) {
|
509
|
+
// Add the text to an offscreen DIV tag
|
510
|
+
var div = document.createElement('DIV');
|
511
|
+
div.style.position = 'absolute';
|
512
|
+
div.style.opacity = 0;
|
513
|
+
div.style.top = '-100px';
|
514
|
+
div.style.left = '-100px';
|
515
|
+
div.innerHTML = tooltips[i];
|
516
|
+
document.body.appendChild(div);
|
517
|
+
|
518
|
+
// Now get the IMG tags and create them
|
519
|
+
var img_tags = div.getElementsByTagName('IMG');
|
520
|
+
|
521
|
+
// Create the image in an off-screen image tag
|
522
|
+
for (var j=0; j<img_tags.length; ++j) {
|
523
|
+
if (img_tags && img_tags[i]) {
|
524
|
+
var img = document.createElement('IMG');
|
525
|
+
img.style.position = 'absolute';
|
526
|
+
img.style.opacity = 0;
|
527
|
+
img.style.top = '-100px';
|
528
|
+
img.style.left = '-100px';
|
529
|
+
img.src = img_tags[i].src
|
530
|
+
document.body.appendChild(img);
|
531
|
+
|
532
|
+
setTimeout(function () {document.body.removeChild(img);}, 250);
|
533
|
+
}
|
534
|
+
}
|
535
|
+
|
536
|
+
// Now remove the div
|
537
|
+
document.body.removeChild(div);
|
538
|
+
}
|
539
|
+
}
|
540
|
+
};
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
/**
|
546
|
+
* This is the tooltips canvas onmousemove listener
|
547
|
+
*/
|
548
|
+
RG.tooltips_mousemove =
|
549
|
+
RG.Tooltips_mousemove = function (obj, e)
|
550
|
+
{
|
551
|
+
var shape = obj.getShape(e);
|
552
|
+
var changeCursor_tooltips = false
|
553
|
+
|
554
|
+
if ( shape
|
555
|
+
&& typeof(shape['index']) == 'number'
|
556
|
+
&& obj.Get('chart.tooltips')[shape['index']]
|
557
|
+
) {
|
558
|
+
|
559
|
+
var text = RGraph.parseTooltipText(obj.Get('chart.tooltips'), shape['index']);
|
560
|
+
|
561
|
+
if (text) {
|
562
|
+
|
563
|
+
/**
|
564
|
+
* Change the cursor
|
565
|
+
*/
|
566
|
+
changeCursor_tooltips = true;
|
567
|
+
|
568
|
+
if (obj.Get('chart.tooltips.event') == 'onmousemove') {
|
569
|
+
|
570
|
+
// Show the tooltip if it's not the same as the one already visible
|
571
|
+
if (
|
572
|
+
!RGraph.Registry.Get('chart.tooltip')
|
573
|
+
|| RGraph.Registry.Get('chart.tooltip').__object__.uid != obj.uid
|
574
|
+
|| RGraph.Registry.Get('chart.tooltip').__index__ != shape['index']
|
575
|
+
) {
|
576
|
+
|
577
|
+
RGraph.HideTooltip();
|
578
|
+
RGraph.Clear(obj.canvas);
|
579
|
+
RGraph.Redraw();
|
580
|
+
RGraph.Tooltip(obj, text, e.pageX, e.pageY, shape['index']);
|
581
|
+
obj.Highlight(shape);
|
582
|
+
}
|
583
|
+
}
|
584
|
+
}
|
585
|
+
|
586
|
+
/**
|
587
|
+
* More highlighting
|
588
|
+
*/
|
589
|
+
} else if (shape && typeof(shape['index']) == 'number') {
|
590
|
+
|
591
|
+
var text = RGraph.parseTooltipText(obj.Get('chart.tooltips'), shape['index']);
|
592
|
+
|
593
|
+
if (text) {
|
594
|
+
changeCursor_tooltips = true
|
595
|
+
}
|
596
|
+
}
|
597
|
+
|
598
|
+
return changeCursor_tooltips;
|
599
|
+
};
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
// End module pattern
|
605
|
+
})(window, document);
|