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,36 +1,415 @@
1
+ 'version:2023-09-16 (6.14)';
2
+ //
3
+ // o--------------------------------------------------------------------------------o
4
+ // | This file is part of the RGraph package - you can learn more at: |
5
+ // | |
6
+ // | https://www.rgraph.net |
7
+ // | |
8
+ // | RGraph is licensed under the Open Source MIT license. That means that it's |
9
+ // | totally free to use and there are no restrictions on what you can do with it! |
10
+ // o--------------------------------------------------------------------------------o
1
11
 
2
- RGraph=window.RGraph||{isRGraph:true};(function(win,doc,undefined)
3
- {var RG=RGraph,ua=navigator.userAgent,ma=Math;RG.annotating_canvas_onmousedown=function(e)
4
- {if(e.button===0){e.target.__object__.set('chart.mousedown',true);var obj=e.target.__object__,prop=obj.properties
5
- obj.context.beginPath();obj.context.strokeStyle=obj.get('chart.annotatable.color');obj.context.lineWidth=obj.get('chart.annotatable.linewidth');var mouseXY=RG.getMouseXY(e),mouseX=mouseXY[0],mouseY=mouseXY[1]
6
- if(obj.type==='bar'&&prop['chart.variant']==='3d'){var adjustment=prop['chart.variant.threed.angle']*mouseXY[0];mouseY-=adjustment;}
7
- RG.Registry.set('annotatable.actions',[obj.get('chart.annotatable.color')]);obj.context.moveTo(mouseX,mouseY);RG.Registry.set('annotatable.last.coordinates',[mouseX,mouseY]);RG.Registry.set('started.annotating',false);RG.Registry.set('chart.annotating',obj);RG.FireCustomEvent(obj,'onannotatebegin');}
8
- return false;};RG.annotating_window_onmouseup=function(e)
9
- {var obj=RG.Registry.get('chart.annotating');var win=window;if(e.button!=0||!obj){return;}
10
- var tags=doc.getElementsByTagName('canvas');for(var i=0;i<tags.length;++i){if(tags[i].__object__){tags[i].__object__.set('chart.mousedown',false);}}
11
- if(RG.Registry.get('annotatable.actions')&&RG.Registry.get('annotatable.actions').length>0&&win.localStorage){var id='__rgraph_annotations_'+e.target.id+'__';var annotations=win.localStorage[id]?win.localStorage[id]+'|':'';annotations+=RG.Registry.get('annotatable.actions');win.localStorage[id]=annotations;}
12
- RG.Registry.set('annotatable.actions',[]);RG.FireCustomEvent(obj,'onannotateend');};RGraph.annotating_canvas_onmousemove=function(e)
13
- {var obj=e.target.__object__;var prop=obj.properties;var mouseXY=RG.getMouseXY(e);var mouseX=mouseXY[0];var mouseY=mouseXY[1];var lastXY=RG.Registry.get('annotatable.last.coordinates');if(obj.get('chart.mousedown')){if(obj.type==='bar'&&prop['chart.variant']==='3d'){var adjustment=prop['chart.variant.threed.angle']*mouseXY[0];mouseY-=adjustment;}
14
- obj.context.beginPath();if(!lastXY){obj.context.moveTo(mouseX,mouseY)}else{obj.context.strokeStyle=obj.properties['chart.annotatable.color'];obj.context.moveTo(lastXY[0],lastXY[1]);obj.context.lineTo(mouseX,mouseY);}
15
- RG.Registry.set('annotatable.actions',RG.Registry.get('annotatable.actions')+'|'+mouseX+','+mouseY);RG.Registry.set('annotatable.last.coordinates',[mouseX,mouseY]);RG.FireCustomEvent(obj,'onannotate');obj.context.stroke();}};RG.ShowPalette=RG.Showpalette=function(e)
16
- {var isSafari=navigator.userAgent.indexOf('Safari')?true:false;e=RG.FixEventObject(e);var canvas=e.target.parentNode.__canvas__,context=canvas.getContext('2d'),obj=canvas.__object__,div=document.createElement('DIV'),coords=RG.getMouseXY(e)
17
- div.__object__=obj;div.className='RGraph_palette';div.style.position='absolute';div.style.backgroundColor='white';div.style.border='1px solid black';div.style.left=0;div.style.top=0;div.style.padding='3px';div.style.paddingLeft='5px';div.style.opacity=0;div.style.boxShadow='rgba(96,96,96,0.5) 3px 3px 3px';div.style.WebkitBoxShadow='rgba(96,96,96,0.5) 3px 3px 3px';div.style.MozBoxShadow='rgba(96,96,96,0.5) 3px 3px 3px';var colors=['Black','Red','Yellow','Green','Orange','White','Magenta','Pink'];for(var i=0,len=colors.length;i<len;i+=1){var div2=doc.createElement('DIV');div2.cssClass='RGraph_palette_color';div2.style.fontSize='12pt';div2.style.cursor='pointer';div2.style.padding='1px';div2.style.paddingRight='10px';div2.style.textAlign='left';var span=document.createElement('SPAN');span.style.display='inline-block';span.style.marginRight='9px';span.style.width='17px';span.style.height='17px';span.style.top='2px';span.style.position='relative';span.style.backgroundColor=colors[i];div2.appendChild(span);div2.innerHTML+=colors[i];div2.onmouseover=function()
18
- {this.style.backgroundColor='#eee';}
19
- div2.onmouseout=function()
20
- {this.style.backgroundColor='';}
21
- div2.onclick=function(e)
22
- {var color=this.childNodes[0].style.backgroundColor;obj.set('chart.annotatable.color',color);}
23
- div.appendChild(div2);}
24
- doc.body.appendChild(div);div.style.left=e.pageX+'px';div.style.top=e.pageY+'px';if((e.pageX+(div.offsetWidth+5))>document.body.offsetWidth){div.style.left=(e.pageX-div.offsetWidth)+'px';}
25
- RGraph.Registry.set('chart.palette',div);setTimeout(function(){div.style.opacity=0.2;},50);setTimeout(function(){div.style.opacity=0.4;},100);setTimeout(function(){div.style.opacity=0.6;},150);setTimeout(function(){div.style.opacity=0.8;},200);setTimeout(function(){div.style.opacity=1;},250);RGraph.hideContext();window.onclick=function()
26
- {RG.hidePalette();}
27
- e.stopPropagation();return false;};RG.clearAnnotations=RG.ClearAnnotations=function(canvas)
28
- {if(typeof canvas==='string'){var id=canvas;canvas=doc.getElementById(id);}else{var id=canvas.id}
29
- var obj=canvas.__object__;if(win.localStorage&&win.localStorage['__rgraph_annotations_'+id+'__']&&win.localStorage['__rgraph_annotations_'+id+'__'].length){win.localStorage['__rgraph_annotations_'+id+'__']=[];RGraph.fireCustomEvent(obj,'onannotateclear');}};RG.replayAnnotations=RG.ReplayAnnotations=function(obj)
30
- {if(!win.localStorage){return;}
31
- var context=obj.context;var annotations=win.localStorage['__rgraph_annotations_'+obj.id+'__'];var i,len,move,coords;context.beginPath();context.lineWidth=obj.get('annotatable.linewidth');if(annotations&&annotations.length){annotations=annotations.split('|');}else{return;}
32
- for(i=0,len=annotations.length;i<len;++i){if(annotations[i].match(/[a-z]+/)){context.stroke();context.beginPath();context.strokeStyle=annotations[i];move=true;continue;}
33
- coords=annotations[i].split(',');coords[0]=Number(coords[0]);coords[1]=Number(coords[1]);if(move){context.moveTo(coords[0],coords[1]);move=false;}else{context.lineTo(coords[0],coords[1]);}}
34
- context.stroke();};window.addEventListener('load',function(e)
35
- {setTimeout(function()
36
- {var tags=doc.getElementsByTagName('canvas');for(var i=0;i<tags.length;++i){if(tags[i].__object__&&tags[i].__object__.isRGraph&&tags[i].__object__.get('chart.annotatable')){RG.replayAnnotations(tags[i].__object__);}}},100);},false);})(window,document);
12
+ RGraph = window.RGraph || {isrgraph:true,isRGraph: true,rgraph:true};
13
+
14
+ // Module pattern
15
+ (function (win, doc, undefined)
16
+ {
17
+ var ua = navigator.userAgent;
18
+
19
+ //
20
+ // This installs some event handlers
21
+ //
22
+ // Checking the RGraph.annotate flag means the annotate code only runs once
23
+ //
24
+ RGraph.annotating_canvas_onmousedown = function (e)
25
+ {
26
+ if (e.button === 0) {
27
+
28
+ e.target.__object__.set('mousedown', true);
29
+
30
+ // Get the object from the canvas. Annotating must be enabled on the
31
+ // last object defined
32
+ var obj = e.target.__object__,
33
+ properties = obj.properties
34
+
35
+ // This starts the annotating "path" and set the color
36
+ obj.context.beginPath();
37
+
38
+ obj.context.strokeStyle = obj.get('annotatableColor');
39
+ obj.context.lineWidth = obj.get('annotatableLinewidth');
40
+
41
+ var mouseXY = RGraph.getMouseXY(e),
42
+ mouseX = mouseXY[0],
43
+ mouseY = mouseXY[1]
44
+
45
+ // Allow for the Bar chart 3D
46
+ if (obj.type === 'bar' && properties.variant === '3d') {
47
+ var adjustment = properties.variantThreedAngle * mouseXY[0];
48
+ mouseY -= adjustment;
49
+ }
50
+
51
+ // Clear the annotation recording
52
+ RGraph.Registry.set('annotatable.actions', [obj.get('annotatableColor')]);
53
+
54
+ // This sets the initial X/Y position
55
+ obj.context.moveTo(mouseX, mouseY);
56
+ RGraph.Registry.set('annotatable.last.coordinates', [mouseX,mouseY]);
57
+
58
+ RGraph.Registry.set('started.annotating', false);
59
+ RGraph.Registry.set('annotating', obj);
60
+
61
+ // Fire the onannotatebegin event.
62
+ RGraph.fireCustomEvent(obj, 'onannotatebegin');
63
+ }
64
+
65
+ return false;
66
+ };
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+ //
76
+ // This cancels annotating for ALL canvases
77
+ //
78
+ RGraph.annotating_window_onmouseup = function (e)
79
+ {
80
+ var obj = RGraph.Registry.get('annotating');
81
+ var win = window;
82
+
83
+ if (e.button != 0 || !obj) {
84
+ return;
85
+ }
86
+
87
+ // This cancels annotating on ALL canvas tags on the page
88
+ var tags = doc.getElementsByTagName('canvas');
89
+
90
+ for (var i=0; i<tags.length; ++i) {
91
+ if (tags[i].__object__) {
92
+ tags[i].__object__.set('mousedown', false);
93
+ }
94
+ }
95
+
96
+ // Store the annotations in browser storage if it's available
97
+ if (RGraph.Registry.get('annotatable.actions') && RGraph.Registry.get('annotatable.actions').length > 0 && win.localStorage) {
98
+
99
+ var id = '__rgraph_annotations_' + e.target.id + '__';
100
+ var annotations = win.localStorage[id] ? win.localStorage[id] + '|' : '';
101
+ annotations += RGraph.Registry.get('annotatable.actions');
102
+
103
+ // Store the annotations information in HTML5 browser storage here
104
+ win.localStorage[id] = annotations;
105
+ }
106
+
107
+ // Clear the recorded annotations
108
+ RGraph.Registry.set('annotatable.actions', []);
109
+
110
+ // Fire the annotate event
111
+ RGraph.fireCustomEvent(obj, 'onannotateend');
112
+ };
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+ //
122
+ // The canvas onmousemove function
123
+ //
124
+ RGraph.annotating_canvas_onmousemove = function (e)
125
+ {
126
+ var obj = e.target.__object__;
127
+ var properties = obj.properties;
128
+ var mouseXY = RGraph.getMouseXY(e);
129
+ var mouseX = mouseXY[0];
130
+ var mouseY = mouseXY[1];
131
+ var lastXY = RGraph.Registry.get('annotatable.last.coordinates');
132
+
133
+ if (obj.get('mousedown')) {
134
+
135
+ // Allow for the Bar chart 3D
136
+ if (obj.type === 'bar' && properties.variant === '3d') {
137
+ var adjustment = properties.variantThreedAngle * mouseXY[0];
138
+ mouseY -= adjustment;
139
+ }
140
+
141
+ obj.context.beginPath();
142
+
143
+ if (!lastXY) {
144
+ obj.context.moveTo(mouseX, mouseY)
145
+ } else {
146
+ obj.context.strokeStyle = obj.properties.annotatableColor;
147
+ obj.context.moveTo(lastXY[0], lastXY[1]);
148
+ obj.context.lineTo(mouseX, mouseY);
149
+ }
150
+
151
+ RGraph.Registry.set('annotatable.actions', RGraph.Registry.get('annotatable.actions') + '|' + mouseX + ',' + mouseY);
152
+ RGraph.Registry.set('annotatable.last.coordinates', [mouseX,mouseY]);
153
+
154
+ RGraph.fireCustomEvent(obj, 'onannotate');
155
+ obj.context.stroke();
156
+ }
157
+ };
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+ //
167
+ // Shows the mini palette used for annotations
168
+ //
169
+ // @param object e The event object
170
+ //
171
+ RGraph.showPalette = function (e)
172
+ {
173
+ var isSafari = navigator.userAgent.indexOf('Safari') ? true : false;
174
+
175
+ var canvas = e.target.parentNode.__canvas__,
176
+ context = canvas.getContext('2d'),
177
+ obj = canvas.__object__,
178
+ div = document.createElement('DIV'),
179
+ coords = RGraph.getMouseXY(e)
180
+
181
+ div.__object__ = obj; // The graph object
182
+ div.className = 'RGraph_palette';
183
+ div.style.position = 'absolute';
184
+ div.style.backgroundColor = 'white';
185
+ div.style.border = '1px solid #999';
186
+ div.style.left = 0;
187
+ div.style.top = 0;
188
+ div.style.padding = '3px';
189
+ div.style.paddingLeft = '5px';
190
+ div.style.opacity = 0;
191
+ div.style.boxShadow = 'rgba(48,48,48,0.25) 1px 1px 3px';
192
+ div.style.WebkitBoxShadow = 'rgba(48,48,48,0.25) 1px 1px 3px';
193
+ div.style.MozBoxShadow = 'rgba(48,48,48,0.25) 1px 1px 3px';
194
+
195
+
196
+ // MUST use named colors that are capitalised
197
+ var colors = [
198
+ 'Black', 'Red', 'Yellow', 'Green',
199
+ 'Orange', 'White', 'Magenta', 'Pink'
200
+ ];
201
+
202
+ // Add the colors to the palette
203
+ for (var i=0,len=colors.length; i<len; i+=1) {
204
+
205
+ var div2 = doc.createElement('DIV');
206
+ div2.cssClass = 'RGraph_palette_color';
207
+ div2.style.fontSize = '12pt';
208
+ div2.style.cursor = 'pointer';
209
+ div2.style.padding = '1px';
210
+ div2.style.paddingRight = '10px';
211
+ div2.style.textAlign = 'left';
212
+
213
+ var span = document.createElement('SPAN');
214
+ span.style.display = 'inline-block';
215
+ span.style.marginRight = '9px';
216
+ span.style.width = '17px';
217
+ span.style.height = '17px';
218
+ span.style.top = '2px';
219
+ span.style.position = 'relative';
220
+ span.style.backgroundColor = colors[i];
221
+ div2.appendChild(span);
222
+
223
+ div2.innerHTML += colors[i];
224
+
225
+
226
+ div2.onmouseover = function ()
227
+ {
228
+ this.style.backgroundColor = '#eee';
229
+ }
230
+
231
+ div2.onmouseout = function ()
232
+ {
233
+ this.style.backgroundColor = '';
234
+ }
235
+
236
+ div2.onclick = function (e)
237
+ {
238
+ var color = this.childNodes[0].style.backgroundColor;
239
+
240
+ obj.set('annotatableColor', color);
241
+ }
242
+ div.appendChild(div2);
243
+ }
244
+
245
+
246
+ doc.body.appendChild(div);
247
+
248
+ //
249
+ // Now the div has been added to the document, move it up and left
250
+ //
251
+ div.style.left = e.pageX + 'px';
252
+ div.style.top = e.pageY + 'px';
253
+
254
+ //
255
+ // Chang the position if the cursor is near the right edge of the browser window
256
+ //
257
+ if ((e.pageX + (div.offsetWidth + 5) ) > document.body.offsetWidth) {
258
+ div.style.left = (e.pageX - div.offsetWidth) + 'px';
259
+ }
260
+
261
+ //
262
+ // Store the palette div in the registry
263
+ //
264
+ RGraph.Registry.set('palette', div);
265
+
266
+ setTimeout(function () {div.style.opacity = 0.2;}, 50);
267
+ setTimeout(function () {div.style.opacity = 0.4;}, 100);
268
+ setTimeout(function () {div.style.opacity = 0.6;}, 150);
269
+ setTimeout(function () {div.style.opacity = 0.8;}, 200);
270
+ setTimeout(function () {div.style.opacity = 1;}, 250);
271
+
272
+ RGraph.hideContext();
273
+
274
+ window.onclick = function ()
275
+ {
276
+ RGraph.hidePalette();
277
+ }
278
+
279
+ // Should this be here? Yes. This function is being used as an event handler.
280
+ e.stopPropagation();
281
+ return false;
282
+ };
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+ //
292
+ // Clears any annotation data from global storage
293
+ //
294
+ // @param object canvas The canvas tag object
295
+ //
296
+ RGraph.clearAnnotations = function (canvas)
297
+ {
298
+ //
299
+ // For BC the argument can also be the ID of the canvas
300
+ //
301
+ if (typeof canvas === 'string') {
302
+ var id = canvas;
303
+ canvas = doc.getElementById(id);
304
+ } else {
305
+ var id = canvas.id
306
+ }
307
+
308
+ var obj = canvas.__object__;
309
+
310
+ if (win.localStorage && win.localStorage['__rgraph_annotations_' + id + '__'] && win.localStorage['__rgraph_annotations_' + id + '__'].length) {
311
+ win.localStorage['__rgraph_annotations_' + id + '__'] = [];
312
+
313
+ RGraph.fireCustomEvent(obj, 'onannotateclear');
314
+ }
315
+ };
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+ //
325
+ // Replays stored annotations
326
+ //
327
+ // @param object obj The graph object
328
+ //
329
+ RGraph.replayAnnotations = function (obj)
330
+ {
331
+ // Check for support
332
+ if (!win.localStorage) {
333
+ return;
334
+ }
335
+
336
+ var context = obj.context;
337
+ var annotations = win.localStorage['__rgraph_annotations_' + obj.id + '__'];
338
+ var i, len, move, coords;
339
+
340
+ // Save the state of the canvas
341
+ context.save();
342
+ context.beginPath();
343
+ context.lineWidth = obj.get('annotatableLinewidth');
344
+
345
+ if (annotations && annotations.length) {
346
+ annotations = annotations.split('|');
347
+ } else {
348
+ return;
349
+ }
350
+
351
+ // Set the stroke color
352
+ context.strokeStyle = annotations[i] || 'black';
353
+
354
+
355
+
356
+ for (i=0,len=annotations.length; i<len; ++i) {
357
+
358
+ // If the element of the array is a color - finish the path,
359
+ // stroke it and start a new one
360
+ if (annotations[i].match(/[a-z]+/)) {
361
+
362
+ context.stroke();
363
+ context.beginPath();
364
+
365
+ context.strokeStyle = annotations[i];
366
+ move = true;
367
+ continue;
368
+ }
369
+
370
+ coords = annotations[i].split(',');
371
+ coords[0] = Number(coords[0]);
372
+ coords[1] = Number(coords[1]);
373
+
374
+ if (move) {
375
+ context.moveTo(coords[0], coords[1]);
376
+ move = false;
377
+ } else {
378
+ context.lineTo(coords[0], coords[1]);
379
+ }
380
+ }
381
+
382
+ context.stroke();
383
+ context.restore();
384
+ };
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+ window.addEventListener('load', function (e)
394
+ {
395
+ // This delay is necessary to allow the window.onload event listener to run
396
+ setTimeout(function ()
397
+ {
398
+ var tags = doc.getElementsByTagName('canvas');
399
+ for (var i=0; i<tags.length; ++i) {
400
+ if (tags[i].__object__ && tags[i].__object__.isRGraph && tags[i].__object__.get('annotatable')) {
401
+ RGraph.replayAnnotations(tags[i].__object__);
402
+ }
403
+ }
404
+ }, 100); // This delay is sufficient to wait before replaying the annotations
405
+ }, false);
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+ // End module pattern
415
+ })(window, document);