rgraph-rails 5.00 → 6.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/publish-geml.yaml +46 -0
  3. data/.gitignore +1 -0
  4. data/README.md +4 -5
  5. data/lib/rgraph-rails/version.rb +1 -1
  6. data/rgraph-rails.gemspec +4 -4
  7. data/vendor/assets/javascripts/RGraph.activity.js +1691 -0
  8. data/vendor/assets/javascripts/RGraph.bar.js +4253 -236
  9. data/vendor/assets/javascripts/RGraph.bipolar.js +3958 -162
  10. data/vendor/assets/javascripts/RGraph.common.annotate.js +414 -35
  11. data/vendor/assets/javascripts/RGraph.common.context.js +635 -30
  12. data/vendor/assets/javascripts/RGraph.common.core.js +10485 -419
  13. data/vendor/assets/javascripts/RGraph.common.csv.js +508 -27
  14. data/vendor/assets/javascripts/RGraph.common.dynamic.js +1693 -90
  15. data/vendor/assets/javascripts/RGraph.common.effects.js +1629 -89
  16. data/vendor/assets/javascripts/RGraph.common.key.js +1003 -53
  17. data/vendor/assets/javascripts/RGraph.common.moment.js +5670 -0
  18. data/vendor/assets/javascripts/RGraph.common.sheets.js +541 -31
  19. data/vendor/assets/javascripts/RGraph.common.sheets.php +351 -0
  20. data/vendor/assets/javascripts/RGraph.common.starburst.js +382 -0
  21. data/vendor/assets/javascripts/RGraph.common.table.js +386 -0
  22. data/vendor/assets/javascripts/RGraph.common.tooltips.js +1433 -32
  23. data/vendor/assets/javascripts/RGraph.drawing.background.js +660 -35
  24. data/vendor/assets/javascripts/RGraph.drawing.circle.js +618 -34
  25. data/vendor/assets/javascripts/RGraph.drawing.image.js +857 -52
  26. data/vendor/assets/javascripts/RGraph.drawing.line.js +712 -0
  27. data/vendor/assets/javascripts/RGraph.drawing.marker1.js +760 -38
  28. data/vendor/assets/javascripts/RGraph.drawing.marker2.js +740 -37
  29. data/vendor/assets/javascripts/RGraph.drawing.marker3.js +573 -36
  30. data/vendor/assets/javascripts/RGraph.drawing.poly.js +667 -36
  31. data/vendor/assets/javascripts/RGraph.drawing.rect.js +638 -34
  32. data/vendor/assets/javascripts/RGraph.drawing.text.js +672 -37
  33. data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +653 -52
  34. data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +714 -51
  35. data/vendor/assets/javascripts/RGraph.fuel.js +1149 -59
  36. data/vendor/assets/javascripts/RGraph.funnel.js +1277 -56
  37. data/vendor/assets/javascripts/RGraph.gantt.js +1646 -82
  38. data/vendor/assets/javascripts/RGraph.gauge.js +1773 -89
  39. data/vendor/assets/javascripts/RGraph.hbar.js +3869 -159
  40. data/vendor/assets/javascripts/RGraph.horseshoe.js +970 -0
  41. data/vendor/assets/javascripts/RGraph.hprogress.js +1829 -81
  42. data/vendor/assets/javascripts/RGraph.line.js +5293 -244
  43. data/vendor/assets/javascripts/RGraph.meter.js +1570 -77
  44. data/vendor/assets/javascripts/RGraph.modaldialog.js +300 -19
  45. data/vendor/assets/javascripts/RGraph.odo.js +1553 -68
  46. data/vendor/assets/javascripts/RGraph.pie.js +3273 -129
  47. data/vendor/assets/javascripts/RGraph.radar.js +2333 -108
  48. data/vendor/assets/javascripts/RGraph.rose.js +2685 -114
  49. data/vendor/assets/javascripts/RGraph.rscatter.js +1920 -80
  50. data/vendor/assets/javascripts/RGraph.scatter.js +4215 -171
  51. data/vendor/assets/javascripts/RGraph.segmented.js +1006 -0
  52. data/vendor/assets/javascripts/RGraph.semicircularprogress.js +1980 -59
  53. data/vendor/assets/javascripts/RGraph.svg.activity.js +1696 -0
  54. data/vendor/assets/javascripts/RGraph.svg.bar.js +2575 -77
  55. data/vendor/assets/javascripts/RGraph.svg.bipolar.js +3533 -106
  56. data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +240 -21
  57. data/vendor/assets/javascripts/RGraph.svg.common.core.js +7105 -299
  58. data/vendor/assets/javascripts/RGraph.svg.common.csv.js +408 -28
  59. data/vendor/assets/javascripts/RGraph.svg.common.fx.js +1291 -68
  60. data/vendor/assets/javascripts/RGraph.svg.common.key.js +451 -20
  61. data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +543 -31
  62. data/vendor/assets/javascripts/RGraph.svg.common.table.js +391 -0
  63. data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +1072 -23
  64. data/vendor/assets/javascripts/RGraph.svg.funnel.js +1151 -32
  65. data/vendor/assets/javascripts/RGraph.svg.gauge.js +1429 -34
  66. data/vendor/assets/javascripts/RGraph.svg.hbar.js +2692 -65
  67. data/vendor/assets/javascripts/RGraph.svg.horseshoe.js +969 -0
  68. data/vendor/assets/javascripts/RGraph.svg.line.js +2855 -86
  69. data/vendor/assets/javascripts/RGraph.svg.pie.js +1630 -58
  70. data/vendor/assets/javascripts/RGraph.svg.radar.js +1772 -58
  71. data/vendor/assets/javascripts/RGraph.svg.rose.js +2419 -83
  72. data/vendor/assets/javascripts/RGraph.svg.scatter.js +2280 -65
  73. data/vendor/assets/javascripts/RGraph.svg.segmented.js +930 -0
  74. data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +1612 -29
  75. data/vendor/assets/javascripts/RGraph.svg.waterfall.js +1525 -50
  76. data/vendor/assets/javascripts/RGraph.thermometer.js +1411 -64
  77. data/vendor/assets/javascripts/RGraph.vprogress.js +1915 -81
  78. data/vendor/assets/javascripts/RGraph.waterfall.js +1896 -89
  79. data/vendor/assets/javascripts/financial-data.js +1067 -0
  80. metadata +37 -16
  81. data/.travis.yml +0 -11
  82. data/vendor/assets/javascripts/RGraph.common.deprecated.js +0 -35
  83. data/vendor/assets/javascripts/RGraph.common.resizing.js +0 -38
  84. data/vendor/assets/javascripts/RGraph.common.zoom.js +0 -15
  85. data/vendor/assets/javascripts/RGraph.cornergauge.js +0 -71
@@ -1,33 +1,1434 @@
1
+ 'version:2023-09-16 (6.14)';
2
+ //
3
+ 'version:2023-07-17 (6.13)';
4
+ //
5
+ // o--------------------------------------------------------------------------------o
6
+ // | This file is part of the RGraph package - you can learn more at: |
7
+ // | |
8
+ // | https://www.rgraph.net |
9
+ // | |
10
+ // | RGraph is licensed under the Open Source MIT license. That means that it's |
11
+ // | totally free to use and there are no restrictions on what you can do with it! |
12
+ // o--------------------------------------------------------------------------------o
1
13
 
2
- RGraph=window.RGraph||{isRGraph:true};(function(win,doc,undefined)
3
- {var RG=RGraph,ua=navigator.userAgent,ma=Math;RG.tooltips={};RG.tooltips.style={display:'inline-block',position:'absolute',padding:'6px',fontFamily:'Arial',fontSize:'10pt',fontWeight:'normal',textAlign:'center',left:0,top:0,backgroundColor:'rgb(255,255,239)',color:'black',visibility:'visible',zIndex:3,borderRadius:'5px',boxShadow:'rgba(96,96,96,0.5) 0 0 5px',opacity:0,lineHeight:'initial'};RG.tooltip=RG.Tooltip=function(obj,text,x,y,idx,e)
4
- {if(RG.trim(text).length===0){return;}
5
- RG.fireCustomEvent(obj,'onbeforetooltip');if(typeof(obj.get('chart.tooltips.override'))=='function'){return obj.get('chart.tooltips.override')(obj,text,x,y,idx);}
6
- var originalX=x;var originalY=y;text=RG.getTooltipTextFromDIV(text);var timers=RG.Registry.get('chart.tooltip.timers');if(timers&&timers.length){for(i=0;i<timers.length;++i){clearTimeout(timers[i]);}}
7
- RG.Registry.Set('chart.tooltip.timers',[]);if(obj.get('chart.contextmenu')){RG.hideContext();}
8
- var tooltipObj=document.createElement('DIV');tooltipObj.className=obj.get('chart.tooltips.css.class');for(var i in RGraph.tooltips.style){if(typeof i==='string'){tooltipObj.style[i]=RGraph.tooltips.style[i];}}
9
- tooltipObj.innerHTML=text;tooltipObj.__text__=text;tooltipObj.__canvas__=obj.canvas;tooltipObj.id='__rgraph_tooltip_'+obj.canvas.id+'_'+obj.uid+'_'+idx;tooltipObj.__event__=obj.get('chart.tooltips.event')||'click';tooltipObj.__object__=obj;if(typeof idx==='number'){tooltipObj.__index__=idx;origIdx=idx;}
10
- if(obj.type==='line'||obj.type==='radar'){for(var ds=0;ds<obj.data.length;++ds){if(idx>=obj.data[ds].length){idx-=obj.data[ds].length;}else{break;}}
11
- tooltipObj.__dataset__=ds;tooltipObj.__index2__=idx;}
12
- document.body.appendChild(tooltipObj);var width=tooltipObj.offsetWidth;var height=tooltipObj.offsetHeight;tooltipObj.style.width=width+'px';var mouseXY=RG.getMouseXY(e);var canvasXY=RG.getCanvasXY(obj.canvas);tooltipObj.style.left=e.pageX-(parseFloat(tooltipObj.style.paddingLeft)+(width/2))+'px';tooltipObj.style.top=e.pageY-height-10+'px';if(parseFloat(tooltipObj.style.left)<=5){tooltipObj.style.left='5px';}
13
- if(parseFloat(tooltipObj.style.left)+parseFloat(tooltipObj.style.width)>window.innerWidth){tooltipObj.style.left=''
14
- tooltipObj.style.right='5px'}
15
- if(RG.isFixed(obj.canvas)){var scrollTop=window.scrollY||document.documentElement.scrollTop;tooltipObj.style.position='fixed';tooltipObj.style.top=e.pageY-scrollTop-height-10+'px';}
16
- if(obj.get('chart.tooltips.effect')==='fade'){for(var i=1;i<=10;++i){(function(index)
17
- {setTimeout(function()
18
- {tooltipObj.style.opacity=index/10;},index*25);})(i);}}else{tooltipObj.style.opacity=1;}
19
- tooltipObj.onmousedown=function(e){e.stopPropagation();}
20
- tooltipObj.onmouseup=function(e){e.stopPropagation();}
21
- tooltipObj.onclick=function(e){if(e.button==0){e.stopPropagation();}}
22
- RG.Registry.set('chart.tooltip',tooltipObj);RG.fireCustomEvent(obj,'ontooltip');};RG.getTooltipTextFromDIV=function(text)
23
- {var result=/^id:(.*)/.exec(text);if(result&&result[1]&&document.getElementById(result[1])){text=document.getElementById(result[1]).innerHTML;}else if(result&&result[1]){text='';}
24
- return text;};RG.getTooltipWidth=function(text,obj)
25
- {var div=document.createElement('DIV');div.className=obj.get('chart.tooltips.css.class');div.style.paddingLeft=RG.tooltips.padding;div.style.paddingRight=RG.tooltips.padding;div.style.fontFamily=RG.tooltips.font_face;div.style.fontSize=RG.tooltips.font_size;div.style.visibility='hidden';div.style.position='absolute';div.style.top='300px';div.style.left=0;div.style.display='inline';div.innerHTML=RG.getTooltipTextFromDIV(text);document.body.appendChild(div);return div.offsetWidth;};RG.hideTooltip=RG.HideTooltip=function()
26
- {var tooltip=RG.Registry.get('chart.tooltip');var uid=arguments[0]&&arguments[0].uid?arguments[0].uid:null;if(tooltip&&tooltip.parentNode&&(!uid||uid==tooltip.__canvas__.uid)){tooltip.parentNode.removeChild(tooltip);tooltip.style.display='none';tooltip.style.visibility='hidden';RG.Registry.Set('chart.tooltip',null);}};RG.preLoadTooltipImages=RG.PreLoadTooltipImages=function(obj)
27
- {var tooltips=obj.get('chart.tooltips');if(RG.hasTooltips(obj)){if(obj.type=='rscatter'){tooltips=[];for(var i=0;i<obj.data.length;++i){tooltips.push(obj.data[3]);}}
28
- for(var i=0;i<tooltips.length;++i){var div=document.createElement('DIV');div.style.position='absolute';div.style.opacity=0;div.style.top='-100px';div.style.left='-100px';div.innerHTML=tooltips[i];document.body.appendChild(div);var img_tags=div.getElementsByTagName('IMG');for(var j=0;j<img_tags.length;++j){if(img_tags&&img_tags[i]){var img=document.createElement('IMG');img.style.position='absolute';img.style.opacity=0;img.style.top='-100px';img.style.left='-100px';img.src=img_tags[i].src
29
- document.body.appendChild(img);setTimeout(function(){document.body.removeChild(img);},250);}}
30
- document.body.removeChild(div);}}};RG.tooltips_mousemove=RG.Tooltips_mousemove=function(obj,e)
31
- {var shape=obj.getShape(e);var changeCursor_tooltips=false
32
- if(shape&&typeof(shape['index'])=='number'&&obj.get('chart.tooltips')[shape['index']]){var text=RG.parseTooltipText(obj.get('chart.tooltips'),shape['index']);if(text){changeCursor_tooltips=true;if(obj.get('chart.tooltips.event')=='onmousemove'){if(!RG.Registry.get('chart.tooltip')||RG.Registry.get('chart.tooltip').__object__.uid!=obj.uid||RG.Registry.get('chart.tooltip').__index__!=shape['index']){RG.hideTooltip();RG.Clear(obj.canvas);RG.redraw();RG.tooltip(obj,text,e.pageX,e.pageY,shape['index']);obj.Highlight(shape);}}}}else if(shape&&typeof(shape['index'])=='number'){var text=RG.parseTooltipText(obj.get('chart.tooltips'),shape['index']);if(text){changeCursor_tooltips=true}}
33
- return changeCursor_tooltips;};})(window,document);
14
+ RGraph = window.RGraph || {isrgraph:true,isRGraph: true,rgraph:true};
15
+
16
+ // Module pattern
17
+ (function (win, doc, undefined)
18
+ {
19
+ var ua = navigator.userAgent;
20
+
21
+ //
22
+ // This is used in two functions, hence it's here
23
+ //
24
+ RGraph.tooltips = {};
25
+ RGraph.tooltips.css =
26
+ RGraph.tooltips.style = {
27
+ display: 'inline-block',
28
+ position: 'absolute',
29
+ padding: '6px',
30
+ fontFamily: 'Arial',
31
+ fontSize: '10pt',
32
+ fontWeight: 'normal',
33
+ textAlign: 'center',
34
+ left: 0,
35
+ top: 0,
36
+ backgroundColor: 'black',
37
+ color: 'white',
38
+ visibility: 'visible',
39
+ zIndex: 3,
40
+ borderRadius: '5px',
41
+ boxShadow: 'rgba(96,96,96,0.5) 0 0 5px',
42
+ opacity: 0,
43
+ lineHeight: RGraph.ISIE ? 'normal' : 'initial'
44
+ };
45
+
46
+
47
+
48
+ //
49
+ // Shows a tooltip next to the mouse pointer
50
+ //
51
+ // @param object object The canvas element object
52
+ // @param string text The tooltip text
53
+ // @param int x The X position that the tooltip should appear at. Combined with the canvases offsetLeft
54
+ // gives the absolute X position
55
+ // @param int y The Y position the tooltip should appear at. Combined with the canvases offsetTop
56
+ // gives the absolute Y position
57
+ // @param int index The index of the tooltip in the graph objects tooltip array
58
+ // @param object event The event object
59
+ //
60
+ RGraph.tooltip = function ()
61
+ {
62
+ var args = RGraph.getArgs(arguments, 'object,text,x,y,index,event');
63
+
64
+ // Set the CSS transition effect on the tooltips default
65
+ // object if the effect is set to slide
66
+ if (args.object.properties.tooltipsEffect === 'slide') {
67
+ RGraph.tooltips.style.transition = 'left ease-out .25s, top ease-out .25s'
68
+ }
69
+
70
+ if (RGraph.SHOW_TOOLTIP_TIMER) {
71
+ clearTimeout(RGraph.SHOW_TOOLTIP_TIMER);
72
+ }
73
+
74
+ if (RGraph.trim(args.text).length === 0) {
75
+ return;
76
+ }
77
+
78
+
79
+
80
+ //
81
+ // Fire the beforetooltip event
82
+ //
83
+ RGraph.fireCustomEvent(args.object, 'onbeforetooltip');
84
+
85
+
86
+
87
+ //
88
+ // tooltipOverride allows you to totally take control of rendering the tooltip yourself
89
+ //
90
+ if (typeof args.object.get('tooltipsOverride') == 'function') {
91
+ return args.object.get('tooltipsOverride')(
92
+ args.object,
93
+ args.text,
94
+ args.x,
95
+ args.y,
96
+ args.index
97
+ );
98
+ }
99
+
100
+
101
+
102
+
103
+ //
104
+ // Save the X/Y coords
105
+ //
106
+ var originalX = args.x;
107
+ var originalY = args.y;
108
+
109
+ //
110
+ // This facilitates the "id:xxx" format
111
+ //
112
+ args.text = RGraph.getTooltipTextFromDIV(args.text);
113
+
114
+ //
115
+ // First clear any exising timers
116
+ //
117
+ var timers = RGraph.Registry.get('tooltip.timers');
118
+
119
+ if (timers && timers.length) {
120
+ for (i=0; i<timers.length; ++i) {
121
+ clearTimeout(timers[i]);
122
+ }
123
+ }
124
+ RGraph.Registry.set('tooltip.timers', []);
125
+
126
+ //
127
+ // Hide the context menu if it's currently shown
128
+ //
129
+ if (args.object.get('contextmenu')) {
130
+ RGraph.hideContext();
131
+ }
132
+
133
+
134
+
135
+ //
136
+ // Show a tool tip
137
+ //
138
+ if (typeof args.object.get('tooltipsCssClass') !== 'string' ) {
139
+ args.object.set('tooltipsCssClass', 'RGraph_tooltip');
140
+ }
141
+
142
+ var tooltipObj = document.createElement('DIV');
143
+ tooltipObj.className = args.object.get('tooltipsCssClass');
144
+
145
+ // Add the default CSS to the tooltip
146
+ for (var i in RGraph.tooltips.style) {
147
+ if (typeof i === 'string') {
148
+ tooltipObj.style[i] = substitute(RGraph.tooltips.style[i]);
149
+ }
150
+ }
151
+
152
+ for (var i in RGraph.tooltips.css) {
153
+ if (typeof i === 'string') {
154
+ tooltipObj.style[i] = substitute(RGraph.tooltips.css[i]);
155
+ }
156
+ }
157
+
158
+ //
159
+ // If the tooltipsCss property is populated then add those values
160
+ // to the tooltip
161
+ //
162
+ if (!RGraph.isNull(args.object.properties.tooltipsCss)) {
163
+ for (var i in args.object.properties.tooltipsCss) {
164
+ if (typeof i === 'string') {
165
+ tooltipObj.style[i] = substitute(args.object.properties.tooltipsCss[i]);
166
+ }
167
+ }
168
+ }
169
+
170
+ // Set the initial values of the CSS left/top properties
171
+ // to the previously stored coordsof the left/top values
172
+ // (ie the last values of the previous tooltip). So when
173
+ // they're changed to the new values the transition will
174
+ // animate them
175
+ if (args.object.properties.tooltipsEffect === 'slide') {
176
+ tooltipObj.style.left = typeof RGraph.tooltip_slide_effect_previous_x_coordinate === 'string' ? RGraph.tooltip_slide_effect_previous_x_coordinate : 0;
177
+ tooltipObj.style.top = typeof RGraph.tooltip_slide_effect_previous_y_coordinate === 'string' ? RGraph.tooltip_slide_effect_previous_y_coordinate : 0;
178
+ }
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+ ///////////////////////////////////////
236
+ // Do tooltip text substitution here //
237
+ ///////////////////////////////////////
238
+ function substitute (original)
239
+ {
240
+ // Must be a string
241
+ original = String(original);
242
+
243
+ var prop = args.object.properties;
244
+ var properties = args.object.properties;
245
+
246
+ if (typeof args.object.tooltipSubstitutions !== 'function') {
247
+ return original;
248
+ }
249
+
250
+ //
251
+ // Get hold of the indexes from the sequentialIndex that we have.
252
+ //
253
+ if (typeof args.object.tooltipSubstitutions === 'function') {
254
+ var specific = args.object.tooltipSubstitutions({
255
+ index: args.index
256
+ });
257
+
258
+ }
259
+
260
+
261
+
262
+ // This allows for escaping the percent
263
+ var text = original.replace(/%%/g, '___--PERCENT--___');
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+ //
282
+ // Draws the key in the tooltip
283
+ //
284
+ (function ()
285
+ {
286
+ if (!specific.values) {
287
+ return;
288
+ }
289
+
290
+ //
291
+ // Allow the user to specify the key colors
292
+ //
293
+ var colors = properties.tooltipsFormattedKeyColors ? properties.tooltipsFormattedKeyColors : properties.colors;
294
+
295
+ // Build up the HTML table that becomes the key
296
+ for (var i=0,str=[]; i<specific.values.length; ++i) {
297
+
298
+ var value = (typeof specific.values === 'object' && typeof specific.values[i] === 'number') ? specific.values[i] : 0;
299
+ var color = properties.colorsSequential ? colors[args.index] : colors[i];
300
+ var label = ( (typeof properties.tooltipsFormattedKeyLabels === 'object' && typeof properties.tooltipsFormattedKeyLabels[i] === 'string') ? properties.tooltipsFormattedKeyLabels[i] : '');
301
+
302
+
303
+
304
+
305
+
306
+ // Chart specific customisations -------------------------
307
+ if (typeof args.object.tooltipsFormattedCustom === 'function') {
308
+
309
+ // The index/group/sequential index
310
+ // The index
311
+ // The colors
312
+ var ret = args.object.tooltipsFormattedCustom(
313
+ specific,
314
+ i,
315
+ colors
316
+ );
317
+
318
+ if (ret.continue ) {continue;};
319
+
320
+ if (typeof ret.label === 'string') {label = ret.label;};
321
+ if (ret.color) {color = ret.color;};
322
+ if (typeof ret.value === 'number') {value = ret.value;};
323
+ }
324
+
325
+
326
+
327
+
328
+ value = RGraph.numberFormat({
329
+ object: args.object,
330
+ number: value.toFixed(args.object.properties.tooltipsFormattedDecimals),
331
+ thousand: args.object.properties.tooltipsFormattedThousand || ',',
332
+ point: args.object.properties.tooltipsFormattedPoint || '.',
333
+ unitspre: args.object.properties.tooltipsFormattedUnitsPre || '',
334
+ unitspost: args.object.properties.tooltipsFormattedUnitsPost || ''
335
+ });
336
+
337
+
338
+
339
+ //
340
+ // If the tooltipsFormattedKeyColorsShape property is set to circle then add
341
+ // some border-radius to the DIV tag
342
+ //
343
+ var borderRadius = 0;
344
+
345
+ if ( typeof args.object.properties.tooltipsFormattedKeyColorsShape === 'string'
346
+ && args.object.properties.tooltipsFormattedKeyColorsShape === 'circle') {
347
+
348
+ borderRadius = '100px';
349
+ }
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+ str[i] = '<tr><td><div id="RGraph_tooltipsFormattedKeyColor_' + i + '" class="RGraph_tooltipsFormattedKeyColor" style="color: transparent">Ml</div></td><td id="RGraph_tooltipsFormattedKeyLabel_' + i + '">'
359
+ + '<span>{1}</span>'.format(label)
360
+ + ' ' + value + '</td></tr>';
361
+
362
+
363
+ // Now that styles can't be applied inline
364
+ // (due to the CSP header) then apply them with
365
+ // JavaScript after a small delay.
366
+ (function (index, color, borderRadius)
367
+ {
368
+ setTimeout(function ()
369
+ {
370
+ var obj = document.getElementById('RGraph_tooltipsFormattedKeyLabel_' + index);
371
+
372
+ // Align the label left
373
+ if (obj && obj.style) {
374
+ obj.style.textAlign = 'left';
375
+ }
376
+
377
+ // Add some styles to the color blob
378
+ var colorBlob = document.getElementById('RGraph_tooltipsFormattedKeyColor_' + index);
379
+
380
+ if (colorBlob) {
381
+ colorBlob.style.textAlign = 'left';
382
+ colorBlob.style.backgroundColor = color;
383
+ colorBlob.style.color = 'transparent';
384
+ colorBlob.style.pointerEvents = 'none';
385
+ colorBlob.style.borderRadius = borderRadius;
386
+ }
387
+
388
+ // Add user specified styles from the
389
+ // tooltipsFormattedKeyColorsCss property
390
+ for (var property in properties.tooltipsFormattedKeyColorsCss) {
391
+ if (typeof property === 'string') {
392
+ colorBlob.style[property] = properties.tooltipsFormattedKeyColorsCss[property];
393
+ }
394
+ }
395
+ }, 5);
396
+ })(i, color, borderRadius);
397
+ }
398
+ str = str.join('');
399
+
400
+ // Add the key to the tooltip text - replacing the placeholder
401
+ text = text.replace('%{key}', '<table id="rgraph_tooltip_key" class="rgraph_tooltip_key RGraph_tooltip_key">' + str + '</table>');
402
+ setTimeout(function ()
403
+ {
404
+ var obj = document.getElementById('rgraph_tooltip_key');
405
+
406
+ if (obj && obj.style) {
407
+ obj.style.color = 'inherit';
408
+ }
409
+ }, 1);
410
+ })();
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+ // Replace the index of the tooltip
423
+ text = text.replace(/%{index}/g, specific.index);
424
+
425
+ // Replace the dataset/group of the tooltip
426
+ text = text.replace(/%{dataset2}/g, specific.dataset2); // Used by the Bipolar
427
+ text = text.replace(/%{dataset}/g, specific.dataset);
428
+ text = text.replace(/%{group2}/g, specific.dataset2);
429
+ text = text.replace(/%{group}/g, specific.dataset);
430
+
431
+ // Replace the sequentialIndex of the tooltip
432
+ text = text.replace(/%{sequential_index}/g, specific.sequentialIndex);
433
+ text = text.replace(/%{seq}/g, specific.sequentialIndex);
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+ //Do %{list} substitution
449
+ if (text.indexOf('%{list}') !== -1) {
450
+ (function ()
451
+ {
452
+ if (properties.tooltipsFormattedListType === 'unordered') properties.tooltipsFormattedListType = 'ul';
453
+ if (properties.tooltipsFormattedListType === '<ul>') properties.tooltipsFormattedListType = 'ul';
454
+ if (properties.tooltipsFormattedListType === 'ordered') properties.tooltipsFormattedListType = 'ol';
455
+ if (properties.tooltipsFormattedListType === '<ol>') properties.tooltipsFormattedListType = 'ol';
456
+
457
+ var str = properties.tooltipsFormattedListType === 'ol' ? '<ol id="rgraph_formatted_tooltips_list">' : '<ul id="rgraph_formatted_tooltips_list">';
458
+ var items = properties.tooltipsFormattedListItems[specific.sequentialIndex];
459
+
460
+ if (items && items.length) {
461
+ for (var i=0; i<items.length; ++i) {
462
+ str += '<li>' + items[i] + '</li>';
463
+ }
464
+ }
465
+
466
+ str += properties.tooltipsFormattedListType === 'ol' ? '</ol>' : '</ul>';
467
+
468
+ // Add the list to the tooltip
469
+ text = text.replace(/%{list}/, str);
470
+
471
+ })();
472
+ }
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+ // Do table substitution (ie %{table} )
490
+ if (text.indexOf('%{table}') !== -1) {
491
+ (function ()
492
+ {
493
+ var str = '<table>';
494
+
495
+ // Add the headers if they're defined
496
+ if (properties.tooltipsFormattedTableHeaders && properties.tooltipsFormattedTableHeaders.length) {
497
+ str += '<thead><tr>';
498
+ for (var i=0; i<properties.tooltipsFormattedTableHeaders.length; ++i) {
499
+ str += '<th>' + properties.tooltipsFormattedTableHeaders[i] + '</th>';
500
+ }
501
+ str += '</tr></thead>';
502
+ }
503
+
504
+
505
+
506
+
507
+
508
+ // Add each row of data
509
+ if (typeof properties.tooltipsFormattedTableData === 'object' && !RGraph.isNull(properties.tooltipsFormattedTableData)) {
510
+ str += '<tbody>';
511
+
512
+ for (var i=0; i<properties.tooltipsFormattedTableData[specific.sequentialIndex].length; ++i) {
513
+ str += '<tr>';
514
+ for (var j=0; j<properties.tooltipsFormattedTableData[specific.sequentialIndex][i].length; ++j) {
515
+ str += '<td>' + String(properties.tooltipsFormattedTableData[specific.sequentialIndex][i][j]) + '</td>';
516
+ }
517
+ str += '</tr>';
518
+ }
519
+
520
+ str += '</tbody>';
521
+ }
522
+
523
+ // Close the table
524
+ str += '</table>';
525
+
526
+ text = text.replace(/%{table}/g, str);
527
+ })();
528
+ }
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+ // Do property substitution when there's an index to the property
543
+ var reg = /%{p(?:rop)?(?:erty)?:([_a-z0-9]+)\[([0-9]+)\]}/i;
544
+
545
+ while (text.match(reg)) {
546
+
547
+ var property = RegExp.$1;
548
+ var index = parseInt(RegExp.$2);
549
+
550
+ if (args.object.properties[property]) {
551
+ text = text.replace(
552
+ reg,
553
+ args.object.properties[property][index] || ''
554
+ );
555
+
556
+ // Get rid of the text
557
+ } else {
558
+ text = text.replace(reg,'');
559
+ }
560
+
561
+ RegExp.lastIndex = null;
562
+ }
563
+
564
+
565
+
566
+
567
+ // Replace this: %{property:xxx}
568
+ while (text.match(/%{property:([_a-z0-9]+)}/i)) {
569
+ var str = '%{property:' + RegExp.$1 + '}';
570
+ text = text.replace(str, args.object.properties[RegExp.$1]);
571
+ }
572
+
573
+
574
+
575
+
576
+ // Replace this: %{prop:xxx}
577
+ while (text.match(/%{prop:([_a-z0-9]+)}/i)) {
578
+ var str = '%{prop:' + RegExp.$1 + '}';
579
+ text = text.replace(str, args.object.properties[RegExp.$1]);
580
+ }
581
+
582
+
583
+
584
+
585
+ // Replace this: %{prop:xxx}
586
+ while (text.match(/%{p:([_a-z0-9]+)}/i)) {
587
+ var str = '%{p:' + RegExp.$1 + '}';
588
+ text = text.replace(str, args.object.properties[RegExp.$1]);
589
+ }
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+ // THIS IS ONLY FOR A NON-EQUI-ANGULAR ROSE CHART
600
+ //
601
+ // Replace this: %{value2}
602
+ if (args.object.type === 'rose' && args.object.properties.variant === 'non-equi-angular') {
603
+ while (text.match(/%{value2}/i)) {
604
+ text = text.replace('%{value2}', specific.value2);
605
+ }
606
+ }
607
+
608
+
609
+
610
+
611
+ // Replace this: %{value} and this: %{value_formatted}
612
+ while (text.match(/%{value(?:_formatted)?}/i)) {
613
+
614
+ var value = specific.value;
615
+
616
+ if (text.match(/%{value_formatted}/i)) {
617
+ text = text.replace(
618
+ '%{value_formatted}',
619
+ typeof value === 'number' ? RGraph.numberFormat({
620
+ object: args.object,
621
+ number: value.toFixed(args.object.properties.tooltipsFormattedDecimals),
622
+ thousand: args.object.properties.tooltipsFormattedThousand || ',',
623
+ point: args.object.properties.tooltipsFormattedPoint || '.',
624
+ unitspre: args.object.properties.tooltipsFormattedUnitsPre || '',
625
+ unitspost: args.object.properties.tooltipsFormattedUnitsPost || ''
626
+ }) : null
627
+ );
628
+ } else {
629
+ text = text.replace('%{value}', value);
630
+ }
631
+ }
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+ ////////////////////////////////////////////////////////////////
642
+ // Do global substitution when there's an index to the global //
643
+ ////////////////////////////////////////////////////////////////
644
+ var reg = /%{global:([_a-z0-9.]+)\[([0-9]+)\]}/i;
645
+
646
+ while (text.match(reg)) {
647
+
648
+ var name = RegExp.$1,
649
+ index = parseInt(RegExp.$2);
650
+
651
+ if (eval(name)) {
652
+ text = text.replace(
653
+ reg,
654
+ eval(name)[index] || ''
655
+ );
656
+
657
+ // Get rid of the text if there was nothing to replace the template bit with
658
+ } else {
659
+ text = text.replace(reg,'');
660
+ }
661
+
662
+ RegExp.lastIndex = null;
663
+ }
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+ //////////////////////////////////////////////////
681
+ // Do global substitution when there's no index //
682
+ //////////////////////////////////////////////////
683
+ var reg = /%{global:([_a-z0-9.]+)}/i;
684
+
685
+ while (text.match(reg)) {
686
+
687
+ var name = RegExp.$1;
688
+
689
+ if (eval(name)) {
690
+ text = text.replace(
691
+ reg,
692
+ eval(name) || ''
693
+ );
694
+
695
+ // Get rid of the text if there was nothing to replace the template bit with
696
+ } else {
697
+ text = text.replace(reg,'');
698
+ }
699
+
700
+ RegExp.lastIndex = null;
701
+ }
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+ // Call any functions
713
+ var regexp = /%{function:([_A-Za-z0-9]+)\((.*?)\)}/;
714
+
715
+ // Temporarily replace carriage returns and line feeds with CR and LF
716
+ // so the the s option is not needed
717
+ text = text.replace(/\r/,'|CR|');
718
+ text = text.replace(/\n/,'|LF|');
719
+
720
+ while (text.match(regexp)) {
721
+
722
+ var str = RegExp.$1 + '(' + RegExp.$2 + ')';
723
+
724
+ for (var i=0,len=str.length; i<len; ++i) {
725
+ str = str.replace(/\r?\n/, "\\n");
726
+ }
727
+
728
+ RGraph.Registry.set('tooltip-templates-function-object', args.object);
729
+
730
+ var func = new Function ('return ' + str);
731
+ var ret = func();
732
+
733
+ text = text.replace(regexp, ret)
734
+ }
735
+
736
+
737
+
738
+
739
+
740
+
741
+ // Do color blob replacement
742
+ text = text.replace(/%{color\:([^}]+)}/g, '<div style="display: inline-block; background-color: $1; scale: 0.9;color: transparent">Mj</div>');
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+ // Replace CR and LF with a space
754
+ text = text.replace(/\|CR\|/, ' ');
755
+ text = text.replace(/\|LF\|/, ' ');
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+ // Replace line returns with br tags
765
+ text = text.replace(/\r?\n/g, '<br />');
766
+ text = text.replace(/___--PERCENT--___/g, '%')
767
+
768
+
769
+ return text.toString();
770
+ }
771
+ // Save the original text on the tooltip
772
+ tooltipObj.__original_text__ = args.text;
773
+
774
+ args.text = substitute(args.text);
775
+
776
+
777
+ // Add the pointer if requested. The background color is updated to match the
778
+ // tooltip further down.
779
+ if (args.object.properties.tooltipsPointer) {
780
+
781
+ // Styles are applied to the pointer below to
782
+ // circumvent a Content-Security-Policy header
783
+ // problem
784
+ args.text += '<div id="RGraph_tooltipsPointer"></div>';
785
+
786
+
787
+
788
+ //
789
+ // If the tooltipsPointerCss property is populated then do the
790
+ // substitution on those too
791
+ //
792
+ if (!RGraph.isNull(args.object.properties.tooltipsPointerCss)) {
793
+
794
+ // This is in a timer to allow the tooltip (and the pointer) to be
795
+ // added to the document. Then the document.getElementById('') method
796
+ // will be able to retrieve it
797
+ setTimeout(function ()
798
+ {
799
+ var pointerObj = document.getElementById('RGraph_tooltipsPointer');
800
+
801
+ for (var i in args.object.properties.tooltipsPointerCss) {
802
+ if (typeof i === 'string') {
803
+ pointerObj.style[i] = substitute(args.object.properties.tooltipsPointerCss[i]);
804
+ }
805
+ }
806
+ }, 50);
807
+ }
808
+ }
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+
856
+
857
+
858
+
859
+
860
+
861
+
862
+
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+ tooltipObj.innerHTML = args.text;
880
+ tooltipObj.__text__ = args.text; // This is set because the innerHTML can change when it's set
881
+ tooltipObj.__canvas__ = args.object.canvas;
882
+ tooltipObj.__event__ = args.object.get('tooltipsEvent') || 'click';
883
+ tooltipObj.__object__ = args.object;
884
+ tooltipObj.id = '__rgraph_tooltip_' + args.object.canvas.id + '_' + args.object.uid + '_'+ args.index;
885
+
886
+
887
+
888
+ // Set styles on the pointer. It's done this way
889
+ // (not adding the style to the HTML above) to
890
+ // prevent an error bein thrown should a
891
+ // Content-Security-Policy header using style-src
892
+ // be in place
893
+ setTimeout(function ()
894
+ {
895
+ var pointerObj = document.getElementById('RGraph_tooltipsPointer');
896
+ var styles = window.getComputedStyle(tooltipObj, false);
897
+
898
+ if (pointerObj) {
899
+ pointerObj.style.backgroundColor = styles.backgroundColor;
900
+ pointerObj.style.color = 'transparent';
901
+ pointerObj.style.position = 'absolute';
902
+ pointerObj.style.bottom = -5 + (RGraph.isNumber(args.object.properties.tooltipsPointerOffsety) ? args.object.properties.tooltipsPointerOffsety : 0) + 'px';
903
+ pointerObj.style.left = 'calc(50% + ' + (RGraph.isNumber(args.object.properties.tooltipsPointerOffsetx) ? args.object.properties.tooltipsPointerOffsetx : 0) + 'px )';
904
+ pointerObj.style.transform = 'translateX(-50%) rotate(45deg)';
905
+ pointerObj.style.width = '10px';
906
+ pointerObj.style.height = '10px';
907
+ }
908
+ }, 16.666);
909
+
910
+ if (typeof args.index === 'number') {
911
+ tooltipObj.__index__ = args.index;
912
+ origIdx = args.index;
913
+ }
914
+
915
+ if (args.object.type === 'line' || args.object.type === 'radar') {
916
+ for (var ds=0; ds<args.object.data.length; ++ds) {
917
+ if (args.index >= args.object.data[ds].length) {
918
+ args.index -= args.object.data[ds].length;
919
+ } else {
920
+ break;
921
+ }
922
+ }
923
+
924
+ tooltipObj.__dataset__ = ds;
925
+ tooltipObj.__index2__ = args.index;
926
+ }
927
+
928
+ document.body.appendChild(tooltipObj);
929
+
930
+ var width = tooltipObj.offsetWidth;
931
+ var height = tooltipObj.offsetHeight;
932
+
933
+
934
+ //
935
+ // Set the width on the tooltip so it doesn't resize if the
936
+ // window is resized
937
+ //
938
+ tooltipObj.style.width = width + 'px';
939
+
940
+
941
+
942
+
943
+ //
944
+ // Now that the tooltip pointer has been added, determine the background-color and update
945
+ // the color of the pointer
946
+ if (args.object.properties.tooltipsPointer) {
947
+
948
+ var styles = window.getComputedStyle(tooltipObj, false);
949
+ var pointer = document.getElementById('RGraph_tooltipsPointer');
950
+
951
+ pointer.style.backgroundColor = styles['background-color'];
952
+
953
+ // Add the pointer to the tooltip as a property
954
+ tooltipObj.__pointer__ = pointer;
955
+
956
+ // Facilitate the property that allows CSS to be added to
957
+ // the tooltip key color blob
958
+ var tooltipsPointerCss = '';
959
+
960
+ if (args.object.properties.tooltipsPointerCss) {
961
+
962
+ var pointerDiv = document.getElementById('RGraph_tooltipsPointer');
963
+
964
+ for(property in args.object.properties.tooltipsPointerCss) {
965
+ if (typeof property === 'string') {
966
+ pointerDiv.style[property] = args.object.properties.tooltipsPointerCss[property];
967
+ }
968
+ }
969
+ }
970
+ }
971
+
972
+
973
+
974
+
975
+ //
976
+ // position the tooltip on the mouse pointers position
977
+ //
978
+ var mouseXY = RGraph.getMouseXY(args.event);
979
+ var canvasXY = RGraph.getCanvasXY(args.object.canvas);
980
+
981
+ // Set these properties to 0 (ie an integer) in case chart libraries are missing
982
+ // default values for them
983
+ args.object.properties.tooltipsOffsetx = args.object.properties.tooltipsOffsetx || 0;
984
+ args.object.properties.tooltipsOffsety = args.object.properties.tooltipsOffsety || 0;
985
+
986
+ // Position based on the mouse pointer coords on the page
987
+ tooltipObj.style.left = args.event.pageX - (parseFloat(tooltipObj.style.paddingLeft) + (width / 2)) + args.object.properties.tooltipsOffsetx + 'px';
988
+ tooltipObj.style.top = args.event.pageY - height - 10 + args.object.properties.tooltipsOffsety + 'px';
989
+
990
+ // If the left is less than zero - set it to 5
991
+ if (parseFloat(tooltipObj.style.left) <= 5) {
992
+ tooltipObj.style.left = 5 + args.object.properties.tooltipsOffsetx + 'px';
993
+ }
994
+
995
+ // If the top is less than zero - set it to 5
996
+ if (parseFloat(tooltipObj.style.top) <= 5) {
997
+ tooltipObj.style.top = 5 + args.object.properties.tooltipsOffsety + 'px';
998
+ }
999
+
1000
+ // If the tooltip goes over the right hand edge then
1001
+ // adjust the positioning
1002
+ if (parseFloat(tooltipObj.style.left) + parseFloat(tooltipObj.style.width) > window.innerWidth) {
1003
+ tooltipObj.style.left = '';
1004
+ tooltipObj.style.right = 5 + args.object.properties.tooltipsOffsetx + 'px';
1005
+ }
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+ //
1019
+ // Allow for static positioning.
1020
+ //
1021
+ if (args.object.properties.tooltipsPositionStatic && typeof args.object.positionTooltipStatic === 'function') {
1022
+
1023
+ args.object.positionTooltipStatic({
1024
+ object: args.object,
1025
+ event: args.event,
1026
+ tooltip: tooltipObj,
1027
+ index: origIdx
1028
+ });
1029
+ }
1030
+
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+ //
1047
+ // Move the tooltip and its pointer if they're off-screen LHS
1048
+ //
1049
+ if (parseInt(tooltipObj.style.left) < 0) {
1050
+
1051
+ var left = parseInt(tooltipObj.style.left);
1052
+ var width = parseInt(tooltipObj.style.width)
1053
+
1054
+ left = left + (width * 0.1 * 4);
1055
+
1056
+ tooltipObj.style.left = left + 'px';
1057
+ var pointer = document.getElementById('RGraph_tooltipsPointer');
1058
+
1059
+ (function (pointer)
1060
+ {
1061
+ setTimeout(function ()
1062
+ {
1063
+ if (pointer) {
1064
+ pointer.style.left = 'calc(10% + ' + (5 + (typeof args.object.properties.tooltipsPointerOffsetx === 'number' ? args.object.properties.tooltipsPointerOffsetx : 0)) + 'px)';
1065
+ //pointer.style.left = 'calc(10% + 5px)';
1066
+ }
1067
+ }, 25);
1068
+ })(pointer)
1069
+
1070
+ //
1071
+ // Move the tooltip and its pointer if they're off-screen RHS
1072
+ //
1073
+ //NB but only if the LHS checking was negative
1074
+ //
1075
+ } else if ( (parseInt(tooltipObj.style.left) + parseInt(tooltipObj.offsetWidth)) > document.body.offsetWidth) {
1076
+ var left = parseInt(tooltipObj.style.left);
1077
+ var width = parseInt(tooltipObj.style.width)
1078
+
1079
+ left = left - (width * 0.1 * 4);
1080
+
1081
+ tooltipObj.style.left = left + 'px';
1082
+ var pointer = document.getElementById('RGraph_tooltipsPointer');
1083
+
1084
+ (function (pointer)
1085
+ {
1086
+ setTimeout(function ()
1087
+ {
1088
+ if (pointer) {
1089
+ pointer.style.left = 'calc(90% - ' + (5 + (typeof args.object.properties.tooltipsPointerOffsetx === 'number' ? args.object.properties.tooltipsPointerOffsetx : 0)) + 'px)';
1090
+ //pointer.style.left = 'calc(90% - 5px)';
1091
+ }
1092
+ }, 25)
1093
+ })(pointer);
1094
+ }
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+ // If the canvas has fixed positioning then set the tooltip position to
1116
+ // fixed too
1117
+ if (RGraph.isFixed(args.object.canvas)) {
1118
+ tooltipObj.style.position = 'fixed';
1119
+ }
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+ // If the effect is fade:
1127
+ // Increase the opacity from its default 0 up to 1 - fading the tooltip in
1128
+ if (args.object.get('tooltipsEffect') === 'fade') {
1129
+ //setTimeout(function ()
1130
+ //{
1131
+ for (var i=1; i<=10; ++i) {
1132
+ (function (index)
1133
+ {
1134
+ setTimeout(function ()
1135
+ {
1136
+ tooltipObj.style.opacity = index / 10;
1137
+ }, index * 25);
1138
+ })(i);
1139
+ }
1140
+ //}, 1000)
1141
+ } else {
1142
+ tooltipObj.style.opacity = 1;
1143
+ }
1144
+
1145
+
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+ //
1156
+ // If the tooltip itself is clicked, cancel it
1157
+ //
1158
+ tooltipObj.onmousedown = function (e){e.stopPropagation();}
1159
+ tooltipObj.onmouseup = function (e){e.stopPropagation();}
1160
+ tooltipObj.onclick = function (e){if (e.button == 0) {e.stopPropagation();}}
1161
+
1162
+ // If the window is resized then hide the tooltip
1163
+ window.addEventListener('resize', function ()
1164
+ {
1165
+ if (tooltipObj) {
1166
+ RGraph.hideTooltip();
1167
+ RGraph.redrawCanvas(args.object.canvas);
1168
+ }
1169
+ });
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+ //
1178
+ // Keep a reference to the tooltip in the registry
1179
+ //
1180
+ RGraph.Registry.set('tooltip', tooltipObj);
1181
+
1182
+ //
1183
+ // Store the final X/Y coordinates so that sliding works
1184
+ //
1185
+ if (args.object.properties.tooltipsEffect === 'slide') {
1186
+ RGraph.tooltip_slide_effect_previous_x_coordinate = tooltipObj.style.left;
1187
+ RGraph.tooltip_slide_effect_previous_y_coordinate = tooltipObj.style.top;
1188
+ }
1189
+
1190
+ //
1191
+ // Fire the tooltip event
1192
+ //
1193
+ RGraph.fireCustomEvent(args.object, 'ontooltip');
1194
+ };
1195
+
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+
1203
+ //
1204
+ //
1205
+ //
1206
+ RGraph.getTooltipTextFromDIV = function ()
1207
+ {
1208
+ var args = RGraph.getArgs(arguments, 'text');
1209
+
1210
+ // This regex is duplicated firher down on roughly line 888
1211
+ var result = /^id:(.*)/.exec(args.text);
1212
+
1213
+ if (result && result[1] && document.getElementById(result[1])) {
1214
+ args.text = document.getElementById(result[1]).innerHTML;
1215
+ } else if (result && result[1]) {
1216
+ args.text = '';
1217
+ }
1218
+
1219
+ return args.text;
1220
+ };
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+ //
1230
+ // Get the width that is set on the tooltip DIV based on the text
1231
+ // that has been given
1232
+ //
1233
+ RGraph.getTooltipWidth = function ()
1234
+ {
1235
+ var args = RGraph.getArgs(arguments, 'text,object');
1236
+
1237
+ var div = document.createElement('DIV');
1238
+ div.className = args.object.get('tooltipsCssClass');
1239
+ div.style.paddingLeft = RGraph.tooltips.padding;
1240
+ div.style.paddingRight = RGraph.tooltips.padding;
1241
+ div.style.fontFamily = RGraph.tooltips.font_face;
1242
+ div.style.fontSize = RGraph.tooltips.font_size;
1243
+ div.style.visibility = 'hidden';
1244
+ div.style.position = 'absolute';
1245
+ div.style.top = '300px';
1246
+ div.style.left = 0;
1247
+ div.style.display = 'inline';
1248
+ div.innerHTML = RGraph.getTooltipTextFromDIV(args.text);
1249
+ document.body.appendChild(div);
1250
+
1251
+ return div.offsetWidth;
1252
+ };
1253
+
1254
+
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+ //
1262
+ // Hides the currently shown tooltip
1263
+ //
1264
+ RGraph.hideTooltip = function ()
1265
+ {
1266
+ var tooltip = RGraph.Registry.get('tooltip');
1267
+ var uid = arguments[0] && arguments[0].uid ? arguments[0].uid : null;
1268
+
1269
+ if (tooltip && tooltip.parentNode && (!uid || uid == tooltip.__canvas__.uid)) {
1270
+
1271
+ // Delete references, that were put there by RGraph,
1272
+ // from the tooltip
1273
+ for (var v of ['__canvas__', '__event__', '__index__', '__object__','__original_text__','__shape__','__text__']) {
1274
+ if (typeof tooltip[v] !== 'undefined') {
1275
+ delete tooltip[v];
1276
+ }
1277
+ }
1278
+
1279
+ // Delete references, that were put there by RGraph,
1280
+ // from the tooltip (that start with "rgraph_"
1281
+ for (i in tooltip) {
1282
+ if (i.substr(0,7) === 'rgraph_') {
1283
+ delete tooltip[i];
1284
+ }
1285
+ }
1286
+
1287
+ tooltip.parentNode.removeChild(tooltip);
1288
+ tooltip.style.display = 'none';
1289
+ tooltip.style.visibility = 'hidden';
1290
+ RGraph.Registry.set('tooltip', null);
1291
+ }
1292
+ };
1293
+
1294
+
1295
+
1296
+
1297
+ //
1298
+ // This (as the name suggests preloads any images it can find in the tooltip text
1299
+ //
1300
+ // @param object obj The chart object
1301
+ //
1302
+ RGraph.preLoadTooltipImages = function ()
1303
+ {
1304
+ var args = RGraph.getArgs(arguments, 'object');
1305
+
1306
+ var tooltips = args.object.get('tooltips');
1307
+
1308
+ if (RGraph.hasTooltips(args.object)) {
1309
+
1310
+ if (args.object.type == 'rscatter') {
1311
+ tooltips = [];
1312
+ for (var i=0; i<args.object.data.length; ++i) {
1313
+ tooltips.push(args.object.data[3]);
1314
+ }
1315
+ }
1316
+
1317
+ for (var i=0; i<tooltips.length; ++i) {
1318
+ // Add the text to an offscreen DIV tag
1319
+ var div = document.createElement('div');
1320
+ div.style.position = 'absolute';
1321
+ div.style.opacity = 0;
1322
+ div.style.top = '-100px';
1323
+ div.style.left = '-100px';
1324
+ div.innerHTML = tooltips[i];
1325
+ document.body.appendChild(div);
1326
+
1327
+ // Now get the IMG tags and create them
1328
+ var img_tags = div.getElementsByTagName('IMG');
1329
+
1330
+ // Create the image in an off-screen image tag
1331
+ for (var j=0; j<img_tags.length; ++j) {
1332
+ if (img_tags && img_tags[i]) {
1333
+ var img = document.createElement('img');
1334
+ img.style.position = 'absolute';
1335
+ img.style.opacity = 0;
1336
+ img.style.top = '-100px';
1337
+ img.style.left = '-100px';
1338
+ img.src = img_tags[i].src
1339
+ document.body.appendChild(img);
1340
+
1341
+ setTimeout(function () {document.body.removeChild(img);}, 250);
1342
+ }
1343
+ }
1344
+
1345
+ // Now remove the div
1346
+ document.body.removeChild(div);
1347
+ }
1348
+ }
1349
+ };
1350
+
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1358
+ //
1359
+ // This is the tooltips canvas onmousemove listener
1360
+ //
1361
+ RGraph.tooltips_mousemove = function ()
1362
+ {
1363
+ var args = RGraph.getArgs(arguments, 'object,event'),
1364
+ shape = args.object.getShape(args.event),
1365
+ changeCursor_tooltips = false
1366
+
1367
+ if ( shape
1368
+ && typeof shape.index === 'number'
1369
+ && args.object.get('tooltips')[shape.index]
1370
+ ) {
1371
+
1372
+ var text = RGraph.parseTooltipText(
1373
+ args.object.get('tooltips'),
1374
+ shape.index
1375
+ );
1376
+
1377
+ if (text) {
1378
+
1379
+ //
1380
+ // Change the cursor
1381
+ //
1382
+ changeCursor_tooltips = true;
1383
+
1384
+ if (args.object.get('tooltipsEvent') === 'onmousemove') {
1385
+
1386
+ // Show the tooltip if it's not the same as the one already visible
1387
+ if (
1388
+ !RGraph.Registry.get('tooltip')
1389
+ || RGraph.Registry.get('tooltip').__object__.uid != args.object.uid
1390
+ || RGraph.Registry.get('tooltip').__index__ != shape.index
1391
+ ) {
1392
+
1393
+ RGraph.hideTooltip();
1394
+ RGraph.clear(args.object.canvas);
1395
+ RGraph.redraw();
1396
+ RGraph.tooltip(
1397
+ args.object,
1398
+ text,
1399
+ args.event.pageX,
1400
+ args.event.pageY,
1401
+ shape.index
1402
+ );
1403
+ args.object.highlight(shape);
1404
+ }
1405
+ }
1406
+ }
1407
+
1408
+ //
1409
+ // More highlighting
1410
+ //
1411
+ } else if (shape && typeof shape.index === 'number') {
1412
+
1413
+ var text = RGraph.parseTooltipText(
1414
+ args.object.get('tooltips'),
1415
+ shape.index
1416
+ );
1417
+
1418
+ if (text) {
1419
+ changeCursor_tooltips = true
1420
+ }
1421
+ }
1422
+
1423
+ return changeCursor_tooltips;
1424
+ };
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+
1432
+
1433
+ // End module pattern
1434
+ })(window, document);