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
@@ -0,0 +1,1006 @@
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
+ RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true};
13
+
14
+ //
15
+ // The Segmented Donut chart constructor
16
+ //
17
+ RGraph.Segmented = function (conf)
18
+ {
19
+ var id = conf.id,
20
+ canvas = document.getElementById(id),
21
+ min = conf.min,
22
+ max = conf.max,
23
+ value = conf.value;
24
+
25
+ // id, min, max, value
26
+ // Get the canvas and context objects
27
+ this.id = id;
28
+ this.canvas = canvas;
29
+ this.context = this.canvas.getContext ? this.canvas.getContext("2d", {alpha: (typeof id === 'object' && id.alpha === false) ? false : true}) : null;
30
+ this.canvas.__object__ = this;
31
+ this.type = 'segmented';
32
+ this.min = RGraph.stringsToNumbers(min);
33
+ this.max = RGraph.stringsToNumbers(max);
34
+ this.value = RGraph.stringsToNumbers(value);
35
+ this.centerx = null;
36
+ this.centery = null;
37
+ this.radius = null;
38
+ this.isRGraph = true;
39
+ this.isrgraph = true;
40
+ this.rgraph = true;
41
+ this.currentValue = null;
42
+ this.uid = RGraph.createUID();
43
+ this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID();
44
+ this.colorsParsed = false;
45
+ this.coordsText = [];
46
+ this.original_colors = [];
47
+ this.firstDraw = true; // After the first draw this will be false
48
+ this.stopAnimationRequested = false;// Used to control the animations
49
+
50
+ //
51
+ // If the value is zero set it to very
52
+ // slightly more than zero so the meter
53
+ // is drawn correctly.
54
+ //
55
+ // Likewise with the maximum value
56
+ //
57
+ if (this.value <= 0.0000001) {
58
+ this.value = 0.0000001;
59
+ }
60
+
61
+
62
+
63
+ // Various config type stuff
64
+ this.properties =
65
+ {
66
+ radius: null,
67
+ centerx: null,
68
+ centery: null,
69
+ width: null,
70
+
71
+ marginLeft: 15,
72
+ marginRight: 15,
73
+ marginTop: 15,
74
+ marginBottom: 15,
75
+
76
+ backgroundColor: 'black',
77
+ colors: ['red','#ddd'],
78
+
79
+ textFont: 'Arial, Verdana, sans-serif',
80
+ textSize: null,
81
+ textColor: 'gray',
82
+ textBold: false,
83
+ textItalic: false,
84
+ textAccessible: false,
85
+ textAccessibleOverflow: 'visible',
86
+ textAccessiblePointerevents: false,
87
+ text: null,
88
+
89
+ labelsCenterFont: null,
90
+ labelsCenterSize: null,
91
+ labelsCenterColor: null,
92
+ labelsCenterBold: null,
93
+ labelsCenterItalic: null,
94
+ labelsCenterUnitsPre: '',
95
+ labelsCenterUnitsPost: '',
96
+ labelsCenterDecimals: 0,
97
+ labelsCenterPoint: '.',
98
+ labelsCenterThousand: ',',
99
+ labelsCenterSpecific: '',
100
+ labelsCenterSpecificFormattedDecimals: 0,
101
+ labelsCenterSpecificFormattedPoint: '.',
102
+ labelsCenterSpecificFormattedThousand: ',',
103
+ labelsCenterSpecificFormattedUnitsPre: '',
104
+ labelsCenterSpecificFormattedUnitsPost: '',
105
+ labelsCenterOffsetx: 0,
106
+ labelsCenterOffsety: 0,
107
+
108
+ radialsCount: 36,
109
+
110
+ contextmenu: null,
111
+
112
+ annotatable: false,
113
+ annotatableColor: 'black',
114
+
115
+ adjustable: false,
116
+
117
+ effectRoundrobinMultiplier: 1,
118
+
119
+ clearto: 'rgba(0,0,0,0)'
120
+ }
121
+
122
+
123
+ // Check for support
124
+ if (!this.canvas) {
125
+ alert('[SDONUT] No canvas support');
126
+ return;
127
+ }
128
+
129
+
130
+
131
+
132
+ // Easy access to properties and the path function
133
+ var properties = this.properties;
134
+ this.path = RGraph.pathObjectFunction;
135
+
136
+
137
+
138
+ //
139
+ // "Decorate" the object with the generic effects if the effects library has been included
140
+ //
141
+ if (RGraph.Effects && typeof RGraph.Effects.decorate === 'function') {
142
+ RGraph.Effects.decorate(this);
143
+ }
144
+
145
+
146
+
147
+ // Add the responsive method. This method resides in the common file.
148
+ this.responsive = RGraph.responsive;
149
+
150
+
151
+ //
152
+ // A setter
153
+ //
154
+ this.set = function (name)
155
+ {
156
+ var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
157
+
158
+ // the number of arguments is only one and it's an
159
+ // object - parse it for configuration data and return.
160
+ if (arguments.length === 1 && typeof arguments[0] === 'object') {
161
+ for (i in arguments[0]) {
162
+ if (typeof i === 'string') {
163
+ this.set(i, arguments[0][i]);
164
+ }
165
+ }
166
+
167
+ return this;
168
+ }
169
+
170
+ properties[name] = value;
171
+
172
+ return this;
173
+ };
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+ //
183
+ // A getter
184
+ //
185
+ // @param name string The name of the property to get
186
+ //
187
+ this.get = function (name)
188
+ {
189
+ return properties[name];
190
+ };
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+ //
200
+ // The function you call to draw the bar chart
201
+ //
202
+ this.draw = function ()
203
+ {
204
+ //
205
+ // Fire the onbeforedraw event
206
+ //
207
+ RGraph.fireCustomEvent(this, 'onbeforedraw');
208
+
209
+
210
+
211
+ // Translate half a pixel for antialiasing purposes - but only if it hasn't been
212
+ // done already
213
+ //
214
+ // MUST be the first thing done!
215
+ //
216
+ if (!this.canvas.__rgraph_aa_translated__) {
217
+ this.context.translate(0.5,0.5);
218
+
219
+ this.canvas.__rgraph_aa_translated__ = true;
220
+ }
221
+
222
+
223
+
224
+
225
+ //
226
+ // Constrain the value to be within the min and max
227
+ //
228
+ if (this.value > this.max) this.value = this.max;
229
+ if (this.value < this.min) this.value = this.min;
230
+
231
+ //
232
+ // Set the current value
233
+ //
234
+ this.currentValue = this.value;
235
+
236
+
237
+
238
+ //
239
+ // Make the margins easy to access
240
+ //
241
+ this.marginLeft = properties.marginLeft;
242
+ this.marginRight = properties.marginRight;
243
+ this.marginTop = properties.marginTop;
244
+ this.marginBottom = properties.marginBottom;
245
+
246
+ this.centerx = ((this.canvas.width - this.marginLeft - this.marginRight) / 2) + this.marginLeft;
247
+ this.centery = ((this.canvas.height - this.marginBottom - this.marginTop) / 2) + this.marginTop;
248
+ this.radius = Math.min(
249
+ (this.canvas.width - this.marginLeft - this.marginRight) / 2,
250
+ (this.canvas.height - this.marginTop - this.marginBottom) / 2
251
+ );
252
+
253
+ //
254
+ // Stop this growing uncontrollably
255
+ //
256
+ this.coordsText = [];
257
+
258
+
259
+
260
+ //
261
+ // Custom centerx, centery and radius
262
+ //
263
+ if (typeof properties.centerx === 'number') this.centerx = properties.centerx;
264
+ if (typeof properties.centery === 'number') this.centery = properties.centery;
265
+ if (typeof properties.radius === 'number') this.radius = properties.radius;
266
+
267
+
268
+ //
269
+ // Parse the colors for gradients. Its down here so that the center X/Y can be used
270
+ //
271
+ if (!this.colorsParsed) {
272
+
273
+ this.parseColors();
274
+
275
+ // Don't want to do this again
276
+ this.colorsParsed = true;
277
+ }
278
+
279
+
280
+ //
281
+ // Draw the meter and its label
282
+ //
283
+ this.drawMeter();
284
+ this.drawLabel();
285
+
286
+ //
287
+ // Setup the context menu if required
288
+ //
289
+ if (properties.contextmenu) {
290
+ RGraph.showContext(this);
291
+ }
292
+
293
+
294
+
295
+
296
+ //
297
+ // Add custom text thats specified
298
+ //
299
+ RGraph.addCustomText(this);
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+ //
309
+ // This installs the event listeners
310
+ //
311
+ RGraph.installEventListeners(this);
312
+
313
+
314
+
315
+ //
316
+ // Fire the onfirstdraw event
317
+ //
318
+ if (this.firstDraw) {
319
+ this.firstDraw = false;
320
+ RGraph.fireCustomEvent(this, 'onfirstdraw');
321
+ this.firstDrawFunc();
322
+ }
323
+
324
+
325
+
326
+
327
+ //
328
+ // Fire the RGraph draw event
329
+ //
330
+ RGraph.fireCustomEvent(this, 'ondraw');
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+ //
341
+ // Install any inline responsive configuration. This
342
+ // should be last in the draw function - even after
343
+ // the draw events.
344
+ //
345
+ RGraph.installInlineResponsive(this);
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+ return this;
358
+ };
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+ //
368
+ // Used in chaining. Runs a function there and then - not waiting for
369
+ // the events to fire (eg the onbeforedraw event)
370
+ //
371
+ // @param function func The function to execute
372
+ //
373
+ this.exec = function (func)
374
+ {
375
+ func(this);
376
+
377
+ return this;
378
+ };
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+ //
388
+ // Draws the meter
389
+ //
390
+ this.drawMeter = function ()
391
+ {
392
+ var width = typeof properties.width === 'number' ? properties.width : this.radius / 2;
393
+
394
+ // Allow for +/-xx style width
395
+ if (typeof properties.width === 'string') {
396
+ width += Number(properties.width);
397
+ }
398
+
399
+
400
+ // First thing to do is clear the canvas to the backgroundColor
401
+ if (properties.backgroundColor) {
402
+ this.path(
403
+ 'fs % fr -5 -5 % %',
404
+ properties.backgroundColor,
405
+ this.canvas.width + 10,
406
+ this.canvas.height + 10
407
+ );
408
+ }
409
+
410
+
411
+ // Draw the circle that becomes the non-indicator part of the chart
412
+ var degrees = 360 / properties.radialsCount;
413
+ degrees /= 2,
414
+ colored = Math.round(((this.value - this.min) / (this.max - this.min)) * (properties.radialsCount * 2));
415
+
416
+ //
417
+ // Draw the background segments
418
+ //
419
+ for (var i=1; i<(properties.radialsCount * 2); i+=2) {
420
+
421
+ var start = (RGraph.toRadians( (i * degrees) - (degrees / 2)) * properties.effectRoundrobinMultiplier) - RGraph.HALFPI,
422
+ end = (RGraph.toRadians( (i * degrees) + (degrees / 2)) * properties.effectRoundrobinMultiplier) - RGraph.HALFPI;
423
+
424
+
425
+ this.path(
426
+
427
+ 'b a % % % % % false a % % % % % true f % ',
428
+
429
+ this.centerx,
430
+ this.centery,
431
+ this.radius,
432
+ start,
433
+ end,
434
+
435
+ this.centerx,
436
+ this.centery,
437
+ this.radius - width,
438
+ end,
439
+ start,
440
+
441
+ i >= colored ? properties.colors[1] : properties.colors[0]
442
+ );
443
+ }
444
+
445
+
446
+ // Reset the linewidth back to 1
447
+ this.context.lineWidth = 1;
448
+ };
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+ //
458
+ // This function draws the text label
459
+ //
460
+ this.drawLabel = function ()
461
+ {
462
+ //
463
+ // Set the text size
464
+ //
465
+ if (RGraph.isNull(properties.textSize)) {
466
+ properties.textSize = this.radius / 2.5;
467
+ }
468
+
469
+
470
+ // Get the text configuration
471
+ var textConf = RGraph.getTextConf({
472
+ object: this,
473
+ prefix: 'labelsCenter'
474
+ });
475
+
476
+
477
+
478
+ //
479
+ // If the xaxisLabels option is a string then turn it
480
+ // into an array.
481
+ //
482
+ if (properties.labelsCenterSpecific && properties.labelsCenterSpecific.length) {
483
+
484
+ // Label substitution
485
+ //
486
+ properties.labelsCenterSpecific = RGraph.labelSubstitution({
487
+ object: this,
488
+ text: properties.labelsCenterSpecific,
489
+ index: 0,
490
+ value: this.value,
491
+ decimals: properties.labelsCenterSpecificFormattedDecimals || 0,
492
+ unitsPre: properties.labelsCenterSpecificFormattedUnitsPre || '',
493
+ unitsPost: properties.labelsCenterSpecificFormattedUnitsPost || '',
494
+ thousand: properties.labelsCenterSpecificFormattedThousand || ',',
495
+ point: properties.labelsCenterSpecificFormattedPoint || '.'
496
+ });
497
+ }
498
+
499
+
500
+
501
+
502
+ // Draw the large center label
503
+ RGraph.text({
504
+
505
+ object: this,
506
+
507
+ font: textConf.font,
508
+ italic: textConf.italic,
509
+ bold: textConf.bold,
510
+ size: textConf.size,
511
+ color: textConf.color,
512
+
513
+ x: this.centerx + properties.labelsCenterOffsetx,
514
+ y: this.centery + properties.labelsCenterOffsety,
515
+
516
+ text: properties.labelsCenterSpecific ? properties.labelsCenterSpecific : RGraph.numberFormat({
517
+ object: this,
518
+ number: (this.value * properties.effectRoundrobinMultiplier).toFixed(properties.labelsCenterDecimals),
519
+ unitspre: properties.labelsCenterUnitsPre,
520
+ unitspost: properties.labelsCenterUnitsPost,
521
+ point: properties.labelsCenterPoint,
522
+ thousand: properties.labelsCenterThousand
523
+ }),
524
+
525
+ halign: 'center',
526
+ valign: 'center',
527
+ accessible: properties.textAccessible
528
+ });
529
+ };
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+ //
539
+ // A placeholder function
540
+ //
541
+ // @param object The event object
542
+ //
543
+ this.getShape = function (e) {};
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+ //
553
+ // This function returns the pertinent value for a particular click (or other mouse event)
554
+ //
555
+ // @param obj e The event object
556
+ //
557
+ this.getValue = function (e)
558
+ {
559
+ if (typeof e === 'number') {
560
+ angle = e;
561
+ } else {
562
+ var mouseXY = RGraph.getMouseXY(e);
563
+
564
+ var angle = RGraph.getAngleByXY(
565
+ this.centerx,
566
+ this.centery,
567
+ mouseXY[0],
568
+ mouseXY[1]
569
+ );
570
+ }
571
+
572
+ // Adjust the angle because canvas angles
573
+ // start at the east axis
574
+ angle += RGraph.HALFPI;
575
+ if (angle > RGraph.TWOPI) {
576
+ angle -= RGraph.TWOPI;
577
+ }
578
+
579
+ // Calculate the value based on the angle and min/max values
580
+ var value = ((angle / RGraph.TWOPI) * (this.max - this.min)) + this.min;
581
+
582
+ // Ensure that the value is in range
583
+ value = Math.max(value, this.min);
584
+ value = Math.min(value, this.max);
585
+
586
+ return value;
587
+ };
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+ //
597
+ // The getObjectByXY() worker method. Don't call this call:
598
+ //
599
+ // RGraph.ObjectRegistry.getObjectByXY(e)
600
+ //
601
+ // @param object e The event object
602
+ //
603
+ this.getObjectByXY = function (e)
604
+ {
605
+ var mouseXY = RGraph.getMouseXY(e),
606
+ width = properties.width;
607
+
608
+ // Work out the radius
609
+ var radius = RGraph.getHypLength(
610
+ this.centerx,
611
+ this.centery,
612
+ mouseXY[0],
613
+ mouseXY[1]
614
+ );
615
+
616
+ if (typeof width === 'string') {
617
+ width = (this.radius / 2) + parseFloat(width);
618
+
619
+ } else if (RGraph.isNull(width)) {
620
+ width = this.radius / 2;
621
+ }
622
+
623
+ if (radius > this.radius || radius < (this.radius - width) ) {
624
+ return null;
625
+ }
626
+
627
+ return this;
628
+ };
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+ //
638
+ // This method handles the adjusting calculation for when the mouse is moved
639
+ //
640
+ // @param object e The event object
641
+ //
642
+ this.adjusting_mousemove = function (e)
643
+ {
644
+ //
645
+ // Handle adjusting for the Bar
646
+ //
647
+ if (properties.adjustable && RGraph.Registry.get('adjusting') && RGraph.Registry.get('adjusting').uid == this.uid) {
648
+ this.value = this.getValue(e);
649
+ RGraph.clear(this.canvas);
650
+ RGraph.redrawCanvas(this.canvas);
651
+ RGraph.fireCustomEvent(this, 'onadjust');
652
+ }
653
+ };
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+ //
663
+ // This method returns the appropriate angle for a value
664
+ //
665
+ // @param number value The value
666
+ //
667
+ this.getAngle = function (value)
668
+ {
669
+ if (typeof value === 'number') {
670
+ // Higher than max
671
+ if (value > this.max || value < this.min) {
672
+ return null;
673
+ }
674
+
675
+ var angle = (((value - this.min) / (this.max - this.min)) * RGraph.TWOPI) - RGraph.HALFPI;
676
+
677
+ if (value === this.max) angle -= 0.00001;
678
+ if (value === this.min) angle += 0.00001;
679
+
680
+ } else {
681
+
682
+ var mouseX = value.offsetX,
683
+ mouseY = value.offsetY;
684
+
685
+ var angle = RGraph.getAngleByXY({
686
+ cx: this.centerx,
687
+ cy: this.centery,
688
+ x: mouseX,
689
+ y: mouseY
690
+ });
691
+
692
+ if (angle > (RGraph.PI + RGraph.HALFPI)) {
693
+ angle -= RGraph.TWOPI;
694
+ }
695
+ }
696
+
697
+ return angle;
698
+ };
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+ //
708
+ // This allows for easy specification of gradients
709
+ //
710
+ this.parseColors = function ()
711
+ {
712
+ // Save the original colors so that they can be restored when the canvas is reset
713
+ if (this.original_colors.length === 0) {
714
+ this.original_colors.backgroundColor = RGraph.arrayClone(properties.backgroundColor);
715
+ this.original_colors.colors = RGraph.arrayClone(properties.colors);
716
+ }
717
+
718
+ // Parse the background color
719
+ properties.backgroundColor = this.parseSingleColorForGradient(properties.backgroundColor);
720
+
721
+
722
+ // Parse colors
723
+ var colors = properties.colors;
724
+
725
+ if (colors && colors.length) {
726
+ for (var i=0; i<colors.length; ++i) {
727
+ colors[i] = this.parseSingleColorForGradient(colors[i]);
728
+ }
729
+ }
730
+ };
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+ //
740
+ // Use this function to reset the object to the post-constructor state. Eg reset colors if
741
+ // need be etc
742
+ //
743
+ this.reset = function ()
744
+ {
745
+ };
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+ //
755
+ // This parses a single color value
756
+ //
757
+ this.parseSingleColorForGradient = function (color)
758
+ {
759
+ if (!color || typeof color != 'string') {
760
+ return color;
761
+ }
762
+
763
+ if (color.match(/^gradient\((.*)\)$/i)) {
764
+
765
+ // Allow for JSON gradients
766
+ if (color.match(/^gradient\(({.*})\)$/i)) {
767
+ return RGraph.parseJSONGradient({
768
+ object: this,
769
+ def: RegExp.$1,
770
+ radial: true
771
+ });
772
+ }
773
+
774
+ var parts = RegExp.$1.split(':');
775
+
776
+ // Create the gradient
777
+ var grad = this.context.createLinearGradient(
778
+ properties.marginLeft,
779
+ 0,
780
+ this.canvas.width - properties.marginLeft - properties.marginRight,
781
+ 0
782
+ );
783
+
784
+ var diff = 1 / (parts.length - 1);
785
+
786
+ grad.addColorStop(0, RGraph.trim(parts[0]));
787
+
788
+ for (var j=1,len=parts.length; j<len; ++j) {
789
+ grad.addColorStop(j * diff, RGraph.trim(parts[j]));
790
+ }
791
+ }
792
+
793
+ return grad ? grad : color;
794
+ };
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+ //
804
+ // Using a function to add events makes it easier to facilitate method chaining
805
+ //
806
+ // @param string type The type of even to add
807
+ // @param function func
808
+ //
809
+ this.on = function (type, func)
810
+ {
811
+ if (type.substr(0,2) !== 'on') {
812
+ type = 'on' + type;
813
+ }
814
+
815
+ if (typeof this[type] !== 'function') {
816
+ this[type] = func;
817
+ } else {
818
+ RGraph.addCustomEventListener(this, type, func);
819
+ }
820
+
821
+ return this;
822
+ };
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+ //
832
+ // This function runs once only
833
+ // (put at the end of the file (before any effects))
834
+ //
835
+ this.firstDrawFunc = function ()
836
+ {
837
+ };
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+ //
847
+ // Meter Grow
848
+ //
849
+ // This effect gradually increases the represented value
850
+ //
851
+ // @param An object of options - eg: {frames: 60}
852
+ // @param function An optional callback function
853
+ //
854
+ this.grow = function ()
855
+ {
856
+ // Cancel any stop request if one is pending
857
+ this.cancelStopAnimation();
858
+
859
+ var obj = this;
860
+
861
+ obj.currentValue = obj.currentValue || obj.min;
862
+
863
+ var opt = arguments[0] || {},
864
+ frames = opt.frames || 30,
865
+ frame = 0,
866
+ diff = obj.value - obj.currentValue,
867
+ step = diff / frames,
868
+ callback = arguments[1] || function () {},
869
+ initial = obj.currentValue
870
+
871
+
872
+
873
+ function iterator ()
874
+ {
875
+ if (obj.stopAnimationRequested) {
876
+
877
+ // Reset the flag
878
+ obj.stopAnimationRequested = false;
879
+
880
+ return;
881
+ }
882
+
883
+ obj.value = initial + (frame++ * step);
884
+
885
+ RGraph.clear(obj.canvas);
886
+ RGraph.redrawCanvas(obj.canvas);
887
+
888
+ if (frame <= frames) {
889
+ RGraph.Effects.updateCanvas(iterator);
890
+ } else {
891
+ callback(obj);
892
+ }
893
+ }
894
+
895
+ iterator();
896
+
897
+ return this;
898
+ };
899
+
900
+
901
+
902
+
903
+
904
+
905
+
906
+
907
+ //
908
+ // RoundRobin
909
+ //
910
+ // This effect does two things:
911
+ // 1. Gradually increases the size of each segment
912
+ // 2. Gradually increases the size of the radius from 0
913
+ //
914
+ // @param object OPTIONAL Options for the effect
915
+ // @param function OPTIONAL A callback function
916
+ //
917
+ this.roundrobin =
918
+ this.roundRobin = function ()
919
+ {
920
+ // Cancel any stop request if one is pending
921
+ this.cancelStopAnimation();
922
+
923
+ var obj = this,
924
+ opt = arguments[0] || {},
925
+ callback = arguments[1] || function () {},
926
+ frame = 0,
927
+ frames = opt.frames || 30,
928
+ radius = this.radius;
929
+
930
+ var iterator = function ()
931
+ {
932
+ if (obj.stopAnimationRequested) {
933
+
934
+ // Reset the flag
935
+ obj.stopAnimationRequested = false;
936
+
937
+ return;
938
+ }
939
+
940
+ obj.set({
941
+ effectRoundrobinMultiplier: RGraph.Effects.getEasingMultiplier(frames, frame)
942
+ });
943
+
944
+ RGraph.redrawCanvas(obj.canvas);
945
+
946
+ if (frame < frames) {
947
+ RGraph.Effects.updateCanvas(iterator);
948
+ frame++;
949
+
950
+ } else {
951
+ RGraph.redrawCanvas(obj.canvas);
952
+ callback(obj);
953
+ }
954
+ };
955
+
956
+ iterator();
957
+
958
+ return this;
959
+ };
960
+
961
+
962
+
963
+
964
+
965
+
966
+
967
+
968
+ //
969
+ // Couple of functions that allow you to control the
970
+ // animation effect
971
+ //
972
+ this.stopAnimation = function ()
973
+ {
974
+ this.stopAnimationRequested = true;
975
+ };
976
+
977
+ this.cancelStopAnimation = function ()
978
+ {
979
+ this.stopAnimationRequested = false;
980
+ };
981
+
982
+
983
+
984
+
985
+
986
+
987
+
988
+
989
+ //
990
+ // Register the object
991
+ //
992
+ RGraph.register(this);
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+ //
1002
+ // This is the 'end' of the constructor so if the first argument
1003
+ // contains configuration data - handle that.
1004
+ //
1005
+ RGraph.parseObjectStyleConfig(this, conf.options);
1006
+ };