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,53 +1,858 @@
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
11
+
12
+ //
13
+ // Having this here means that the RGraph libraries can be included in any order, instead of you having
14
+ // to include the common core library first.
15
+ //
1
16
 
2
- RGraph=window.RGraph||{isRGraph:true};RGraph.Drawing=RGraph.Drawing||{};RGraph.Drawing.Image=function(conf)
3
- {if(typeof conf==='object'&&typeof conf.x==='number'&&typeof conf.y==='number'&&typeof conf.src==='string'&&typeof conf.id==='string'){var id=conf.id,canvas=document.getElementById(id),x=conf.x,y=conf.y,src=conf.src,parseConfObjectForOptions=true;}else{var id=conf,canvas=document.getElementById(id),x=arguments[1],y=arguments[2],src=arguments[3];}
4
- this.id=id;this.canvas=document.getElementById(this.id);this.context=this.canvas.getContext('2d');this.colorsParsed=false;this.canvas.__object__=this;this.alignmentProcessed=false;this.original_colors=[];this.firstDraw=true;this.propertyNameAliases={};this.x=x;this.y=y;this.src=src;this.img=new Image();this.img.src=this.src;this.type='drawing.image';this.isRGraph=true;this.uid=RGraph.createUID();this.canvas.uid=this.canvas.uid?this.canvas.uid:RGraph.CreateUID();this.properties={'chart.src':null,'chart.width':null,'chart.height':null,'chart.halign':'left','chart.valign':'top','chart.events.mousemove':null,'chart.events.click':null,'chart.shadow':false,'chart.shadow.color':'gray','chart.shadow.offsetx':3,'chart.shadow.offsety':3,'chart.shadow.blur':5,'chart.tooltips':null,'chart.tooltips.highlight':true,'chart.tooltips.css.class':'RGraph_tooltip','chart.tooltips.event':'onclick','chart.highlight.stroke':'rgba(0,0,0,0)','chart.highlight.fill':'rgba(255,255,255,0.7)','chart.colors.alpha':1,'chart.border':false,'chart.border.color':'black','chart.border.linewidth':1,'chart.border.radius':0,'chart.background.color':'rgba(0,0,0,0)','chart.clearto':'rgba(0,0,0,0)'}
5
- if(!this.canvas){alert('[DRAWING.IMAGE] No canvas support');return;}
6
- this.coords=[];this.$0={};if(!this.canvas.__rgraph_aa_translated__){this.context.translate(0.5,0.5);this.canvas.__rgraph_aa_translated__=true;}
7
- var RG=RGraph,ca=this.canvas,co=ca.getContext('2d'),prop=this.properties,pa2=RG.path2,win=window,doc=document,ma=Math
8
- if(RG.Effects&&typeof RG.Effects.decorate==='function'){RG.Effects.decorate(this);}
9
- this.set=this.Set=function(name)
10
- {var value=typeof arguments[1]==='undefined'?null:arguments[1];if(arguments.length===1&&typeof name==='object'){RG.parseObjectStyleConfig(this,name);return this;}
11
- if(name.substr(0,6)!='chart.'){name='chart.'+name;}
12
- while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
13
- prop[name]=value;return this;};this.get=this.Get=function(name)
14
- {if(name.substr(0,6)!='chart.'){name='chart.'+name;}
15
- while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
16
- return prop[name.toLowerCase()];};this.draw=this.Draw=function()
17
- {RG.fireCustomEvent(this,'onbeforedraw');var obj=this;this.img.onload=function()
18
- {if(!obj.colorsParsed){obj.parseColors();obj.colorsParsed=true;}
19
- obj.width=this.width;obj.height=this.height;if(!this.alignmentProcessed){var customWidthHeight=(typeof obj.properties['chart.width']=='number'&&typeof obj.properties['chart.width']=='number');if(obj.properties['chart.halign']==='center'){obj.x-=customWidthHeight?(obj.properties['chart.width']/2):(this.width/2);}else if(obj.properties['chart.halign']=='right'){obj.x-=customWidthHeight?obj.properties['chart.width']:this.width;}
20
- if(obj.properties['chart.valign']==='center'){obj.y-=customWidthHeight?(obj.properties['chart.height']/2):(this.height/2);}else if(obj.properties['chart.valign']=='bottom'){obj.y-=customWidthHeight?obj.properties['chart.height']:this.height;}
21
- this.alignmentProcessed=true;}}
22
- if(this.img.complete||this.img.readyState===4){this.img.onload();}
23
- if(prop['chart.shadow']){RG.setShadow(this,prop['chart.shadow.color'],prop['chart.shadow.offsetx'],prop['chart.shadow.offsety'],prop['chart.shadow.blur']);}
24
- var oldAlpha=co.globalAlpha;co.globalAlpha=prop['chart.colors.alpha'];if(prop['chart.border']){co.strokeStyle=prop['chart.border.color'];co.lineWidth=prop['chart.border.linewidth'];var borderRadius=0;if(this.width||this.height){borderRadius=ma.min(this.width/2,this.height/2)}
25
- if((prop['chart.width']/2)>borderRadius&&(prop['chart.height']/2)>borderRadius){borderRadius=ma.min((prop['chart.width']/2),(prop['chart.height']/2))}
26
- if(prop['chart.border.radius']<borderRadius){borderRadius=prop['chart.border.radius'];}
27
- co.beginPath();this.roundedRect(ma.round(this.x)-ma.round(co.lineWidth/2),ma.round(this.y)-ma.round(co.lineWidth/2),(prop['chart.width']||this.img.width)+co.lineWidth,(prop['chart.height']||this.img.height)+co.lineWidth,borderRadius);}
28
- if(borderRadius){co.save();this.drawBackgroundColor(borderRadius);co.beginPath();this.roundedRect(ma.round(this.x)-ma.round(co.lineWidth/2),ma.round(this.y)-ma.round(co.lineWidth/2),(prop['chart.width']||this.img.width)+co.lineWidth,(prop['chart.height']||this.img.height)+co.lineWidth,borderRadius);co.clip();}else{this.drawBackgroundColor(0);}
29
- if(typeof prop['chart.height']==='number'||typeof prop['chart.width']==='number'){co.drawImage(this.img,ma.round(this.x),ma.round(this.y),prop['chart.width']||this.width,prop['chart.height']||this.height);}else{co.drawImage(this.img,ma.round(this.x),ma.round(this.y));}
30
- if(borderRadius){co.restore();}
31
- RG.noShadow(this);if(prop['chart.border']){co.stroke();}
32
- co.globalAlpha=oldAlpha;this.img.onload=function()
33
- {RG.redrawCanvas(ca);obj.coords[0]=[ma.round(obj.x),ma.round(obj.y),typeof prop['chart.width']==='number'?prop['chart.width']:this.width,typeof prop['chart.height']=='number'?prop['chart.height']:this.height];}
34
- RG.noShadow(this);RG.installEventListeners(this);if(this.firstDraw){this.firstDraw=false;RG.fireCustomEvent(this,'onfirstdraw');this.firstDrawFunc();}
35
- RG.fireCustomEvent(this,'ondraw');return this;};this.exec=function(func)
36
- {func(this);return this;};this.getObjectByXY=function(e)
37
- {var mouseXY=RG.getMouseXY(e);if(this.getShape(e)){return this;}};this.getShape=function(e)
38
- {var mouseXY=RG.getMouseXY(e),mouseX=mouseXY[0],mouseY=mouseXY[1];if(this.coords&&this.coords[0]&&mouseXY[0]>=this.coords[0][0]&&mouseXY[0]<=(this.coords[0][0]+this.coords[0][2])&&mouseXY[1]>=this.coords[0][1]&&mouseXY[1]<=(this.coords[0][1]+this.coords[0][3])){return{0:this,1:this.coords[0][0],2:this.coords[0][1],3:this.coords[0][2],4:this.coords[0][3],5:0,'object':this,'x':this.coords[0][0],'y':this.coords[0][1],'width':this.coords[0][2],'height':this.coords[0][3],'index':0,'tooltip':prop['chart.tooltips']?prop['chart.tooltips'][0]:null};}
39
- return null;};this.highlight=this.Highlight=function(shape)
40
- {if(prop['chart.tooltips.highlight']){if(typeof prop['chart.highlight.style']==='function'){(prop['chart.highlight.style'])(shape);}else{pa2(co,['b','r',this.coords[0][0],this.coords[0][1],this.coords[0][2],this.coords[0][3],'f',prop['chart.highlight.fill'],'s',prop['chart.highlight.stroke']]);}}};this.parseColors=function()
41
- {if(this.original_colors.length===0){this.original_colors['chart.colors.background']=RG.arrayClone(prop['chart.colors.background']);this.original_colors['chart.highlight.stroke']=RG.arrayClone(prop['chart.highlight.stroke']);this.original_colors['chart.highlight.fill']=RG.arrayClone(prop['chart.highlight.fill']);}
42
- prop['chart.colors.background']=this.parseSingleColorForGradient(prop['chart.colors.background']);prop['chart.highlight.stroke']=this.parseSingleColorForGradient(prop['chart.highlight.stroke']);prop['chart.highlight.fill']=this.parseSingleColorForGradient(prop['chart.highlight.fill']);};this.reset=function()
43
- {};this.parseSingleColorForGradient=function(color)
44
- {if(!color){return color;}
45
- if(typeof color==='string'&&color.match(/^gradient\((.*)\)$/i)){if(color.match(/^gradient\(({.*})\)$/i)){return RGraph.parseJSONGradient({object:this,def:RegExp.$1});}
46
- var parts=RegExp.$1.split(':'),grad=co.createLinearGradient(this.x,this.y,this.x+this.img.width,this.y),diff=1/(parts.length-1);grad.addColorStop(0,RG.trim(parts[0]));for(var j=1;j<parts.length;++j){grad.addColorStop(j*diff,RG.trim(parts[j]));}}
47
- return grad?grad:color;};this.on=function(type,func)
48
- {if(type.substr(0,2)!=='on'){type='on'+type;}
49
- if(typeof this[type]!=='function'){this[type]=func;}else{RG.addCustomEventListener(this,type,func);}
50
- return this;};this.firstDrawFunc=function()
51
- {};this.roundedRect=function(x,y,width,height,radius)
52
- {co.save();co.translate(x,y);co.moveTo(width/2,0);co.arcTo(width,0,width,height,ma.min(height/2,radius));co.arcTo(width,height,0,height,ma.min(width/2,radius));co.arcTo(0,height,0,0,ma.min(height/2,radius));co.arcTo(0,0,radius,0,ma.min(width/2,radius));co.lineTo(width/2,0);co.restore();};this.drawBackgroundColor=function(borderRadius)
53
- {co.beginPath();co.fillStyle=prop['chart.background.color'];this.roundedRect(ma.round(this.x)-ma.round(co.lineWidth/2),ma.round(this.y)-ma.round(co.lineWidth/2),(prop['chart.width']||this.img.width)+co.lineWidth,(prop['chart.height']||this.img.height)+co.lineWidth,borderRadius);co.fill();};RG.register(this);if(parseConfObjectForOptions){RG.parseObjectStyleConfig(this,conf.options);}};
17
+ // Define the RGraph global variable
18
+ RGraph = window.RGraph || {isrgraph:true,isRGraph: true,rgraph:true};
19
+ RGraph.Drawing = RGraph.Drawing || {};
20
+
21
+ //
22
+ // The constructor. This function sets up the object.
23
+ //
24
+ RGraph.Drawing.Image = function (conf)
25
+ {
26
+ var id = conf.id,
27
+ canvas = document.getElementById(id),
28
+ x = conf.x,
29
+ y = conf.y,
30
+ src = conf.src;
31
+
32
+ // id, x, y
33
+ this.id = id;
34
+ this.canvas = document.getElementById(this.id);
35
+ this.context = this.canvas.getContext('2d');
36
+ this.colorsParsed = false;
37
+ this.canvas.__object__ = this;
38
+ this.alignmentProcessed = false;
39
+ this.original_colors = [];
40
+ this.firstDraw = true; // After the first draw this will be false
41
+
42
+ //
43
+ // Store the properties
44
+ //
45
+ this.x = x;
46
+ this.y = y;
47
+ this.src = src;
48
+ this.img = new Image();
49
+ this.img.src = this.src;
50
+
51
+
52
+ //
53
+ // This defines the type of this shape
54
+ //
55
+ this.type = 'drawing.image';
56
+
57
+
58
+ //
59
+ // This facilitates easy object identification, and should always be true
60
+ //
61
+ this.isRGraph = true;
62
+ this.isrgraph = true;
63
+ this.rgraph = true;
64
+
65
+
66
+ //
67
+ // This adds a uid to the object that you can use for identification purposes
68
+ //
69
+ this.uid = RGraph.createUID();
70
+
71
+
72
+ //
73
+ // This adds a UID to the canvas for identification purposes
74
+ //
75
+ this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID();
76
+
77
+
78
+
79
+
80
+ //
81
+ // Some example background properties
82
+ //
83
+ this.properties =
84
+ {
85
+ src: null,
86
+
87
+ width: null,
88
+ height: null,
89
+
90
+ halign: 'left',
91
+ valign: 'top',
92
+
93
+ shadow: false,
94
+ shadowColor: 'gray',
95
+ shadowOffsetx: 3,
96
+ shadowOffsety: 3,
97
+ shadowBlur: 5,
98
+
99
+ tooltips: null,
100
+ tooltipsHighlight: true,
101
+ tooltipsCssClass: 'RGraph_tooltip',
102
+ tooltipsCss: null,
103
+ tooltipsEffect: 'slide',
104
+ tooltipsEvent: 'onclick',
105
+ tooltipsFormattedPoint: '.',
106
+ tooltipsFormattedThousand: ',',
107
+ tooltipsFormattedDecimals: 0,
108
+ tooltipsFormattedUnitsPre: '',
109
+ tooltipsFormattedUnitsPost: '',
110
+ tooltipsFormattedListType: 'ul',
111
+ tooltipsFormattedListItems: null,
112
+ tooltipsPointer: true,
113
+ tooltipsPointerOffsetx: 0,
114
+ tooltipsPointerOffsety: 0,
115
+ tooltipsPositionStatic: true,
116
+
117
+ highlightStroke: 'rgba(0,0,0,0)',
118
+ highlightFill: 'rgba(255,255,255,0.7)',
119
+
120
+ colorsAlpha: 1,
121
+
122
+ border: false,
123
+ borderColor: 'black',
124
+ borderLinewidth: 1,
125
+ borderRadius: 0,
126
+
127
+ backgroundColor: 'rgba(0,0,0,0)',
128
+
129
+ text: null,
130
+
131
+ clearto: 'rgba(0,0,0,0)'
132
+ }
133
+
134
+ //
135
+ // A simple check that the browser has canvas support
136
+ //
137
+ if (!this.canvas) {
138
+ alert('[DRAWING.IMAGE] No canvas support');
139
+ return;
140
+ }
141
+
142
+ //
143
+ // This can be used to store the coordinates of shapes on the graph
144
+ //
145
+ this.coords = [];
146
+
147
+
148
+ //
149
+ // Create the dollar object so that functions can be added to them
150
+ //
151
+ this.$0 = {};
152
+
153
+
154
+
155
+
156
+ // Easy access to properties and the path function
157
+ var properties = this.properties;
158
+ this.path = RGraph.pathObjectFunction;
159
+
160
+ //
161
+ // "Decorate" the object with the generic effects if the effects library has been included
162
+ //
163
+ if (RGraph.Effects && typeof RGraph.Effects.decorate === 'function') {
164
+ RGraph.Effects.decorate(this);
165
+ }
166
+
167
+
168
+
169
+ //
170
+ // A setter method for setting graph properties. It can be used like this: obj.set('colorsStroke', '#666');
171
+ //
172
+ // @param name string The name of the property to set OR it can be a map
173
+ // of name/value settings like what you set in the constructor
174
+ //
175
+ this.set = function (name)
176
+ {
177
+ var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
178
+
179
+ // the number of arguments is only one and it's an
180
+ // object - parse it for configuration data and return.
181
+ if (arguments.length === 1 && typeof arguments[0] === 'object') {
182
+ for (i in arguments[0]) {
183
+ if (typeof i === 'string') {
184
+ this.set(i, arguments[0][i]);
185
+ }
186
+ }
187
+
188
+ return this;
189
+ }
190
+
191
+ properties[name] = value;
192
+
193
+ return this;
194
+ };
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+ //
204
+ // A getter method for retrieving graph properties. It can be used like this: obj.get('colorsStroke');
205
+ //
206
+ // @param name string The name of the property to get
207
+ //
208
+ this.get = function (name)
209
+ {
210
+ return properties[name];
211
+ };
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+ //
221
+ // Draws the circle
222
+ //
223
+ this.draw = function ()
224
+ {
225
+ //
226
+ // Fire the onbeforedraw event
227
+ //
228
+ RGraph.fireCustomEvent(this, 'onbeforedraw');
229
+
230
+ // Translate half a pixel for antialiasing purposes - but only if it hasn't been
231
+ // done already
232
+ //
233
+ // MUST be the first thing done!
234
+ //
235
+ if (!this.canvas.__rgraph_aa_translated__) {
236
+ this.context.translate(0.5,0.5);
237
+
238
+ this.canvas.__rgraph_aa_translated__ = true;
239
+ }
240
+
241
+
242
+ //
243
+ // Parse the colors. This allows for simple gradient syntax
244
+ //
245
+ var obj = this;
246
+ this.img.onload = function ()
247
+ {
248
+ if (!obj.colorsParsed) {
249
+
250
+ obj.parseColors();
251
+
252
+ // Don't want to do this again
253
+ obj.colorsParsed = true;
254
+ }
255
+
256
+ obj.width = this.width;
257
+ obj.height = this.height;
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+ if (!obj.alignmentProcessed) {
266
+
267
+ var customWidthHeight = (typeof obj.properties.width == 'number' && typeof obj.properties.width == 'number');
268
+
269
+ // Horizontal alignment
270
+ if (obj.properties.halign === 'center') {
271
+ obj.x -= customWidthHeight ? (obj.properties.width / 2) : (this.width / 2);
272
+ } else if (obj.properties.halign == 'right') {
273
+ obj.x -= customWidthHeight ? obj.properties.width : this.width;
274
+ }
275
+
276
+ // Vertical alignment
277
+ if (obj.properties.valign === 'center') {
278
+ obj.y -= customWidthHeight ? (obj.properties.height / 2) : (this.height / 2);
279
+ } else if (obj.properties.valign == 'bottom') {
280
+ obj.y -= customWidthHeight ? obj.properties.height : this.height;
281
+ }
282
+
283
+ // Don't do this again
284
+ obj.alignmentProcessed = true;
285
+ }
286
+ }
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+ // The onload event doesn't always fire - so call it manually as well
296
+ if (this.img.complete || this.img.readyState === 4) {
297
+ this.img.onload();
298
+ }
299
+
300
+
301
+ //
302
+ // Draw the image here
303
+ //
304
+
305
+ if (properties.shadow) {
306
+ RGraph.setShadow(
307
+ this,
308
+ properties.shadowColor,
309
+ properties.shadowOffsetx,
310
+ properties.shadowOffsety,
311
+ properties.shadowBlur
312
+ );
313
+ }
314
+
315
+ var oldAlpha = this.context.globalAlpha;
316
+ this.context.globalAlpha = properties.colorsAlpha;
317
+
318
+
319
+
320
+
321
+
322
+ //
323
+ // Draw a border around the image
324
+ //
325
+ if (properties.border) {
326
+
327
+ this.context.strokeStyle = properties.borderColor;
328
+ this.context.lineWidth = properties.borderLinewidth;
329
+
330
+ var borderRadius = 0;
331
+
332
+ // Work out the borderRadius only if the image has been loaded
333
+ if (this.width || this.height) {
334
+ borderRadius = Math.min(this.width / 2, this.height / 2)
335
+ }
336
+
337
+ if ((properties.width / 2) > borderRadius && (properties.height / 2) > borderRadius) {
338
+ borderRadius = Math.min((properties.width / 2), (properties.height / 2))
339
+ }
340
+
341
+ if (properties.borderRadius < borderRadius) {
342
+ borderRadius = properties.borderRadius;
343
+ }
344
+
345
+
346
+
347
+
348
+ this.context.beginPath();
349
+ this.roundedRect(
350
+ Math.round(this.x) - Math.round(this.context.lineWidth / 2),
351
+ Math.round(this.y) - Math.round(this.context.lineWidth / 2),
352
+ (properties.width || this.img.width) + this.context.lineWidth,
353
+ (properties.height || this.img.height) + this.context.lineWidth,
354
+ borderRadius
355
+ );
356
+ }
357
+
358
+
359
+
360
+ if (borderRadius) {
361
+ this.context.save();
362
+
363
+ // Draw the rect that casts the shadow
364
+
365
+ // Draw the background color
366
+ this.drawBackgroundColor(borderRadius);
367
+
368
+
369
+
370
+ // Clip the canvas
371
+ this.context.beginPath();
372
+ this.roundedRect(
373
+ Math.round(this.x) - Math.round(this.context.lineWidth / 2),
374
+ Math.round(this.y) - Math.round(this.context.lineWidth / 2),
375
+ (properties.width || this.img.width) + this.context.lineWidth,
376
+ (properties.height || this.img.height) + this.context.lineWidth,
377
+ borderRadius
378
+ );
379
+ this.context.clip();
380
+
381
+ } else {
382
+
383
+ // Draw the background color
384
+ this.drawBackgroundColor(0);
385
+ }
386
+
387
+
388
+ if (typeof properties.height === 'number' || typeof properties.width === 'number') {
389
+ this.context.drawImage(
390
+ this.img,
391
+ Math.round(this.x),
392
+ Math.round(this.y),
393
+ properties.width || this.width,
394
+ properties.height || this.height
395
+ );
396
+ } else {
397
+ this.context.drawImage(
398
+ this.img,
399
+ Math.round(this.x),
400
+ Math.round(this.y)
401
+ );
402
+ }
403
+
404
+
405
+
406
+
407
+ // If borderRadius is enabled restore the canvas to it's pre-clipped state
408
+ if (borderRadius) {
409
+ this.context.restore();
410
+ }
411
+
412
+ RGraph.noShadow(this);
413
+
414
+
415
+
416
+ // If the border is enabled need a stroke so that the border is drawn
417
+ if (properties.border) {
418
+ this.context.stroke();
419
+ }
420
+
421
+
422
+
423
+
424
+
425
+ this.context.globalAlpha = oldAlpha;
426
+
427
+ var obj = this;
428
+ this.img.onload = function ()
429
+ {
430
+ RGraph.redrawCanvas(obj.canvas);
431
+
432
+ obj.coords[0] = [
433
+ Math.round(obj.x),
434
+ Math.round(obj.y),
435
+ typeof properties.width === 'number' ? properties.width : this.width, typeof properties.height == 'number' ? properties.height : this.height
436
+ ];
437
+ }
438
+
439
+ RGraph.noShadow(this);
440
+
441
+
442
+
443
+
444
+ //
445
+ // Add custom text thats specified
446
+ //
447
+ RGraph.addCustomText(this);
448
+
449
+
450
+
451
+
452
+
453
+
454
+ //
455
+ // This installs the event listeners
456
+ //
457
+ RGraph.installEventListeners(this);
458
+
459
+
460
+ //
461
+ // Fire the onfirstdraw event
462
+ //
463
+ if (this.firstDraw) {
464
+ this.firstDraw = false;
465
+ RGraph.fireCustomEvent(this, 'onfirstdraw');
466
+ this.firstDrawFunc();
467
+ }
468
+
469
+
470
+
471
+
472
+ //
473
+ // Fire the draw event
474
+ //
475
+ RGraph.fireCustomEvent(this, 'ondraw');
476
+
477
+ return this;
478
+ };
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+ //
488
+ // Used in chaining. Runs a function there and then - not waiting for
489
+ // the events to fire (eg the onbeforedraw event)
490
+ //
491
+ // @param function func The function to execute
492
+ //
493
+ this.exec = function (func)
494
+ {
495
+ func(this);
496
+
497
+ return this;
498
+ };
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+ //
508
+ // The getObjectByXY() worker method
509
+ //
510
+ this.getObjectByXY = function (e)
511
+ {
512
+ var mouseXY = RGraph.getMouseXY(e);
513
+
514
+ if (this.getShape(e)) {
515
+ return this;
516
+ }
517
+ };
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+ //
527
+ // Not used by the class during creating the shape, but is used by event handlers
528
+ // to get the coordinates (if any) of the selected bar
529
+ //
530
+ // @param object e The event object
531
+ // @param object OPTIONAL You can pass in the bar object instead of the
532
+ // function using "this"
533
+ //
534
+ this.getShape = function (e)
535
+ {
536
+ var mouseXY = RGraph.getMouseXY(e),
537
+ mouseX = mouseXY[0],
538
+ mouseY = mouseXY[1];
539
+
540
+ if ( this.coords
541
+ && this.coords[0]
542
+ && mouseXY[0] >= this.coords[0][0]
543
+ && mouseXY[0] <= (this.coords[0][0] + this.coords[0][2])
544
+ && mouseXY[1] >= this.coords[0][1]
545
+ && mouseXY[1] <= (this.coords[0][1] + this.coords[0][3])) {
546
+
547
+ if (RGraph.parseTooltipText && properties.tooltips) {
548
+ var tooltip = RGraph.parseTooltipText(properties.tooltips, 0);
549
+ }
550
+
551
+ return {
552
+ object: this,
553
+ x: this.coords[0][0],
554
+ y: this.coords[0][1],
555
+ width: this.coords[0][2],
556
+ height: this.coords[0][3],
557
+ dataset: 0,
558
+ index: 0,
559
+ sequentialIndex: 0,
560
+ tooltip: typeof tooltip === 'string' ? tooltip : null
561
+ };
562
+ }
563
+
564
+ return null;
565
+ };
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+ //
575
+ // Each object type has its own Highlight() function which highlights the appropriate shape
576
+ //
577
+ // @param object shape The shape to highlight
578
+ //
579
+ this.highlight = function (shape)
580
+ {
581
+ if (properties.tooltipsHighlight) {
582
+ if (typeof properties.highlightStyle === 'function') {
583
+ (properties.highlightStyle)(shape);
584
+ } else {
585
+ this.path(
586
+ 'b r % % % % f % s %',
587
+ this.coords[0][0],this.coords[0][1],this.coords[0][2],this.coords[0][3],
588
+ properties.highlightFill, properties.highlightStroke
589
+ );
590
+ }
591
+ }
592
+ };
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+ //
602
+ // This allows for easy specification of gradients
603
+ //
604
+ this.parseColors = function ()
605
+ {
606
+ // Save the original colors so that they can be restored when the canvas is reset
607
+ if (this.original_colors.length === 0) {
608
+ this.original_colors.colorsBackground = RGraph.arrayClone(properties.colorsBackground);
609
+ this.original_colors.highlightStroke = RGraph.arrayClone(properties.highlightStroke);
610
+ this.original_colors.highlightFill = RGraph.arrayClone(properties.highlightFill);
611
+ }
612
+
613
+
614
+
615
+
616
+ //
617
+ // Parse various properties for colors
618
+ //
619
+ properties.colorsBackground = this.parseSingleColorForGradient(properties.colorsBackground);
620
+ properties.highlightStroke = this.parseSingleColorForGradient(properties.highlightStroke);
621
+ properties.highlightFill = this.parseSingleColorForGradient(properties.highlightFill);
622
+ };
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+ //
632
+ // Use this function to reset the object to the post-constructor state. Eg reset colors if
633
+ // need be etc
634
+ //
635
+ this.reset = function ()
636
+ {
637
+ };
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+ //
647
+ // This parses a single color value
648
+ //
649
+ this.parseSingleColorForGradient = function (color)
650
+ {
651
+ if (!color) {
652
+ return color;
653
+ }
654
+
655
+
656
+ if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
657
+
658
+ // Allow for JSON gradients
659
+ if (color.match(/^gradient\(({.*})\)$/i)) {
660
+ return RGraph.parseJSONGradient({object: this, def: RegExp.$1});
661
+ }
662
+
663
+ var parts = RegExp.$1.split(':'),
664
+ grad = this.context.createLinearGradient(this.x, this.y, this.x + this.img.width, this.y),
665
+ diff = 1 / (parts.length - 1);
666
+
667
+ grad.addColorStop(0, RGraph.trim(parts[0]));
668
+
669
+ for (var j=1; j<parts.length; ++j) {
670
+ grad.addColorStop(j * diff, RGraph.trim(parts[j]));
671
+ }
672
+ }
673
+
674
+ return grad ? grad : color;
675
+ };
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+ //
685
+ // Using a function to add events makes it easier to facilitate method chaining
686
+ //
687
+ // @param string type The type of even to add
688
+ // @param function func
689
+ //
690
+ this.on = function (type, func)
691
+ {
692
+ if (type.substr(0,2) !== 'on') {
693
+ type = 'on' + type;
694
+ }
695
+
696
+ if (typeof this[type] !== 'function') {
697
+ this[type] = func;
698
+ } else {
699
+ RGraph.addCustomEventListener(this, type, func);
700
+ }
701
+
702
+ return this;
703
+ };
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+ //
713
+ // This function runs once only
714
+ // (put at the end of the file (before any effects))
715
+ //
716
+ this.firstDrawFunc = function ()
717
+ {
718
+ };
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+ //
728
+ // This draws a rectangle for the border of the image with optional rounded corners
729
+ //
730
+ this.roundedRect = function (x, y, width, height, radius)
731
+ {
732
+ // Save the existing state of the canvas so that it can be restored later
733
+ this.context.save();
734
+
735
+ // Translate to the given X/Y coordinates
736
+ this.context.translate(x, y);
737
+
738
+ // Move to the center of the top horizontal line
739
+ this.context.moveTo(width / 2,0);
740
+
741
+ // Draw the rounded corners. The connecting lines in between them are drawn automatically
742
+ this.context.arcTo(width,0,width,height, Math.min(height / 2, radius));
743
+ this.context.arcTo(width, height, 0, height, Math.min(width / 2, radius));
744
+ this.context.arcTo(0, height, 0, 0, Math.min(height / 2, radius));
745
+ this.context.arcTo(0, 0, radius, 0, Math.min(width / 2, radius));
746
+
747
+ // Draw a line back to the start coordinates
748
+ this.context.lineTo(width / 2,0);
749
+
750
+ // Restore the state of the canvas to as it was before the save()
751
+ this.context.restore();
752
+ };
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+ //
762
+ //
763
+ //
764
+ this.drawBackgroundColor = function (borderRadius)
765
+ {
766
+ this.context.beginPath();
767
+ this.context.fillStyle = properties.backgroundColor;
768
+ this.roundedRect(
769
+ Math.round(this.x) - Math.round(this.context.lineWidth / 2),
770
+ Math.round(this.y) - Math.round(this.context.lineWidth / 2),
771
+ (properties.width || this.img.width) + this.context.lineWidth,
772
+ (properties.height || this.img.height) + this.context.lineWidth,
773
+ borderRadius
774
+ );
775
+ this.context.fill();
776
+ };
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+ //
786
+ // A worker function that handles Bar chart specific tooltip substitutions
787
+ //
788
+ this.tooltipSubstitutions = function (opt)
789
+ {
790
+ return {
791
+ index: 0,
792
+ dataset: 0,
793
+ sequentialIndex: 0,
794
+ value: null
795
+ };
796
+ };
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+ //
806
+ // This allows for static tooltip positioning
807
+ //
808
+ this.positionTooltipStatic = function (args)
809
+ {
810
+ var obj = args.object,
811
+ e = args.event,
812
+ tooltip = args.tooltip,
813
+ index = args.index,
814
+ canvasXY = RGraph.getCanvasXY(obj.canvas);
815
+
816
+ // Position the tooltip in the X direction
817
+ args.tooltip.style.left = (
818
+ canvasXY[0] // The X coordinate of the canvas
819
+ + this.x // The X coordinate of the image
820
+ + ((properties.width || this.img.width) / 2) // Add half of the image width
821
+ - (tooltip.offsetWidth / 2) // Subtract half of the tooltip width
822
+ + obj.properties.tooltipsOffsetx // Add any user defined offset
823
+ ) + 'px';
824
+
825
+ args.tooltip.style.top = (
826
+ canvasXY[1] // The Y coordinate of the canvas
827
+ - tooltip.offsetHeight // The height of the tooltip
828
+ + obj.properties.tooltipsOffsety // Add any user defined offset
829
+ + this.y // Add the Y coordinate
830
+ - 10 // An arbitrary amount
831
+ ) + 'px';
832
+ };
833
+
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+ //
842
+ // Objects are now always registered so that the chart is redrawn if need be.
843
+ //
844
+ RGraph.register(this);
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+ //
854
+ // This is the 'end' of the constructor so if the first argument
855
+ // contains configuration data - handle that.
856
+ //
857
+ RGraph.parseObjectStyleConfig(this, conf.options);
858
+ };