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,969 @@
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
+ RGraph.SVG = RGraph.SVG || {};
14
+
15
+ // Module pattern
16
+ (function (win, doc, undefined)
17
+ {
18
+ RGraph.SVG.Horseshoe = function (conf)
19
+ {
20
+ //
21
+ // A setter that the constructor uses (at the end)
22
+ // to set all of the properties
23
+ //
24
+ // @param string name The name of the property to set
25
+ // @param string value The value to set the property to
26
+ //
27
+ this.set = function (name, value)
28
+ {
29
+ if (arguments.length === 1 && typeof name === 'object') {
30
+ for (i in arguments[0]) {
31
+ if (typeof i === 'string') {
32
+
33
+ name = ret.name;
34
+ value = ret.value;
35
+
36
+ this.set(name, value);
37
+ }
38
+ }
39
+ } else {
40
+
41
+
42
+ var ret = RGraph.SVG.commonSetter({
43
+ object: this,
44
+ name: name,
45
+ value: value
46
+ });
47
+
48
+ name = ret.name;
49
+ value = ret.value;
50
+
51
+ this.properties[name] = value;
52
+ }
53
+
54
+ return this;
55
+ };
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ //
65
+ // A getter.
66
+ //
67
+ // @param name string The name of the property to get
68
+ //
69
+ this.get = function (name)
70
+ {
71
+ return this.properties[name];
72
+ };
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ this.min = RGraph.SVG.stringsToNumbers(conf.min);
82
+ this.max = RGraph.SVG.stringsToNumbers(conf.max);
83
+ this.value = RGraph.SVG.stringsToNumbers(conf.value);
84
+ this.currentValue = null; // Used by animations
85
+ this.id = conf.id;
86
+ this.uid = RGraph.SVG.createUID();
87
+ this.container = document.getElementById(this.id);
88
+ this.layers = {}; // MUST be before the SVG tag is created!
89
+ this.svg = RGraph.SVG.createSVG({object: this,container: this.container});
90
+ this.isRGraph = true;
91
+ this.isrgraph = true;
92
+ this.rgraph = true;
93
+ this.width = Number(this.svg.getAttribute('width'));
94
+ this.height = Number(this.svg.getAttribute('height'));
95
+ this.type = 'horseshoe';
96
+ this.colorsParsed = false;
97
+ this.originalColors = {};
98
+ this.gradientCounter = 1;
99
+ this.nodes = {};
100
+ this.firstDraw = true; // After the first draw this will be false
101
+
102
+ // Bounds checking
103
+ if (this.value > this.max) this.value = this.max;
104
+ if (this.value < this.min) this.value = this.min;
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ // Add this object to the ObjectRegistry
113
+ RGraph.SVG.OR.add(this);
114
+
115
+ // Set the DIV container to be inline-block
116
+ this.container.style.display = 'inline-block';
117
+
118
+ this.properties =
119
+ {
120
+ radius: null,
121
+ centerx: null,
122
+ centery: null,
123
+ width: 10,
124
+
125
+ marginLeft: 15,
126
+ marginRight: 15,
127
+ marginTop: 15,
128
+ marginBottom: 15,
129
+
130
+ backgroundColor: null,
131
+ colors: ['black','#eee'],
132
+
133
+ textFont: 'Arial, Verdana, sans-serif',
134
+ textSize: 70,
135
+ textColor: 'black',
136
+ textBold: false,
137
+ textItalic: false,
138
+ text: null,
139
+
140
+ labelsCenter: true,
141
+ labelsCenterFont: null,
142
+ labelsCenterSize: null,
143
+ labelsCenterColor: null,
144
+ labelsCenterBold: null,
145
+ labelsCenterItalic: null,
146
+ labelsCenterUnitsPre: '',
147
+ labelsCenterUnitsPost: '',
148
+ labelsCenterDecimals: 0,
149
+ labelsCenterPoint: '.',
150
+ labelsCenterThousand: ',',
151
+ labelsCenterSpecific: null,
152
+ labelsCenterSpecificFormattedDecimals: 0,
153
+ labelsCenterSpecificFormattedPoint: '.',
154
+ labelsCenterSpecificFormattedThousand: ',',
155
+ labelsCenterSpecificFormattedUnitsPre: '',
156
+ labelsCenterSpecificFormattedUnitsPost: '',
157
+ labelsCenterOffsetx: 0,
158
+ labelsCenterOffsety: 0,
159
+
160
+ ends: true,
161
+ endsRadius: null,
162
+ endsStroke: null,
163
+ endsColor: null,
164
+
165
+ adjustable: false
166
+ };
167
+
168
+
169
+
170
+
171
+ //
172
+ // Copy the global object properties to this instance
173
+ //
174
+ RGraph.SVG.getGlobals(this);
175
+
176
+
177
+
178
+
179
+
180
+ //
181
+ // "Decorate" the object with the generic effects if the effects library has been included
182
+ //
183
+ if (RGraph.SVG.FX && typeof RGraph.SVG.FX.decorate === 'function') {
184
+ RGraph.SVG.FX.decorate(this);
185
+ }
186
+
187
+
188
+
189
+
190
+
191
+ // Add the responsive function to the object
192
+ this.responsive = RGraph.SVG.responsive;
193
+
194
+
195
+
196
+
197
+
198
+ var properties = this.properties;
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+ //
208
+ // The draw method draws the Bar chart
209
+ //
210
+ this.draw = function ()
211
+ {
212
+ // Fire the beforedraw event
213
+ RGraph.SVG.fireCustomEvent(this, 'onbeforedraw');
214
+
215
+
216
+ // Reset this to prevent it from growing
217
+ this.nodes = {};
218
+
219
+ // Should the first thing that's done inthe.draw() function
220
+ // except for the onbeforedraw event
221
+ this.width = Number(this.svg.getAttribute('width'));
222
+ this.height = Number(this.svg.getAttribute('height'));
223
+
224
+
225
+
226
+ // Create the defs tag if necessary
227
+ RGraph.SVG.createDefs(this);
228
+
229
+
230
+
231
+ // Add these
232
+ this.graphWidth = this.width - properties.marginLeft - properties.marginRight;
233
+ this.graphHeight = this.height - properties.marginTop - properties.marginBottom;
234
+
235
+
236
+
237
+ // Work out the center point
238
+ this.centerx = (this.graphWidth / 2) + properties.marginLeft;
239
+ this.centery = (this.graphHeight / 2) + properties.marginTop;
240
+ this.radius = Math.min(this.graphWidth / 2, this.graphHeight / 2);
241
+
242
+
243
+
244
+ // Allow the user to override the calculated centerx/y/radius
245
+ this.centerx = typeof properties.centerx === 'number' ? properties.centerx : this.centerx;
246
+ this.centery = typeof properties.centery === 'number' ? properties.centery : this.centery;
247
+ this.radius = typeof properties.radius === 'number' ? properties.radius : this.radius;
248
+
249
+ //
250
+ // Allow the centerx/centery/radius to be a plus/minus
251
+ //
252
+ if (typeof properties.radius === 'string' && properties.radius.match(/^\+|-\d+$/) ) this.radius += parseFloat(properties.radius);
253
+ if (typeof properties.centerx === 'string' && properties.centerx.match(/^\+|-\d+$/) ) this.centerx += parseFloat(properties.centerx);
254
+ if (typeof properties.centery === 'string' && properties.centery.match(/^\+|-\d+$/) ) this.centery += parseFloat(properties.centery);
255
+
256
+
257
+
258
+ // Parse the colors for gradients
259
+ RGraph.SVG.resetColorsToOriginalValues({object:this});
260
+ this.parseColors();
261
+
262
+
263
+
264
+
265
+
266
+ // Draw the meter
267
+ this.drawMeter();
268
+
269
+
270
+
271
+
272
+ // Draw the labels
273
+ this.drawLabels();
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+ //
283
+ // Ajusting
284
+ //
285
+ if (properties.adjustable && !this.adjusting_event_listeners_installed) {
286
+
287
+ this.adjusting_mousedown = false;
288
+
289
+ var obj = this;
290
+
291
+ var func = function (e)
292
+ {
293
+ var div = e.currentTarget,
294
+ mouseX = e.offsetX,
295
+ mouseY = e.offsetY;
296
+
297
+ if (RGraph.SVG.ISFF) {
298
+ mouseX = e.pageX - e.currentTarget.offsetLeft;
299
+ mouseY = e.pageY - e.currentTarget.offsetTop;
300
+ }
301
+
302
+ var radius = RGraph.SVG.TRIG.getHypLength({
303
+ x1: mouseX,
304
+ y1: mouseY,
305
+ x2: obj.centerx,
306
+ y2: obj.centery,
307
+ object: obj
308
+ });
309
+
310
+ if (radius > obj.radius) {
311
+ return;
312
+ }
313
+
314
+ var value = obj.getValue(e);
315
+
316
+
317
+ obj.value = value;
318
+ obj.currentValue = value;
319
+
320
+ RGraph.SVG.clear(obj.svg);
321
+ obj.draw();
322
+ };
323
+
324
+
325
+
326
+
327
+ this.container.addEventListener('mousedown', function (e)
328
+ {
329
+ obj.adjusting_mousedown = true;
330
+ func(e);
331
+
332
+ // Fire the beforedraw event
333
+ RGraph.SVG.fireCustomEvent(obj, 'onadjustbegin');
334
+
335
+ }, false);
336
+
337
+ this.container.addEventListener('mousemove', function (e)
338
+ {
339
+ if (obj.adjusting_mousedown) {
340
+ func(e);
341
+
342
+ // Fire the beforedraw event
343
+ RGraph.SVG.fireCustomEvent(obj, 'onadjust');
344
+ }
345
+ }, false);
346
+
347
+ window.addEventListener('mouseup', function (e)
348
+ {
349
+ obj.adjusting_mousedown = false;
350
+
351
+ // Fire the beforedraw event
352
+ RGraph.SVG.fireCustomEvent(obj, 'onadjustend');
353
+
354
+ }, false);
355
+
356
+ this.adjusting_event_listeners_installed = true;
357
+ }
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+ //
367
+ // Allow the addition of custom text via the
368
+ // text: property.
369
+ //
370
+ RGraph.SVG.addCustomText(this);
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+ //
386
+ // Fire the onfirstdraw event
387
+ //
388
+ if (this.firstDraw) {
389
+ this.firstDraw = false;
390
+ RGraph.SVG.fireCustomEvent(this, 'onfirstdraw');
391
+ }
392
+
393
+
394
+
395
+
396
+ // Fire the draw event
397
+ RGraph.SVG.fireCustomEvent(this, 'ondraw');
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+ //
406
+ // Install any inline responsive configuration. This
407
+ // should be last in the draw function - even after
408
+ // the draw events.
409
+ //
410
+ RGraph.SVG.installInlineResponsive(this);
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+ return this;
423
+ };
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+ //
433
+ // New create() shortcut function
434
+ // For example:
435
+ // this.create('rect,x:0,y:0,width:100,height:100'[,parent]);
436
+ //
437
+ // @param str string The tag definition to parse and create
438
+ // @param object The (optional) parent element
439
+ // @return object The new tag
440
+ //
441
+ this.create = function (str)
442
+ {
443
+ var def = RGraph.SVG.create.parseStr(this, str);
444
+ def.svg = this.svg;
445
+
446
+ // By default the parent is the SVG tag - but if
447
+ // requested then change it to the tag that has
448
+ // been given
449
+ if (arguments[1]) {
450
+ def.parent = arguments[1];
451
+ }
452
+
453
+ return RGraph.SVG.create(def);
454
+ };
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+ //
464
+ // Draws the meter
465
+ //
466
+ this.drawMeter = function ()
467
+ {
468
+ var width = typeof properties.width === 'number' ? properties.width : this.radius / 2;
469
+
470
+ // Allow for +/-xx style width
471
+ if (typeof properties.width === 'string') {
472
+ width += Number(properties.width);
473
+ }
474
+
475
+
476
+ // First thing to do is clear the canvas to the backgroundColor
477
+ if (properties.backgroundColor) {
478
+ var rect = RGraph.SVG.create({
479
+ svg: this.svg,
480
+ type: 'rect',
481
+ parent: this.svg.all,
482
+ attr: {
483
+ fill: properties.backgroundColor,
484
+ x: 0,
485
+ y: 0,
486
+ width: this.width,
487
+ height: this.height
488
+ }
489
+ });
490
+ }
491
+
492
+
493
+
494
+
495
+
496
+ //
497
+ // Draw the background circular bar (the light gray one)
498
+ //
499
+ var path = RGraph.SVG.TRIG.getArcPath3({
500
+ cx: this.centerx,
501
+ cy: this.centery,
502
+ radius: this.radius,
503
+ start: 0,
504
+ end: RGraph.SVG.TRIG.TWOPI,
505
+ lineto: false
506
+ });
507
+
508
+ var path2 = RGraph.SVG.TRIG.getArcPath3({
509
+ cx: this.centerx,
510
+ cy: this.centery,
511
+ radius: this.radius - properties.width,
512
+ start: RGraph.SVG.TRIG.TWOPI,
513
+ end: 0,
514
+ anticlockwise: true
515
+ });
516
+
517
+
518
+ RGraph.SVG.create({
519
+ svg: this.svg,
520
+ parent: this.svg.all,
521
+ type: 'path',
522
+ attr: {
523
+ d: path + ' ' + path2 + ' z',
524
+ fill: properties.colors[1]
525
+ }
526
+ });
527
+
528
+
529
+
530
+ //
531
+ // Draw the indicator bar
532
+ //
533
+ var angle = ( (this.value - this.min) / (this.max - this.min) ) * RGraph.SVG.TRIG.TWOPI
534
+
535
+ var path = RGraph.SVG.TRIG.getArcPath3({
536
+ cx: this.centerx,
537
+ cy: this.centery,
538
+ radius: this.radius,
539
+ start: 0,
540
+ end: angle,
541
+ lineto: false
542
+ });
543
+
544
+ var path2 = RGraph.SVG.TRIG.getArcPath3({
545
+ cx: this.centerx,
546
+ cy: this.centery,
547
+ radius: this.radius - properties.width,
548
+ start: angle,
549
+ end: 0,
550
+ anticlockwise: true
551
+ });
552
+
553
+
554
+ RGraph.SVG.create({
555
+ svg: this.svg,
556
+ parent: this.svg.all,
557
+ type: 'path',
558
+ attr: {
559
+ d: path + ' ' + path2 + ' z',
560
+ fill: properties.colors[0]
561
+ }
562
+ });
563
+
564
+
565
+
566
+
567
+ //
568
+ // Draw the circles at each end of the bar
569
+ //
570
+ if (properties.ends) {
571
+ // Start of bar
572
+ RGraph.SVG.create({
573
+ svg: this.svg,
574
+ parent: this.svg.all,
575
+ type: 'circle',
576
+ attr: {
577
+ cx: this.centerx,
578
+ cy:this.centery - this.radius + (properties.width / 2),
579
+ r: typeof properties.endsRadius === 'number' ? properties.endsRadius : properties.width * 1.5,
580
+ fill: (properties.endsColor || properties.colors[0]),
581
+ stroke: typeof properties.endsStroke === 'string' ? properties.endsStroke : (properties.backgroundColor || 'white'),
582
+ 'stroke-width': 3
583
+ }
584
+ });
585
+
586
+ // End of bar
587
+ var endpoint = RGraph.SVG.TRIG.getRadiusEndPoint({
588
+ angle: angle - RGraph.SVG.TRIG.HALFPI,
589
+ radius: this.radius - (properties.width / 2)
590
+ });
591
+
592
+ // Get the endpoint for the end of the bar
593
+ endpoint[0] += this.centerx;
594
+ endpoint[1] += this.centery;
595
+
596
+ RGraph.SVG.create({
597
+ svg: this.svg,
598
+ parent: this.svg.all,
599
+ type: 'circle',
600
+ attr: {
601
+ cx: endpoint[0],
602
+ cy: endpoint[1],
603
+ r: typeof properties.endsRadius === 'number' ? properties.endsRadius : properties.width * 1.5,
604
+ fill: (properties.endsColor || properties.colors[0]),
605
+ stroke: typeof properties.endsStroke === 'string' ? properties.endsStroke : (properties.backgroundColor || 'white'),
606
+ 'stroke-width': 3
607
+ }
608
+ });
609
+ }
610
+
611
+
612
+
613
+ // Store the new value as the currentValue
614
+ this.currentValue = this.value;
615
+ };
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+ //
625
+ // Draw the labels
626
+ //
627
+ this.drawLabels = function ()
628
+ {
629
+ // Draw the center label
630
+ if (properties.labelsCenter) {
631
+
632
+ var label = RGraph.SVG.numberFormat({
633
+ object: this,
634
+ num: this.value.toFixed(properties.labelsCenterDecimals),
635
+ prepend: properties.labelsCenterUnitsPre,
636
+ append: properties.labelsCenterUnitsPost,
637
+ point: properties.labelsCenterPoint,
638
+ thousand: properties.labelsCenterThousand,
639
+ formatter: properties.labelsCenterFormatter
640
+ });
641
+
642
+
643
+
644
+
645
+
646
+ if (properties.labelsCenterSpecific) {
647
+ properties.labelsCenterSpecific = RGraph.SVG.labelSubstitution({
648
+ object: this,
649
+ text: properties.labelsCenterSpecific,
650
+ index: 0,
651
+ value: this.value,
652
+ decimals: properties.labelsCenterSpecificFormattedDecimals || 0,
653
+ unitsPre: properties.labelsCenterSpecificFormattedUnitsPre || '',
654
+ unitsPost: properties.labelsCenterSpecificFormattedUnitsPost || '',
655
+ thousand: properties.labelsCenterSpecificFormattedThousand || ',',
656
+ point: properties.labelsCenterSpecificFormattedPoint || '.'
657
+ });
658
+ }
659
+
660
+
661
+
662
+
663
+ // Get the text configuration
664
+ var textConf = RGraph.SVG.getTextConf({
665
+ object: this,
666
+ prefix: 'labelsCenter'
667
+ });
668
+
669
+ var text = RGraph.SVG.text({
670
+ object: this,
671
+ parent: this.svg.all,
672
+ tag: 'labels.center',
673
+
674
+ text: typeof properties.labelsCenterSpecific === 'string' ? properties.labelsCenterSpecific : label,
675
+
676
+ x: this.centerx + properties.labelsCenterOffsetx,
677
+ y: this.centery + properties.labelsCenterOffsety,
678
+
679
+ valign: 'center',
680
+ halign: 'center',
681
+
682
+ font: textConf.font,
683
+ size: textConf.size,
684
+ bold: textConf.bold,
685
+ italic: textConf.italic,
686
+ color: textConf.color
687
+ });
688
+
689
+ // Store a reference to the center label
690
+ this.nodes.labelsCenter = text;
691
+ }
692
+ };
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+ //
702
+ // This allows for easy specification of gradients
703
+ //
704
+ this.parseColors = function ()
705
+ {
706
+ // Save the original colors so that they can be restored when the canvas is reset
707
+ if (!Object.keys(this.originalColors).length) {
708
+ this.originalColors = {
709
+ colors: RGraph.SVG.arrayClone(properties.colors),
710
+ backgroundColor: RGraph.SVG.arrayClone(properties.backgroundColor)
711
+ }
712
+ }
713
+
714
+
715
+ // colors
716
+ var colors = properties.colors;
717
+
718
+ if (colors) {
719
+ for (var i=0; i<colors.length; ++i) {
720
+ colors[i] = RGraph.SVG.parseColorLinear({
721
+ object: this,
722
+ color: colors[i],
723
+ start: this.centerx - this.radius,
724
+ end: this.centerx + this.radius,
725
+ direction: 'horizontal'
726
+ });
727
+ }
728
+ }
729
+
730
+ // Background color
731
+ properties.backgroundColor = RGraph.SVG.parseColorLinear({
732
+ object: this,
733
+ color: properties.backgroundColor,
734
+ start: properties.marginLeft,
735
+ end: this.width - properties.marginRight,
736
+ direction: 'horizontal'
737
+ });
738
+ };
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+ //
748
+ // Using a function to add events makes it easier to facilitate method
749
+ // chaining
750
+ //
751
+ // @param string type The type of even to add
752
+ // @param function func
753
+ //
754
+ this.on = function (type, func)
755
+ {
756
+ if (type.substr(0,2) !== 'on') {
757
+ type = 'on' + type;
758
+ }
759
+
760
+ RGraph.SVG.addCustomEventListener(this, type, func);
761
+
762
+ return this;
763
+ };
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+ //
773
+ // Used in chaining. Runs a function there and then - not waiting for
774
+ // the events to fire (eg the onbeforedraw event)
775
+ //
776
+ // @param function func The function to execute
777
+ //
778
+ this.exec = function (func)
779
+ {
780
+ func(this);
781
+
782
+ return this;
783
+ };
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+ //
793
+ // This function returns the pertinent angle for a particular click (or other mouse event)
794
+ //
795
+ // @param obj e The event object
796
+ // OR
797
+ // int e An integer value for
798
+ // which to the relevant
799
+ // angle
800
+ //
801
+ this.getAngle = function (e)
802
+ {
803
+ if (typeof e === 'number') {
804
+ var angle = ((e - this.min) / (this.max - this.min)) * RGraph.SVG.TRIG.TWOPI;
805
+ angle -= RGraph.SVG.TRIG.HALFPI;
806
+
807
+ } else {
808
+ var mouseX = e.offsetX,
809
+ mouseY = e.offsetY;
810
+
811
+ var angle = RGraph.SVG.TRIG.getAngleByXY({
812
+ cx: this.centerx,
813
+ cy: this.centery,
814
+ x: mouseX,
815
+ y: mouseY
816
+ });
817
+
818
+ angle -= RGraph.SVG.TRIG.HALFPI;
819
+ }
820
+
821
+ return angle;
822
+ };
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+ //
832
+ // This function returns the pertinent value for a particular click (or other mouse event)
833
+ //
834
+ // @param obj e The event object
835
+ //
836
+ //
837
+ this.getValue = function (e)
838
+ {
839
+ // Treat the argument as an angle (given in radians)
840
+ if (typeof e === 'number') {
841
+ var angle = e;
842
+
843
+ // Treat the argument as an event object
844
+ } else {
845
+ // Get the angle of the click
846
+ var angle = this.getAngle(e);
847
+ }
848
+
849
+ // Calculate the value based on the angle and min/max values
850
+ var value = (((angle + RGraph.SVG.TRIG.HALFPI) / RGraph.SVG.TRIG.TWOPI) * (this.max - this.min)) + this.min;
851
+
852
+ // Ensure that the value is in range
853
+ value = Math.max(value, this.min);
854
+ value = Math.min(value, this.max);
855
+
856
+ return value;
857
+ };
858
+
859
+
860
+
861
+
862
+
863
+
864
+
865
+
866
+ //
867
+ // This function returns the pertinent radius (from the centerx/y) of a given event object
868
+ // (eg from a click or mouse event).
869
+ //
870
+ // @param obj e The event object
871
+ //
872
+ this.getRadius = function (e)
873
+ {
874
+ var x = e.offsetX,
875
+ y = e.offsetY;
876
+
877
+ var radius = RGraph.SVG.TRIG.getHypLength({
878
+ x1: x,
879
+ y1: y,
880
+ x2: this.centerx,
881
+ y2: this.centery
882
+ });
883
+
884
+ return radius;
885
+ };
886
+
887
+
888
+
889
+
890
+
891
+
892
+
893
+
894
+ //
895
+ // Segmented donut Grow
896
+ //
897
+ // This effect gradually increases the represented value
898
+ //
899
+ // @param An object of options - eg: {frames: 60}
900
+ // @param function An optional callback function
901
+ //
902
+ this.grow = function ()
903
+ {
904
+ var obj = this;
905
+
906
+ this.currentValue = typeof this.currentValue === 'number' ? this.currentValue : this.min;
907
+
908
+ // Limit value to the max and min values
909
+ this.value = Math.min(this.value, this.max);
910
+ this.value = Math.max(this.value, this.min);
911
+
912
+ var opt = arguments[0] || {},
913
+ frames = opt.frames || 60,
914
+ frame = 0,
915
+ diff = this.value - this.currentValue,
916
+ step = diff / frames,
917
+ callback = arguments[1] || function () {},
918
+ initial = this.currentValue
919
+
920
+
921
+
922
+ function iterator ()
923
+ {
924
+ obj.value = initial + (frame++ * step);
925
+
926
+ RGraph.SVG.redraw(obj.svg);
927
+
928
+ if (frame++ >= frames) {
929
+ this.currentValue = this.value;
930
+ callback(obj);
931
+ } else {
932
+ RGraph.SVG.FX.update(iterator);
933
+ }
934
+ }
935
+
936
+ iterator();
937
+
938
+ return this;
939
+ };
940
+
941
+
942
+
943
+
944
+
945
+
946
+
947
+ //
948
+ // Set the options that the user has provided
949
+ //
950
+ for (i in conf.options) {
951
+ if (typeof i === 'string') {
952
+ this.set(i, conf.options[i]);
953
+ }
954
+ }
955
+
956
+
957
+
958
+ return this;
959
+ };
960
+
961
+
962
+
963
+
964
+
965
+
966
+
967
+
968
+ // End module pattern
969
+ })(window, document);