rgraph-rails 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +0 -1
- data/README.md +3 -3
- data/lib/rgraph-rails/version.rb +1 -1
- data/vendor/assets/javascripts/RGraph.bar.js +239 -3764
- data/vendor/assets/javascripts/RGraph.bipolar.js +115 -1986
- data/vendor/assets/javascripts/RGraph.common.annotate.js +35 -399
- data/vendor/assets/javascripts/RGraph.common.context.js +30 -600
- data/vendor/assets/javascripts/RGraph.common.core.js +403 -5187
- data/vendor/assets/javascripts/RGraph.common.csv.js +19 -275
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +35 -454
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +84 -1189
- data/vendor/assets/javascripts/RGraph.common.effects.js +90 -1548
- data/vendor/assets/javascripts/RGraph.common.key.js +54 -755
- data/vendor/assets/javascripts/RGraph.common.resizing.js +37 -567
- data/vendor/assets/javascripts/RGraph.common.sheets.js +29 -356
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +32 -614
- data/vendor/assets/javascripts/RGraph.common.zoom.js +14 -223
- data/vendor/assets/javascripts/RGraph.cornergauge.js +71 -0
- data/vendor/assets/javascripts/RGraph.drawing.background.js +35 -620
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +35 -576
- data/vendor/assets/javascripts/RGraph.drawing.image.js +52 -807
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +41 -717
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +37 -668
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +36 -563
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +40 -608
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +35 -597
- data/vendor/assets/javascripts/RGraph.drawing.text.js +34 -642
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +50 -809
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +51 -856
- data/vendor/assets/javascripts/RGraph.fuel.js +58 -964
- data/vendor/assets/javascripts/RGraph.funnel.js +55 -984
- data/vendor/assets/javascripts/RGraph.gantt.js +75 -1241
- data/vendor/assets/javascripts/RGraph.gauge.js +87 -1397
- data/vendor/assets/javascripts/RGraph.hbar.js +143 -2376
- data/vendor/assets/javascripts/RGraph.hprogress.js +80 -1397
- data/vendor/assets/javascripts/RGraph.line.js +241 -4162
- data/vendor/assets/javascripts/RGraph.meter.js +74 -1278
- metadata +3 -30
- data/vendor/assets/images/bg.png +0 -0
- data/vendor/assets/images/bullet.png +0 -0
- data/vendor/assets/images/facebook-large.png +0 -0
- data/vendor/assets/images/google-plus-large.png +0 -0
- data/vendor/assets/images/logo.png +0 -0
- data/vendor/assets/images/meter-image-sd-needle.png +0 -0
- data/vendor/assets/images/meter-image-sd.png +0 -0
- data/vendor/assets/images/meter-sketch-needle.png +0 -0
- data/vendor/assets/images/meter-sketch.png +0 -0
- data/vendor/assets/images/odometer-background.png +0 -0
- data/vendor/assets/images/rgraph.jpg +0 -0
- data/vendor/assets/images/title.png +0 -0
- data/vendor/assets/images/twitter-large.png +0 -0
- data/vendor/assets/javascripts/RGraph.modaldialog.js +0 -301
- data/vendor/assets/javascripts/RGraph.odo.js +0 -1265
- data/vendor/assets/javascripts/RGraph.pie.js +0 -2272
- data/vendor/assets/javascripts/RGraph.radar.js +0 -1847
- data/vendor/assets/javascripts/RGraph.rose.js +0 -1877
- data/vendor/assets/javascripts/RGraph.rscatter.js +0 -1425
- data/vendor/assets/javascripts/RGraph.scatter.js +0 -2970
- data/vendor/assets/javascripts/RGraph.semicircularprogress.js +0 -1015
- data/vendor/assets/javascripts/RGraph.thermometer.js +0 -1129
- data/vendor/assets/javascripts/RGraph.vprogress.js +0 -1452
- data/vendor/assets/javascripts/RGraph.waterfall.js +0 -1252
- data/vendor/assets/javascripts/financial-data.js +0 -1067
- data/vendor/assets/stylesheets/ModalDialog.css +0 -90
- data/vendor/assets/stylesheets/animations.css +0 -3347
- data/vendor/assets/stylesheets/website.css +0 -446
@@ -1,577 +1,36 @@
|
|
1
|
-
// version: 2016-06-04
|
2
|
-
/**
|
3
|
-
* o--------------------------------------------------------------------------------o
|
4
|
-
* | This file is part of the RGraph package - you can learn more at: |
|
5
|
-
* | |
|
6
|
-
* | http://www.rgraph.net |
|
7
|
-
* | |
|
8
|
-
* | RGraph is dual licensed under the Open Source GPL (General Public License) |
|
9
|
-
* | v2.0 license and a commercial license which means that you're not bound by |
|
10
|
-
* | the terms of the GPL. The commercial license starts at just 99 GBP and |
|
11
|
-
* | you can read about it here: |
|
12
|
-
* | |
|
13
|
-
* | http://www.rgraph.net/license |
|
14
|
-
* o--------------------------------------------------------------------------------o
|
15
|
-
*/
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Having this here means that the RGraph libraries can be included in any order, instead of you having
|
19
|
-
* to include the common core library first.
|
20
|
-
*/
|
21
1
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
var canvas = document.getElementById(id);
|
58
|
-
var x = arguments[1];
|
59
|
-
var y = arguments[2];
|
60
|
-
var radius = arguments[3];
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
this.id = id;
|
67
|
-
this.canvas = document.getElementById(this.id);
|
68
|
-
this.context = this.canvas.getContext('2d');
|
69
|
-
this.canvas.__object__ = this;
|
70
|
-
this.original_colors = [];
|
71
|
-
this.firstDraw = true; // After the first draw this will be false
|
72
|
-
|
73
|
-
|
74
|
-
/**
|
75
|
-
* Store the properties
|
76
|
-
*/
|
77
|
-
this.centerx = x;
|
78
|
-
this.centery = y;
|
79
|
-
this.radius = radius;
|
80
|
-
|
81
|
-
/**
|
82
|
-
* This defines the type of this shape
|
83
|
-
*/
|
84
|
-
this.type = 'drawing.circle';
|
85
|
-
|
86
|
-
|
87
|
-
/**
|
88
|
-
* This facilitates easy object identification, and should always be true
|
89
|
-
*/
|
90
|
-
this.isRGraph = true;
|
91
|
-
|
92
|
-
|
93
|
-
/**
|
94
|
-
* This adds a uid to the object that you can use for identification purposes
|
95
|
-
*/
|
96
|
-
this.uid = RGraph.CreateUID();
|
97
|
-
|
98
|
-
|
99
|
-
/**
|
100
|
-
* This adds a UID to the canvas for identification purposes
|
101
|
-
*/
|
102
|
-
this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Some example background properties
|
109
|
-
*/
|
110
|
-
this.properties =
|
111
|
-
{
|
112
|
-
'chart.strokestyle': 'rgba(0,0,0,0)',
|
113
|
-
'chart.fillstyle': 'red',
|
114
|
-
'chart.events.click': null,
|
115
|
-
'chart.events.mousemove': null,
|
116
|
-
'chart.shadow': false,
|
117
|
-
'chart.shadow.color': 'gray',
|
118
|
-
'chart.shadow.offsetx': 3,
|
119
|
-
'chart.shadow.offsety': 3,
|
120
|
-
'chart.shadow.blur': 5,
|
121
|
-
'chart.highlight.stroke': 'black',
|
122
|
-
'chart.highlight.fill': 'rgba(255,255,255,0.7)',
|
123
|
-
'chart.tooltips': null,
|
124
|
-
'chart.tooltips.highlight': true,
|
125
|
-
'chart.tooltips.event': 'onclick',
|
126
|
-
'chart.linewidth': 2,
|
127
|
-
'chart.clearto': 'rgba(0,0,0,0)'
|
128
|
-
}
|
129
|
-
|
130
|
-
/**
|
131
|
-
* A simple check that the browser has canvas support
|
132
|
-
*/
|
133
|
-
if (!this.canvas) {
|
134
|
-
alert('[DRAWING.CIRCLE] No canvas support');
|
135
|
-
return;
|
136
|
-
}
|
137
|
-
|
138
|
-
/**
|
139
|
-
* This can be used to store the coordinates of shapes on the graph
|
140
|
-
*/
|
141
|
-
this.coords = [[this.centerx, this.centery, this.radius]];
|
142
|
-
|
143
|
-
|
144
|
-
/**
|
145
|
-
* Create the dollar object so that functions can be added to them
|
146
|
-
*/
|
147
|
-
this.$0 = {};
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
|
153
|
-
* done already
|
154
|
-
*/
|
155
|
-
if (!this.canvas.__rgraph_aa_translated__) {
|
156
|
-
this.context.translate(0.5,0.5);
|
157
|
-
|
158
|
-
this.canvas.__rgraph_aa_translated__ = true;
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
// Short variable names
|
165
|
-
var RG = RGraph,
|
166
|
-
ca = this.canvas,
|
167
|
-
co = ca.getContext('2d'),
|
168
|
-
prop = this.properties,
|
169
|
-
pa2 = RG.path2,
|
170
|
-
win = window,
|
171
|
-
doc = document,
|
172
|
-
ma = Math
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
/**
|
177
|
-
* "Decorate" the object with the generic effects if the effects library has been included
|
178
|
-
*/
|
179
|
-
if (RG.Effects && typeof RG.Effects.decorate === 'function') {
|
180
|
-
RG.Effects.decorate(this);
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
/**
|
187
|
-
* A setter method for setting graph properties. It can be used like this: obj.Set('chart.strokestyle', '#666');
|
188
|
-
*
|
189
|
-
* @param name string The name of the property to set OR it can be a map
|
190
|
-
* of name/value settings like what you set in the constructor
|
191
|
-
*/
|
192
|
-
this.set =
|
193
|
-
this.Set = function (name)
|
194
|
-
{
|
195
|
-
var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
|
196
|
-
|
197
|
-
/**
|
198
|
-
* the number of arguments is only one and it's an
|
199
|
-
* object - parse it for configuration data and return.
|
200
|
-
*/
|
201
|
-
if (arguments.length === 1 && typeof name === 'object') {
|
202
|
-
RG.parseObjectStyleConfig(this, name);
|
203
|
-
return this;
|
204
|
-
}
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
/**
|
211
|
-
* This should be done first - prepend the property name with "chart." if necessary
|
212
|
-
*/
|
213
|
-
if (name.substr(0,6) != 'chart.') {
|
214
|
-
name = 'chart.' + name;
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
// Convert uppercase letters to dot+lower case letter
|
221
|
-
while(name.match(/([A-Z])/)) {
|
222
|
-
name = name.replace(/([A-Z])/, '.' + RegExp.$1.toLowerCase());
|
223
|
-
}
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
prop[name] = value;
|
231
|
-
|
232
|
-
return this;
|
233
|
-
};
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
/**
|
239
|
-
* A getter method for retrieving graph properties. It can be used like this: obj.Get('chart.strokestyle');
|
240
|
-
*
|
241
|
-
* @param name string The name of the property to get
|
242
|
-
*/
|
243
|
-
this.get =
|
244
|
-
this.Get = function (name)
|
245
|
-
{
|
246
|
-
/**
|
247
|
-
* This should be done first - prepend the property name with "chart." if necessary
|
248
|
-
*/
|
249
|
-
if (name.substr(0,6) != 'chart.') {
|
250
|
-
name = 'chart.' + name;
|
251
|
-
}
|
252
|
-
|
253
|
-
// Convert uppercase letters to dot+lower case letter
|
254
|
-
name = name.replace(/([A-Z])/g, function (str)
|
255
|
-
{
|
256
|
-
return '.' + String(RegExp.$1).toLowerCase()
|
257
|
-
});
|
258
|
-
|
259
|
-
return prop[name.toLowerCase()];
|
260
|
-
};
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
/**
|
266
|
-
* Draws the circle
|
267
|
-
*/
|
268
|
-
this.draw =
|
269
|
-
this.Draw = function ()
|
270
|
-
{
|
271
|
-
/**
|
272
|
-
* Fire the onbeforedraw event
|
273
|
-
*/
|
274
|
-
RG.FireCustomEvent(this, 'onbeforedraw');
|
275
|
-
|
276
|
-
|
277
|
-
/**
|
278
|
-
* Parse the colors. This allows for simple gradient syntax
|
279
|
-
*/
|
280
|
-
if (!this.colorsParsed) {
|
281
|
-
|
282
|
-
this.parseColors();
|
283
|
-
|
284
|
-
// Don't want to do this again
|
285
|
-
this.colorsParsed = true;
|
286
|
-
}
|
287
|
-
|
288
|
-
pa2(co, ['b', 'lw',prop['chart.linewidth']]);
|
289
|
-
|
290
|
-
if (prop['chart.shadow']) {
|
291
|
-
RG.SetShadow(this, prop['chart.shadow.color'], prop['chart.shadow.offsetx'], prop['chart.shadow.offsety'], prop['chart.shadow.blur']);
|
292
|
-
}
|
293
|
-
|
294
|
-
pa2(co, ['a',this.coords[0][0], this.coords[0][1], this.radius, 0, RGraph.TWOPI, false,'f',prop['chart.fillstyle'],'s', prop['chart.strokestyle']]);
|
295
|
-
|
296
|
-
// Must turn the shadow off before the fill is done
|
297
|
-
RG.NoShadow(this);
|
298
|
-
|
299
|
-
|
300
|
-
/**
|
301
|
-
* This installs the event listeners
|
302
|
-
*/
|
303
|
-
RG.InstallEventListeners(this);
|
304
|
-
|
305
|
-
|
306
|
-
/**
|
307
|
-
* Fire the onfirstdraw event
|
308
|
-
*/
|
309
|
-
if (this.firstDraw) {
|
310
|
-
RG.fireCustomEvent(this, 'onfirstdraw');
|
311
|
-
this.firstDraw = false;
|
312
|
-
this.firstDrawFunc();
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
/**
|
318
|
-
* Fire the ondraw event
|
319
|
-
*/
|
320
|
-
RG.FireCustomEvent(this, 'ondraw');
|
321
|
-
|
322
|
-
return this;
|
323
|
-
};
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
/**
|
328
|
-
* Used in chaining. Runs a function there and then - not waiting for
|
329
|
-
* the events to fire (eg the onbeforedraw event)
|
330
|
-
*
|
331
|
-
* @param function func The function to execute
|
332
|
-
*/
|
333
|
-
this.exec = function (func)
|
334
|
-
{
|
335
|
-
func(this);
|
336
|
-
|
337
|
-
return this;
|
338
|
-
};
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
/**
|
344
|
-
* The getObjectByXY() worker method
|
345
|
-
*/
|
346
|
-
this.getObjectByXY = function (e)
|
347
|
-
{
|
348
|
-
if (this.getShape(e)) {
|
349
|
-
return this;
|
350
|
-
}
|
351
|
-
};
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
/**
|
357
|
-
* Not used by the class during creating the shape, but is used by event handlers
|
358
|
-
* to get the coordinates (if any) of the selected bar
|
359
|
-
*
|
360
|
-
* @param object e The event object
|
361
|
-
* @param object OPTIONAL You can pass in the bar object instead of the
|
362
|
-
* function using "this"
|
363
|
-
*/
|
364
|
-
this.getShape = function (e)
|
365
|
-
{
|
366
|
-
var mouseXY = RGraph.getMouseXY(e);
|
367
|
-
var mouseX = mouseXY[0];
|
368
|
-
var mouseY = mouseXY[1];
|
369
|
-
|
370
|
-
if (RG.getHypLength(this.centerx, this.centery, mouseXY[0], mouseXY[1]) <= this.radius) {
|
371
|
-
|
372
|
-
return {
|
373
|
-
0: this, 1: this.centerx, 2: this.centery, 3: this.radius, 4: null, 5: 0,
|
374
|
-
'object': this, 'x': this.centerx, 'y': this.centery, 'radius': this.radius, 'index': 0, 'tooltip': prop['chart.tooltips'] ? prop['chart.tooltips'][0] : null
|
375
|
-
};
|
376
|
-
}
|
377
|
-
|
378
|
-
return null;
|
379
|
-
};
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
/**
|
385
|
-
* This function positions a tooltip when it is displayed
|
386
|
-
*
|
387
|
-
* @param obj object The chart object
|
388
|
-
* @param int x The X coordinate specified for the tooltip
|
389
|
-
* @param int y The Y coordinate specified for the tooltip
|
390
|
-
* @param object tooltip The tooltips DIV element
|
391
|
-
*/
|
392
|
-
this.positionTooltip = function (obj, x, y, tooltip, idx)
|
393
|
-
{
|
394
|
-
var canvasXY = RG.getCanvasXY(obj.canvas);
|
395
|
-
var width = tooltip.offsetWidth;
|
396
|
-
var height = tooltip.offsetHeight;
|
397
|
-
var radius = this.radius;
|
398
|
-
var mouseXY = RG.getMouseXY(window.event);
|
399
|
-
|
400
|
-
// Set the top position
|
401
|
-
tooltip.style.left = 0;
|
402
|
-
tooltip.style.top = canvasXY[1] + this.coords[0][1] - (height / 2) - this.radius + 'px';
|
403
|
-
|
404
|
-
// Set the top position
|
405
|
-
tooltip.style.left = 0;
|
406
|
-
tooltip.style.top = window.event.pageY - height - 5 + 'px';
|
407
|
-
|
408
|
-
// By default any overflow is hidden
|
409
|
-
tooltip.style.overflow = '';
|
410
|
-
|
411
|
-
// Reposition the tooltip if at the edges:
|
412
|
-
|
413
|
-
// LEFT edge
|
414
|
-
if (canvasXY[0] + mouseXY[0] - (width / 2) < 0) {
|
415
|
-
tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.1) + 'px';
|
416
|
-
|
417
|
-
// RIGHT edge
|
418
|
-
} else if (canvasXY[0] + mouseXY[0] + (width / 2) > doc.body.offsetWidth) {
|
419
|
-
tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.9) + 'px';
|
420
|
-
|
421
|
-
// Default positioning - CENTERED
|
422
|
-
} else {
|
423
|
-
tooltip.style.left = canvasXY[0] + mouseXY[0] - (width / 2) + 'px';
|
424
|
-
}
|
425
|
-
};
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
/**
|
431
|
-
* Each object type has its own Highlight() function which highlights the appropriate shape
|
432
|
-
*
|
433
|
-
* @param object shape The shape to highlight
|
434
|
-
*/
|
435
|
-
this.highlight =
|
436
|
-
this.Highlight = function (shape)
|
437
|
-
{
|
438
|
-
if (prop['chart.tooltips.highlight']) {
|
439
|
-
if (typeof prop['chart.highlight.style'] === 'function') {
|
440
|
-
(prop['chart.highlight.style'])(shape);
|
441
|
-
} else {
|
442
|
-
pa2(co, ['b','a',this.centerx, this.centery, this.radius + 0.5, 0, RGraph.TWOPI, false,'f',prop['chart.highlight.fill'],'s',prop['chart.highlight.stroke']]);
|
443
|
-
}
|
444
|
-
}
|
445
|
-
};
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
/**
|
451
|
-
* This allows for easy specification of gradients
|
452
|
-
*/
|
453
|
-
this.parseColors = function ()
|
454
|
-
{
|
455
|
-
|
456
|
-
// Save the original colors so that they can be restored when the canvas is reset
|
457
|
-
if (this.original_colors.length === 0) {
|
458
|
-
this.original_colors['chart.fillstyle'] = RG.array_clone(prop['chart.fillstyle']);
|
459
|
-
this.original_colors['chart.strokestyle'] = RG.array_clone(prop['chart.strokestyle']);
|
460
|
-
this.original_colors['chart.highlight.stroke'] = RG.array_clone(prop['chart.highlight.stroke']);
|
461
|
-
this.original_colors['chart.highlight.fill'] = RG.array_clone(prop['chart.highlight.fill']);
|
462
|
-
}
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
/**
|
468
|
-
* Parse various properties for colors
|
469
|
-
*/
|
470
|
-
prop['chart.fillstyle'] = this.parseSingleColorForGradient(prop['chart.fillstyle']);
|
471
|
-
prop['chart.strokestyle'] = this.parseSingleColorForGradient(prop['chart.strokestyle']);
|
472
|
-
prop['chart.highlight.stroke'] = this.parseSingleColorForGradient(prop['chart.highlight.stroke']);
|
473
|
-
prop['chart.highlight.fill'] = this.parseSingleColorForGradient(prop['chart.highlight.fill']);
|
474
|
-
};
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
/**
|
480
|
-
* Use this function to reset the object to the post-constructor state. Eg reset colors if
|
481
|
-
* need be etc
|
482
|
-
*/
|
483
|
-
this.reset = function ()
|
484
|
-
{
|
485
|
-
};
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
/**
|
491
|
-
* This parses a single color value
|
492
|
-
*/
|
493
|
-
this.parseSingleColorForGradient = function (color)
|
494
|
-
{
|
495
|
-
if (!color) {
|
496
|
-
return color;
|
497
|
-
}
|
498
|
-
|
499
|
-
if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
|
500
|
-
|
501
|
-
var parts = RegExp.$1.split(':');
|
502
|
-
|
503
|
-
// Create the gradient
|
504
|
-
var grad = co.createRadialGradient(this.centerx, this.centery, 0, this.centerx, this.centery, this.radius);
|
505
|
-
|
506
|
-
var diff = 1 / (parts.length - 1);
|
507
|
-
|
508
|
-
//grad.addColorStop(0, RG.trim(parts[0]));
|
509
|
-
|
510
|
-
for (var j=0; j<parts.length; j+=1) {
|
511
|
-
grad.addColorStop(j * diff, RG.trim(parts[j]));
|
512
|
-
}
|
513
|
-
}
|
514
|
-
|
515
|
-
return grad ? grad : color;
|
516
|
-
};
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
/**
|
522
|
-
* Using a function to add events makes it easier to facilitate method chaining
|
523
|
-
*
|
524
|
-
* @param string type The type of even to add
|
525
|
-
* @param function func
|
526
|
-
*/
|
527
|
-
this.on = function (type, func)
|
528
|
-
{
|
529
|
-
if (type.substr(0,2) !== 'on') {
|
530
|
-
type = 'on' + type;
|
531
|
-
}
|
532
|
-
|
533
|
-
this[type] = func;
|
534
|
-
|
535
|
-
return this;
|
536
|
-
};
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
/**
|
542
|
-
* This function runs once only
|
543
|
-
* (put at the end of the file (before any effects))
|
544
|
-
*/
|
545
|
-
this.firstDrawFunc = function ()
|
546
|
-
{
|
547
|
-
};
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
RG.att(ca);
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
/**
|
563
|
-
* Objects are now always registered so that the chart is redrawn if need be.
|
564
|
-
*/
|
565
|
-
RG.Register(this);
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
/**
|
571
|
-
* This is the 'end' of the constructor so if the first argument
|
572
|
-
* contains configuration data - handle that.
|
573
|
-
*/
|
574
|
-
if (parseConfObjectForOptions) {
|
575
|
-
RG.parseObjectStyleConfig(this, conf.options);
|
576
|
-
}
|
577
|
-
};
|
2
|
+
RGraph=window.RGraph||{isRGraph:true};RGraph.Drawing=RGraph.Drawing||{};RGraph.Drawing.Circle=function(conf)
|
3
|
+
{if(typeof conf==='object'&&typeof conf.x==='number'&&typeof conf.y==='number'&&typeof conf.radius==='number'&&typeof conf.id==='string'){var id=conf.id
|
4
|
+
var canvas=document.getElementById(id);var x=conf.x;var y=conf.y;var radius=conf.radius;var parseConfObjectForOptions=true;}else{var id=conf;var canvas=document.getElementById(id);var x=arguments[1];var y=arguments[2];var radius=arguments[3];}
|
5
|
+
this.id=id;this.canvas=document.getElementById(this.id);this.context=this.canvas.getContext('2d');this.canvas.__object__=this;this.original_colors=[];this.firstDraw=true;this.centerx=x;this.centery=y;this.radius=radius;this.type='drawing.circle';this.isRGraph=true;this.uid=RGraph.CreateUID();this.canvas.uid=this.canvas.uid?this.canvas.uid:RGraph.CreateUID();this.properties={'chart.strokestyle':'rgba(0,0,0,0)','chart.fillstyle':'red','chart.events.click':null,'chart.events.mousemove':null,'chart.shadow':false,'chart.shadow.color':'gray','chart.shadow.offsetx':3,'chart.shadow.offsety':3,'chart.shadow.blur':5,'chart.highlight.stroke':'black','chart.highlight.fill':'rgba(255,255,255,0.7)','chart.tooltips':null,'chart.tooltips.highlight':true,'chart.tooltips.event':'onclick','chart.linewidth':2,'chart.clearto':'rgba(0,0,0,0)'}
|
6
|
+
if(!this.canvas){alert('[DRAWING.CIRCLE] No canvas support');return;}
|
7
|
+
this.coords=[[this.centerx,this.centery,this.radius]];this.$0={};if(!this.canvas.__rgraph_aa_translated__){this.context.translate(0.5,0.5);this.canvas.__rgraph_aa_translated__=true;}
|
8
|
+
var RG=RGraph,ca=this.canvas,co=ca.getContext('2d'),prop=this.properties,pa2=RG.path2,win=window,doc=document,ma=Math
|
9
|
+
if(RG.Effects&&typeof RG.Effects.decorate==='function'){RG.Effects.decorate(this);}
|
10
|
+
this.set=this.Set=function(name)
|
11
|
+
{var value=typeof arguments[1]==='undefined'?null:arguments[1];if(arguments.length===1&&typeof name==='object'){RG.parseObjectStyleConfig(this,name);return this;}
|
12
|
+
if(name.substr(0,6)!='chart.'){name='chart.'+name;}
|
13
|
+
while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
|
14
|
+
prop[name]=value;return this;};this.get=this.Get=function(name)
|
15
|
+
{if(name.substr(0,6)!='chart.'){name='chart.'+name;}
|
16
|
+
while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
|
17
|
+
return prop[name.toLowerCase()];};this.draw=this.Draw=function()
|
18
|
+
{RG.FireCustomEvent(this,'onbeforedraw');if(!this.colorsParsed){this.parseColors();this.colorsParsed=true;}
|
19
|
+
pa2(co,['b','lw',prop['chart.linewidth']]);if(prop['chart.shadow']){RG.SetShadow(this,prop['chart.shadow.color'],prop['chart.shadow.offsetx'],prop['chart.shadow.offsety'],prop['chart.shadow.blur']);}
|
20
|
+
pa2(co,['a',this.coords[0][0],this.coords[0][1],this.radius,0,RGraph.TWOPI,false,'f',prop['chart.fillstyle'],'s',prop['chart.strokestyle']]);RG.NoShadow(this);RG.InstallEventListeners(this);if(this.firstDraw){RG.fireCustomEvent(this,'onfirstdraw');this.firstDraw=false;this.firstDrawFunc();}
|
21
|
+
RG.FireCustomEvent(this,'ondraw');return this;};this.exec=function(func)
|
22
|
+
{func(this);return this;};this.getObjectByXY=function(e)
|
23
|
+
{if(this.getShape(e)){return this;}};this.getShape=function(e)
|
24
|
+
{var mouseXY=RGraph.getMouseXY(e);var mouseX=mouseXY[0];var mouseY=mouseXY[1];if(RG.getHypLength(this.centerx,this.centery,mouseXY[0],mouseXY[1])<=this.radius){return{0:this,1:this.centerx,2:this.centery,3:this.radius,4:null,5:0,'object':this,'x':this.centerx,'y':this.centery,'radius':this.radius,'index':0,'tooltip':prop['chart.tooltips']?prop['chart.tooltips'][0]:null};}
|
25
|
+
return null;};this.highlight=this.Highlight=function(shape)
|
26
|
+
{if(prop['chart.tooltips.highlight']){if(typeof prop['chart.highlight.style']==='function'){(prop['chart.highlight.style'])(shape);}else{pa2(co,['b','a',this.centerx,this.centery,this.radius+0.5,0,RGraph.TWOPI,false,'f',prop['chart.highlight.fill'],'s',prop['chart.highlight.stroke']]);}}};this.parseColors=function()
|
27
|
+
{if(this.original_colors.length===0){this.original_colors['chart.fillstyle']=RG.array_clone(prop['chart.fillstyle']);this.original_colors['chart.strokestyle']=RG.array_clone(prop['chart.strokestyle']);this.original_colors['chart.highlight.stroke']=RG.array_clone(prop['chart.highlight.stroke']);this.original_colors['chart.highlight.fill']=RG.array_clone(prop['chart.highlight.fill']);}
|
28
|
+
prop['chart.fillstyle']=this.parseSingleColorForGradient(prop['chart.fillstyle']);prop['chart.strokestyle']=this.parseSingleColorForGradient(prop['chart.strokestyle']);prop['chart.highlight.stroke']=this.parseSingleColorForGradient(prop['chart.highlight.stroke']);prop['chart.highlight.fill']=this.parseSingleColorForGradient(prop['chart.highlight.fill']);};this.reset=function()
|
29
|
+
{};this.parseSingleColorForGradient=function(color)
|
30
|
+
{if(!color){return color;}
|
31
|
+
if(typeof color==='string'&&color.match(/^gradient\((.*)\)$/i)){var parts=RegExp.$1.split(':');var grad=co.createRadialGradient(this.centerx,this.centery,0,this.centerx,this.centery,this.radius);var diff=1/(parts.length-1);for(var j=0;j<parts.length;j+=1){grad.addColorStop(j*diff,RG.trim(parts[j]));}}
|
32
|
+
return grad?grad:color;};this.on=function(type,func)
|
33
|
+
{if(type.substr(0,2)!=='on'){type='on'+type;}
|
34
|
+
if(typeof this[type]!=='function'){this[type]=func;}else{RG.addCustomEventListener(this,type,func);}
|
35
|
+
return this;};this.firstDrawFunc=function()
|
36
|
+
{};RG.att(ca);RG.Register(this);if(parseConfObjectForOptions){RG.parseObjectStyleConfig(this,conf.options);}};
|