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,1696 @@
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.Activity = 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 = 'activity';
96
+ this.colorsParsed = false;
97
+ this.originalColors = {};
98
+ this.gradientCounter = 1;
99
+ this.adjusting_index = null;
100
+ this.nodes = {};
101
+ this.firstDraw = true; // After the first draw this will be false
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+ // Add this object to the ObjectRegistry
112
+ RGraph.SVG.OR.add(this);
113
+
114
+ // Set the DIV container to be inline-block
115
+ this.container.style.display = 'inline-block';
116
+
117
+ this.properties =
118
+ {
119
+ radius: null,
120
+ centerx: null,
121
+ centery: null,
122
+ width: null,
123
+ ends: 'round',
124
+
125
+ marginLeft: 15,
126
+ marginRight: 15,
127
+ marginTop: 15,
128
+ marginBottom: 15,
129
+ marginInner: 1,
130
+
131
+ backgroundColor: 'black',
132
+ backgroundGrid: false,
133
+ backgroundGridColor: '#ddd',
134
+ backgroundGridRadials: true,
135
+ backgroundGridRadialsCount: 8,
136
+ backgroundRings: true,
137
+ backgroundRingsColors: null,
138
+ backgroundRingsAlpha: 0.5,
139
+
140
+ colors: ['#F45B5B','#90EE7E','#2B908F','red','green','blue','yellow','pink'],
141
+
142
+ icons: null,
143
+ iconsWidth: null,
144
+ iconsHeight: null,
145
+ iconsOffsetx: 0,
146
+ iconsOffsety: 0,
147
+
148
+ textFont: 'Arial, Verdana, sans-serif',
149
+ textSize: 12,
150
+ textColor: '#aaa',
151
+ textBold: false,
152
+ textItalic: false,
153
+ text: null,
154
+
155
+ labelsCenter: false,
156
+ labelsCenterIndex: 0,
157
+ labelsCenterFont: null,
158
+ labelsCenterSize: 40,
159
+ labelsCenterColor: null,
160
+ labelsCenterBold: null,
161
+ labelsCenterItalic: null,
162
+ labelsCenterUnitsPre: '',
163
+ labelsCenterUnitsPost: '',
164
+ labelsCenterDecimals: 0,
165
+ labelsCenterPoint: '.',
166
+ labelsCenterThousand: ',',
167
+ labelsCenterSpecific: null,
168
+ labelsCenterHalign: 'center',
169
+ labelsCenterValign: 'center',
170
+ labelsCenterOffsetx: 0,
171
+ labelsCenterOffsety: 0,
172
+ labels: [],
173
+ labelsColor: null,
174
+ labelsFont: null,
175
+ labelsSize: null,
176
+ labelsBold: null,
177
+ labelsItalic: null,
178
+ labelsBackgroundFill: 'transparent',
179
+ labelsBackgroundStroke: 'transparent',
180
+ labelsHalign: 'right',
181
+ labelsValign: 'center',
182
+ labelsOffsetx: 0,
183
+ labelsOffsety: 0,
184
+ labelsFormattedDecimals: 0,
185
+ labelsFormattedPoint: '.',
186
+ labelsFormattedThousand: ',',
187
+ labelsFormattedUnitsPre: '',
188
+ labelsFormattedUnitsPost: '',
189
+
190
+ adjustable: false,
191
+
192
+ tooltips: null,
193
+ tooltipsOverride: null,
194
+ tooltipsEffect: 'fade',
195
+ tooltipsCssClass: 'RGraph_tooltip',
196
+ tooltipsCss: null,
197
+ tooltipsEvent: 'click',
198
+ tooltipsFormattedThousand: ',',
199
+ tooltipsFormattedPoint: '.',
200
+ tooltipsFormattedDecimals: 0,
201
+ tooltipsFormattedUnitsPre: '',
202
+ tooltipsFormattedUnitsPost: '',
203
+ tooltipsFormattedKeyColors: null,
204
+ tooltipsFormattedKeyColorsShape: 'square',
205
+ tooltipsFormattedKeyLabels: [],
206
+ tooltipsFormattedTableHeaders: null,
207
+ tooltipsFormattedTableData: null,
208
+ tooltipsPointer: true,
209
+ tooltipsPositionStatic: true,
210
+
211
+ highlightStroke: 'rgba(0,0,0,0)',
212
+ highlightFill: 'rgba(255,255,255,0.7)',
213
+ highlightLinewidth: 1
214
+ };
215
+
216
+
217
+
218
+
219
+ //
220
+ // Copy the global object properties to this instance
221
+ //
222
+ RGraph.SVG.getGlobals(this);
223
+
224
+
225
+
226
+
227
+
228
+ //
229
+ // "Decorate" the object with the generic effects if the effects library has been included
230
+ //
231
+ if (RGraph.SVG.FX && typeof RGraph.SVG.FX.decorate === 'function') {
232
+ RGraph.SVG.FX.decorate(this);
233
+ }
234
+
235
+
236
+
237
+
238
+
239
+ // Add the responsive function to the object
240
+ this.responsive = RGraph.SVG.responsive;
241
+
242
+
243
+
244
+
245
+ var properties = this.properties;
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+ //
255
+ // The draw method draws the Bar chart
256
+ //
257
+ this.draw = function ()
258
+ {
259
+ // Fire the beforedraw event
260
+ RGraph.SVG.fireCustomEvent(this, 'onbeforedraw');
261
+
262
+
263
+ //
264
+ // Convert the value to an array if its a number
265
+ //
266
+ if (typeof this.value === 'number') {
267
+ this.value = [this.value];
268
+ }
269
+
270
+ // Bounds checking
271
+ for (var i=0; i<this.value.length; ++i) {
272
+ if (this.value[i] > this.max) this.value[i] = this.max;
273
+ if (this.value[i] < this.min) this.value[i] = this.min;
274
+ }
275
+
276
+ // Reset this to prevent it from growing
277
+ this.nodes = {};
278
+
279
+ // Should the first thing that's done inthe.draw() function
280
+ // except for the onbeforedraw event
281
+ this.width = Number(this.svg.getAttribute('width'));
282
+ this.height = Number(this.svg.getAttribute('height'));
283
+
284
+
285
+
286
+ // Create the defs tag if necessary
287
+ RGraph.SVG.createDefs(this);
288
+
289
+
290
+
291
+ // Add these
292
+ this.graphWidth = this.width - properties.marginLeft - properties.marginRight;
293
+ this.graphHeight = this.height - properties.marginTop - properties.marginBottom;
294
+
295
+
296
+
297
+ // Work out the center point
298
+ this.centerx = (this.graphWidth / 2) + properties.marginLeft;
299
+ this.centery = (this.graphHeight / 2) + properties.marginTop;
300
+ this.radius = Math.min(this.graphWidth / 2, this.graphHeight / 2);
301
+
302
+
303
+
304
+ // Allow the user to override the calculated centerx/y/radius
305
+ this.centerx = typeof properties.centerx === 'number' ? properties.centerx : this.centerx;
306
+ this.centery = typeof properties.centery === 'number' ? properties.centery : this.centery;
307
+ this.radius = typeof properties.radius === 'number' ? properties.radius : this.radius;
308
+
309
+ //
310
+ // Allow the centerx/centery/radius to be a plus/minus
311
+ //
312
+ if (typeof properties.radius === 'string' && properties.radius.match(/^\+|-\d+$/) ) this.radius += parseFloat(properties.radius);
313
+ if (typeof properties.centerx === 'string' && properties.centerx.match(/^\+|-\d+$/) ) this.centerx += parseFloat(properties.centerx);
314
+ if (typeof properties.centery === 'string' && properties.centery.match(/^\+|-\d+$/) ) this.centery += parseFloat(properties.centery);
315
+
316
+
317
+
318
+ // Parse the colors for gradients
319
+ RGraph.SVG.resetColorsToOriginalValues({object:this});
320
+ this.parseColors();
321
+
322
+
323
+
324
+
325
+
326
+ // Calculate the width
327
+ if (!properties.width) {
328
+ properties.width = (this.radius * 0.75) / this.value.length;
329
+ properties.width -= (2 * properties.marginInner);
330
+ }
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+ // Draw the background
340
+ this.drawBackground();
341
+
342
+
343
+
344
+
345
+ // Draw the meter
346
+ this.drawMeter();
347
+
348
+
349
+
350
+
351
+ // Draw the labels
352
+ this.drawLabels();
353
+
354
+
355
+
356
+
357
+
358
+
359
+ // Draw the icons
360
+ this.drawIcons();
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+ //
370
+ // Ajusting
371
+ //
372
+ if (properties.adjustable && !this.adjusting_event_listeners_installed) {
373
+
374
+ this.adjusting_mousedown = false;
375
+
376
+ var obj = this;
377
+
378
+ var func = function (e)
379
+ {
380
+ var div = e.currentTarget,
381
+ mouseX = e.offsetX,
382
+ mouseY = e.offsetY;
383
+
384
+ if (RGraph.SVG.ISFF) {
385
+ mouseX = e.pageX - e.currentTarget.offsetLeft;
386
+ mouseY = e.pageY - e.currentTarget.offsetTop;
387
+ }
388
+
389
+ // Get the radius of the click
390
+ var radius = obj.getRadius(e);
391
+
392
+
393
+
394
+
395
+
396
+ if (radius > obj.radius) {
397
+ return;
398
+ }
399
+
400
+ if (typeof obj.adjusting_index !== 'number') {
401
+ var index = obj.getIndexByRadius({radius: radius});
402
+ obj.adjusting_index = index;
403
+ } else {
404
+ var index = obj.adjusting_index;
405
+ }
406
+
407
+ var value = obj.getValue(e);
408
+ obj.value[index] = value;
409
+ obj.currentValue = RGraph.SVG.arrayClone(value);
410
+
411
+ RGraph.SVG.clear(obj.svg);
412
+ obj.draw();
413
+ };
414
+
415
+
416
+
417
+
418
+ this.container.addEventListener('mousedown', function (e)
419
+ {
420
+ obj.adjusting_mousedown = true;
421
+
422
+ func(e);
423
+
424
+ // Fire the beforedraw event
425
+ RGraph.SVG.fireCustomEvent(obj, 'onadjustbegin');
426
+
427
+ }, false);
428
+
429
+ this.container.addEventListener('mousemove', function (e)
430
+ {
431
+ if (obj.adjusting_mousedown) {
432
+ func(e);
433
+
434
+ // Fire the beforedraw event
435
+ RGraph.SVG.fireCustomEvent(obj, 'onadjust');
436
+ }
437
+ }, false);
438
+
439
+ window.addEventListener('mouseup', function (e)
440
+ {
441
+ obj.adjusting_mousedown = false;
442
+ obj.adjusting_index = null;
443
+
444
+ // Fire the beforedraw event
445
+ RGraph.SVG.fireCustomEvent(obj, 'onadjustend');
446
+ }, false);
447
+
448
+ this.adjusting_event_listeners_installed = true;
449
+ }
450
+
451
+ // Add the event listener that clears the highlight rect if
452
+ // there is any. Must be MOUSEDOWN (ie before the click event)
453
+ var obj = this; document.body.addEventListener('mouseup', function (e)
454
+ {
455
+ obj.removeHighlight();
456
+
457
+ }, false);
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+ //
467
+ // Allow the addition of custom text via the
468
+ // text: property.
469
+ //
470
+ RGraph.SVG.addCustomText(this);
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+ //
485
+ // Fire the onfirstdraw event
486
+ //
487
+ if (this.firstDraw) {
488
+ this.firstDraw = false;
489
+ RGraph.SVG.fireCustomEvent(this, 'onfirstdraw');
490
+ }
491
+
492
+
493
+
494
+
495
+ // Fire the draw event
496
+ RGraph.SVG.fireCustomEvent(this, 'ondraw');
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+ //
505
+ // Install any inline responsive configuration. This
506
+ // should be last in the draw function - even after
507
+ // the draw events.
508
+ //
509
+ RGraph.SVG.installInlineResponsive(this);
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+ return this;
522
+ };
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+ //
532
+ // New create() shortcut function
533
+ //eg:
534
+ // this.create('rect,x:0,y:0,width:100,height:100'[,parent]);
535
+ //
536
+ // @param mixed definition This can either be an object
537
+ // which holds details of the object
538
+ // that you want to make or a string
539
+ // that holds the same information.
540
+ // @param mixed This can be either a string that
541
+ // holds style information to be
542
+ // applied to the new node or it
543
+ // can be the parent node that the
544
+ // new node is to be added to.
545
+ // @param string If used, this can be a string
546
+ // that holds the style information
547
+ // that is to be applied to the new
548
+ // node.
549
+ //
550
+ this.create = function (definition)
551
+ {
552
+ return RGraph.SVG.create.call(this, definition, arguments[1], arguments[2]);
553
+ };
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+ //
563
+ // Go through the bars looking for the correct one for the given radius
564
+ //
565
+ this.getIndexByRadius = function (opt)
566
+ {
567
+ var radius = opt.radius;
568
+
569
+ for (var i=0; i<this.nodes.bars.length; ++i) {
570
+ var radiusInner = parseFloat(this.nodes.bars[i].getAttribute('data-radius-inner'));
571
+ var radiusOuter = parseFloat(this.nodes.bars[i].getAttribute('data-radius-outer'));
572
+
573
+ if (radius >= radiusInner && radius <= radiusOuter) {
574
+ return i;
575
+ }
576
+ }
577
+
578
+ return null;
579
+ };
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+ //
589
+ // Draw the background"grid"
590
+ //
591
+ this.drawBackground = function ()
592
+ {
593
+ // First thing to do is clear the canvas to the backgroundColor
594
+ if (properties.backgroundColor) {
595
+ RGraph.SVG.create({
596
+ svg: this.svg,
597
+ type: 'rect',
598
+ parent: this.svg.all,
599
+ attr: {
600
+ fill: properties.backgroundColor,
601
+ x: 0,
602
+ y: 0,
603
+ width: this.width,
604
+ height: this.height
605
+ }
606
+ });
607
+ }
608
+
609
+
610
+
611
+
612
+ //
613
+ // Draw the grid?
614
+ //
615
+ if (properties.backgroundGrid) {
616
+
617
+ // Determine how many background circles
618
+ // should be shown on the data points
619
+ var count = this.value.length + 1;
620
+
621
+ for (var i=0; i<count; i++) {
622
+
623
+ var radius = this.radius - (i * (properties.width + (2 * properties.marginInner)));
624
+
625
+ RGraph.SVG.create({
626
+ svg: this.svg,
627
+ type: 'circle',
628
+ parent: this.svg.all,
629
+ attr: {
630
+ fill: 'transparent',
631
+ stroke: properties.backgroundGridColor,
632
+ cx: this.centerx,
633
+ cy: this.centery,
634
+ r: radius
635
+ }
636
+ });
637
+ }
638
+
639
+
640
+ // Rename the variable so that it makes a little more sense
641
+ // when used further down
642
+ var minRadius = radius
643
+
644
+
645
+
646
+
647
+ //
648
+ // Draw the background lines that go from the center outwards
649
+ //
650
+ if (properties.backgroundGridRadials) {
651
+
652
+ var angle = (RGraph.SVG.TRIG.TWOPI / properties.backgroundGridRadialsCount);
653
+
654
+ for (var i=0; i<=properties.backgroundGridRadialsCount; ++i) {
655
+
656
+ var path1 = RGraph.SVG.TRIG.getArcPath3({
657
+ svg: this.svg,
658
+ cx: this.centerx,
659
+ cy: this.centery,
660
+ radius: this.radius,
661
+ start: i * angle,
662
+ end: i * angle,
663
+ lineto: false
664
+ });
665
+
666
+ var path2 = RGraph.SVG.TRIG.getArcPath3({
667
+ svg: this.svg,
668
+ cx: this.centerx,
669
+ cy: this.centery,
670
+ radius: minRadius,
671
+ start: i * angle,
672
+ end: i * angle,
673
+ lineto: true
674
+ });
675
+
676
+ RGraph.SVG.create({
677
+ svg: this.svg,
678
+ type: 'path',
679
+ parent: this.svg.all,
680
+ attr: {
681
+ fill: 'transparent',
682
+ stroke: properties.backgroundGridColor,
683
+ d: path1 + ' ' + path2
684
+ }
685
+ });
686
+ }
687
+ }
688
+ }
689
+ };
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+ //
699
+ // Draws the meter
700
+ //
701
+ this.drawMeter = function ()
702
+ {
703
+ this.nodes.bars = [];
704
+
705
+ //
706
+ // Loop through the values and draw the background rings
707
+ //
708
+ for (var i=0; i<this.value.length; ++i) {
709
+
710
+ // The radiuses of the ring
711
+ var inner = this.radius - properties.marginInner - (i * properties.marginInner * 2) - (i * properties.width) - properties.width,
712
+ outer = this.radius - properties.marginInner - (i * properties.marginInner * 2) - (i * properties.width);
713
+
714
+ // Determine the color
715
+ if (RGraph.SVG.isArray(properties.backgroundRingsColors) && typeof properties.backgroundRingsColors[i] === 'string') {
716
+ var color = properties.backgroundRingsColors[i];
717
+ } else {
718
+ var color = properties.colors[i];
719
+ }
720
+
721
+
722
+
723
+
724
+
725
+
726
+ // Draw the background rings if enabled
727
+ if (properties.backgroundRings) {
728
+
729
+ // Draw the background ring
730
+ var path = RGraph.SVG.donut({
731
+ svg: this.svg.all,
732
+ cx: this.centerx,
733
+ cy: this.centery,
734
+ innerRadius: inner,
735
+ outerRadius: outer,
736
+ fill: color,
737
+ opacity: properties.backgroundRingsAlpha
738
+ });
739
+
740
+ path.setAttribute('data-radiusInner', inner);
741
+ path.setAttribute('data-radiusOuter', outer);
742
+ path.setAttribute('data-centerx', this.centerx);
743
+ path.setAttribute('data-centery', this.centery);
744
+ }
745
+
746
+
747
+
748
+ // Create the group the main path and the ends path objects will be children of.
749
+ // This does not include the background of the ring
750
+ //
751
+ // *** IMPORTANT ***
752
+ //
753
+ // This group must be created and added to the SVG document AFTER the
754
+ // background ring or the background rings will sit on top of the clickable
755
+ // bit and prevent tooltips from working
756
+ //
757
+ var group = RGraph.SVG.create({
758
+ svg: this.svg,
759
+ type: 'g',
760
+ parent: this.svg.all,
761
+ attr: {
762
+ 'data-index': i
763
+ }
764
+ });
765
+
766
+
767
+
768
+ // First calculate the angle that the indicator bar extends to
769
+ var angle = ((this.value[i] - this.min) / (this.max - this.min)) * RGraph.SVG.TRIG.TWOPI;
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+ //
789
+ // Draw the foreground to the ring
790
+ //
791
+ var arcPath = this.pathBar({
792
+ radiusInner: inner,
793
+ radiusOuter: outer,
794
+ angle: angle
795
+ });
796
+
797
+ var path = RGraph.SVG.create({
798
+ svg: this.svg,
799
+ type: 'path',
800
+ parent: group,
801
+ attr: {
802
+ fill: properties.colors[i],
803
+ d: arcPath,
804
+ 'data-index': i,
805
+ 'data-centerx': this.centerx,
806
+ 'data-centery': this.centery,
807
+ 'data-angles-info': 'These angles are designed to be used with the RGraph.SVG.TRIG.getArcPath3() function',
808
+ 'data-start-angle': 0,
809
+ 'data-end-angle': angle,
810
+ 'data-radius-inner': inner,
811
+ 'data-radius-outer': outer
812
+ }
813
+ });
814
+
815
+ // Set the angle and radiuses on the group tag too
816
+ group.setAttribute('data-centerx', this.centerx);
817
+ group.setAttribute('data-centery', this.centery);
818
+ group.setAttribute('data-start-angle', 0);
819
+ group.setAttribute('data-end-angle', angle);
820
+ group.setAttribute('data-radius-inner', inner);
821
+ group.setAttribute('data-radius-outer', outer);
822
+
823
+ this.nodes.bars[i] = group;
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+ //
837
+ // Draw the circles at each end of the bar if necessary
838
+ //
839
+ if (properties.ends === 'round' && 0) {
840
+
841
+ var endcircle1 = RGraph.SVG.create({
842
+ svg: this.svg,
843
+ type: 'circle',
844
+ parent: group,
845
+ attr: {
846
+ fill: color,
847
+ cx: this.centerx,
848
+ cy: this.centery - outer + (properties.width / 2),
849
+ r: properties.width / 2
850
+ }
851
+ });
852
+
853
+ // Calculate the endpoint for the second circle
854
+ var endpoint = RGraph.SVG.TRIG.getRadiusEndPoint({
855
+ cx: this.centerx,
856
+ cy: this.centery,
857
+ radius: outer - (properties.width / 2),
858
+ angle: angle - RGraph.SVG.TRIG.HALFPI
859
+ });
860
+
861
+ var endcircle2 = RGraph.SVG.create({
862
+ svg: this.svg,
863
+ type: 'circle',
864
+ parent: group,
865
+ attr: {
866
+ fill: color,
867
+ cx: this.centerx + endpoint[0],
868
+ cy: this.centery + endpoint[1],
869
+ r: properties.width / 2
870
+ }
871
+ });
872
+ }
873
+
874
+
875
+
876
+
877
+
878
+
879
+ //
880
+ // Add the tooltip if necessary
881
+ //
882
+ if ( !RGraph.SVG.isNull(properties.tooltips)
883
+ && (!RGraph.SVG.isNull(properties.tooltips[i]) || typeof properties.tooltips === 'string')
884
+ ) {
885
+
886
+ var obj = this;
887
+
888
+ //
889
+ // Add tooltip event listeners
890
+ //
891
+ (function (index)
892
+ {
893
+ group.addEventListener(properties.tooltipsEvent.replace(/^on/, ''), function (e)
894
+ {
895
+ obj.removeHighlight();
896
+
897
+ // Show the tooltip
898
+ RGraph.SVG.tooltip({
899
+ object: obj,
900
+ index: index,
901
+ group: null,
902
+ sequentialIndex: index,
903
+ text: typeof properties.tooltips === 'string' ? properties.tooltips : properties.tooltips[index],
904
+ event: e
905
+ });
906
+
907
+ // Highlight the group that has been clicked on
908
+ obj.highlight(e.target);
909
+ }, false);
910
+
911
+ group.addEventListener('mousemove', function (e)
912
+ {
913
+ e.target.style.cursor = 'pointer';
914
+ }, false);
915
+ })(i);
916
+ }
917
+ }
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+
927
+
928
+ // Store the new value as the currentValue
929
+ this.currentValue = RGraph.SVG.arrayClone(this.value);
930
+ };
931
+
932
+
933
+
934
+
935
+
936
+
937
+
938
+
939
+ //
940
+ // This function creates the path for the indicator bar. It only creates the
941
+ // path - it does not create an element or add anything to the DOM
942
+ //
943
+ this.pathBar = function (opt)
944
+ {
945
+ var inner = opt.radiusInner,
946
+ outer = opt.radiusOuter,
947
+ angle = opt.angle;
948
+
949
+ var arcPath1 = RGraph.SVG.TRIG.getArcPath3({
950
+ svg: this.svg,
951
+ cx: this.centerx,
952
+ cy: this.centery,
953
+ radius: outer,
954
+ start: 0,
955
+ end: angle,
956
+ lineto: false
957
+ });
958
+
959
+ // Draw a round end
960
+ if (properties.ends === 'round') {
961
+ var endpoint1 = RGraph.SVG.TRIG.getRadiusEndPoint({
962
+ cx: this.centerx,
963
+ cy: this.centery,
964
+ radius: ((outer - inner) / 2) + inner,
965
+ angle: opt.angle - RGraph.SVG.TRIG.HALFPI
966
+ });
967
+
968
+ var endPath1 = RGraph.SVG.TRIG.getArcPath3({
969
+ svg: this.svg,
970
+ cx: this.centerx + endpoint1[0],
971
+ cy: this.centery + endpoint1[1],
972
+ radius: (outer - inner) / 2,
973
+ start: angle,
974
+ end: angle + RGraph.SVG.TRIG.PI,
975
+ lineto: false,
976
+ moveto: false
977
+ });
978
+
979
+ } else {
980
+ endPath1 = '';
981
+ }
982
+
983
+
984
+ var arcPath2 = RGraph.SVG.TRIG.getArcPath3({
985
+ svg: this.svg,
986
+ cx: this.centerx,
987
+ cy: this.centery,
988
+ radius: inner,
989
+ start: angle,
990
+ end: 0,
991
+ anticlockwise: true
992
+ });
993
+
994
+
995
+
996
+ // Draw a round end
997
+ if (properties.ends === 'round') {
998
+ var endPath2 = RGraph.SVG.TRIG.getArcPath3({
999
+ svg: this.svg,
1000
+ cx: this.centerx,
1001
+ cy: this.centery - inner - ((outer - inner) / 2),
1002
+ radius: (outer - inner) / 2,
1003
+ start: RGraph.SVG.TRIG.PI,
1004
+ end: RGraph.SVG.TRIG.TWOPI,
1005
+ lineto: true
1006
+ });
1007
+ } else {
1008
+ endPath2 = '';
1009
+ }
1010
+
1011
+ return arcPath1
1012
+ + ' ' + endPath1
1013
+ + ' ' + arcPath2
1014
+ + ' ' + endPath2
1015
+ + ' z';
1016
+ };
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+ //
1026
+ // Highlights a bar when it has been clicked
1027
+ //
1028
+ // @param el object The element that has been clicked on
1029
+ //
1030
+ this.highlight = function (el)
1031
+ {
1032
+ var group = el.parentNode,
1033
+ index = group.getAttribute('data-index'),
1034
+ radiusInner = parseFloat(group.getAttribute('data-radius-inner')),
1035
+ radiusOuter = parseFloat(group.getAttribute('data-radius-outer')),
1036
+ angle = parseFloat(group.getAttribute('data-end-angle'));
1037
+
1038
+
1039
+
1040
+ // Create a group for the highlight
1041
+ var highlightGroup = RGraph.SVG.create({
1042
+ svg: this.svg,
1043
+ type: 'g',
1044
+ parent: this.svg.all,
1045
+ attr: {
1046
+ fill: properties.highlightFill,
1047
+ stroke: properties.highlightStroke,
1048
+ },
1049
+ style: {
1050
+ pointerEvents: 'none'
1051
+ }
1052
+ });
1053
+
1054
+
1055
+
1056
+ // Get the path for the highlight node
1057
+ var arcPath = this.pathBar({
1058
+ radiusInner: radiusInner,
1059
+ radiusOuter: radiusOuter,
1060
+ angle: angle
1061
+ });
1062
+
1063
+
1064
+
1065
+
1066
+ // Create the highlight node
1067
+ var path = RGraph.SVG.create({
1068
+ svg: this.svg,
1069
+ type: 'path',
1070
+ parent: highlightGroup,
1071
+ attr: {
1072
+ d: arcPath,
1073
+ 'stroke-width': properties.highlightLinewidth,
1074
+
1075
+ 'data-highlight': 'true',
1076
+ 'data-index': index,
1077
+ 'data-centerx': this.centerx,
1078
+ 'data-centery': this.centery,
1079
+ 'data-angles-info': 'These angles are designed to be used with the RGraph.SVG.TRIG.getArcPath3() function',
1080
+ 'data-start-angle': 0,
1081
+ 'data-end-angle': angle,
1082
+ 'data-radius-inner': radiusInner,
1083
+ 'data-radius-outer': radiusOuter
1084
+ }
1085
+ });
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+ this.nodes.highlight = highlightGroup;
1095
+ RGraph.SVG.REG.set('highlight', highlightGroup);
1096
+ };
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+ //
1106
+ // Removes any highlight from the chart
1107
+ //
1108
+ this.removeHighlight = function ()
1109
+ {
1110
+ //var highlight = RGraph.SVG.REG.get('highlight');
1111
+
1112
+ //if (highlight && highlight.parentNode) {
1113
+ // highlight.parentNode.removeChild(highlight);
1114
+ //}
1115
+
1116
+ //RGraph.SVG.REG.set('highlight', null);
1117
+
1118
+ RGraph.SVG.removeHighlight();
1119
+ };
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+ //
1129
+ // Draw the labels
1130
+ //
1131
+ this.drawLabels = function ()
1132
+ {
1133
+ // Draw the center label
1134
+ if (properties.labelsCenter) {
1135
+
1136
+ var label = RGraph.SVG.numberFormat({
1137
+ object: this,
1138
+ num: this.value[properties.labelsCenterIndex].toFixed(properties.labelsCenterDecimals),
1139
+ prepend: properties.labelsCenterUnitsPre,
1140
+ append: properties.labelsCenterUnitsPost,
1141
+ point: properties.labelsCenterPoint,
1142
+ thousand: properties.labelsCenterThousand,
1143
+ formatter: properties.labelsCenterFormatter
1144
+ });
1145
+
1146
+
1147
+ // Get the text configuration
1148
+ var textConf = RGraph.SVG.getTextConf({
1149
+ object: this,
1150
+ prefix: 'labelsCenter'
1151
+ });
1152
+
1153
+ var text = RGraph.SVG.text({
1154
+ object: this,
1155
+ parent: this.svg.all,
1156
+ tag: 'labels.center',
1157
+
1158
+ text: typeof properties.labelsCenterSpecific === 'string' ? properties.labelsCenterSpecific : label,
1159
+
1160
+ x: this.centerx + properties.labelsCenterOffsetx,
1161
+ y: this.centery + properties.labelsCenterOffsety,
1162
+
1163
+ valign: properties.labelsCenterValign,
1164
+ halign: properties.labelsCenterHalign,
1165
+
1166
+ font: textConf.font,
1167
+ size: textConf.size,
1168
+ bold: textConf.bold,
1169
+ italic: textConf.italic,
1170
+ color: textConf.color
1171
+ });
1172
+
1173
+ // Store a reference to the center label
1174
+ this.nodes.labelsCenter = text;
1175
+ }
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+ if (properties.labels.length) {
1186
+
1187
+ var textConf = RGraph.SVG.getTextConf({
1188
+ object: this,
1189
+ prefix: 'labels'
1190
+ });
1191
+
1192
+ if (typeof properties.labels === 'string') {
1193
+ properties.labels = RGraph.SVG.arrayPad({
1194
+ array: [],
1195
+ length: this.value.length,
1196
+ value: properties.labels
1197
+ });
1198
+ }
1199
+
1200
+
1201
+ // Loop thru the labels
1202
+ for (var i=0; i<properties.labels.length; ++i) {
1203
+
1204
+ if ( typeof properties.labels === 'object' && properties.labels.length && typeof properties.labels[i] === 'string' ) {
1205
+
1206
+ var text = RGraph.SVG.labelSubstitution({
1207
+ object: this,
1208
+ text: properties.labels[i],
1209
+ index: i,
1210
+ value: this.value[i],
1211
+ decimals: properties.labelsFormattedDecimals,
1212
+ point: properties.labelsFormattedPoint,
1213
+ thousand: properties.labelsFormattedThousand,
1214
+ unitsPre: properties.labelsFormattedUnitsPre,
1215
+ unitsPost: properties.labelsFormattedUnitsPost,
1216
+ });
1217
+ }
1218
+
1219
+ RGraph.SVG.text({
1220
+ object: this,
1221
+ parent: this.svg.all,
1222
+
1223
+ color: textConf.color,
1224
+ font: textConf.font,
1225
+ size: textConf.size,
1226
+ bold: textConf.bold,
1227
+ italic: textConf.italic,
1228
+
1229
+ text: text,
1230
+
1231
+ x: this.centerx - 5 + properties.labelsOffsetx - (properties.ends ? (properties.width / 2) : 0),
1232
+ y: this.centery - this.radius + properties.marginInner + (i * properties.width) + (properties.width / 2) + (i * 2 * properties.marginInner) + properties.labelsOffsety,
1233
+
1234
+ valign: properties.labelsValign,
1235
+ halign: properties.labelsHalign,
1236
+
1237
+ background: properties.labelsBackground,
1238
+
1239
+ padding: 2
1240
+ });
1241
+ }
1242
+ }
1243
+ };
1244
+
1245
+
1246
+
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+ //
1253
+ // Draw icons if they're wanted
1254
+ //
1255
+ this.drawIcons = function ()
1256
+ {
1257
+ if (RGraph.SVG.isArray(properties.icons)) {
1258
+ for (var i=0,images=[]; i<this.value.length; ++i) {
1259
+ if (typeof properties.icons[i] === 'string' && properties.icons[i].length) {
1260
+
1261
+ // Use this to store the SVG image tags that are created in
1262
+ var svg_images = [];
1263
+
1264
+ // A reference to this chart object
1265
+ var obj = this;
1266
+
1267
+
1268
+ images[i] = new Image();
1269
+ images[i].src = properties.icons[i];
1270
+ images[i].index = i;
1271
+
1272
+ svg_images[i] = RGraph.SVG.create({
1273
+ svg: this.svg,
1274
+ parent: this.svg.all,
1275
+ type: 'image',
1276
+ attr: {
1277
+ href: properties.icons[i],
1278
+ x: this.centerx + properties.iconsOffsetx - (properties.ends ? (properties.width / 2) : 0) + 5,
1279
+ y: this.centery - this.radius + properties.marginInner + (i * properties.width) + (properties.width / 2) + (i * 2 * properties.marginInner) + properties.iconsOffsety,
1280
+ index: i
1281
+ }
1282
+ });
1283
+
1284
+ // Set the width/height on the image if requested
1285
+ if (typeof properties.iconsWidth === 'number') svg_images[i].setAttribute('width', properties.iconsWidth);
1286
+ if (typeof properties.iconsHeight === 'number') svg_images[i].setAttribute('height', properties.iconsHeight);
1287
+
1288
+ // Now move the SVG image as required
1289
+ svg_images[i].onload = function ()
1290
+ {
1291
+ var index = this.getAttribute('index'),
1292
+ width = properties.iconsWidth || images[index].width,
1293
+ height = properties.iconsHeight || images[index].height;
1294
+
1295
+ // Reposition the image
1296
+ //this.setAttribute('x', parseInt(this.getAttribute('x')) + (width / 2));
1297
+ this.setAttribute('y', parseInt(this.getAttribute('y')) - (height / 2));
1298
+ }
1299
+ }
1300
+ }
1301
+ }
1302
+ };
1303
+
1304
+
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+
1311
+ //
1312
+ // This allows for easy specification of gradients
1313
+ //
1314
+ this.parseColors = function ()
1315
+ {
1316
+ // Save the original colors so that they can be restored when the canvas is reset
1317
+ if (!Object.keys(this.originalColors).length) {
1318
+ this.originalColors = {
1319
+ colors: RGraph.SVG.arrayClone(properties.colors),
1320
+ backgroundColor: RGraph.SVG.arrayClone(properties.backgroundColor)
1321
+ }
1322
+ }
1323
+
1324
+ // colors
1325
+ var colors = properties.colors;
1326
+
1327
+ if (colors) {
1328
+ for (var i=0; i<colors.length; ++i) {
1329
+ colors[i] = RGraph.SVG.parseColorLinear({
1330
+ object: this,
1331
+ color: colors[i],
1332
+ start: this.centerx - this.radius,
1333
+ end: this.centerx + this.radius,
1334
+ direction: 'horizontal'
1335
+ });
1336
+ }
1337
+ }
1338
+
1339
+ // Background color
1340
+ properties.backgroundColor = RGraph.SVG.parseColorLinear({
1341
+ object: this,
1342
+ color: properties.backgroundColor,
1343
+ start: properties.marginLeft,
1344
+ end: this.width - properties.marginRight,
1345
+ direction: 'horizontal'
1346
+ });
1347
+ };
1348
+
1349
+
1350
+
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+ //
1357
+ // Using a function to add events makes it easier to facilitate method
1358
+ // chaining
1359
+ //
1360
+ // @param string type The type of even to add
1361
+ // @param function func
1362
+ //
1363
+ this.on = function (type, func)
1364
+ {
1365
+ if (type.substr(0,2) !== 'on') {
1366
+ type = 'on' + type;
1367
+ }
1368
+
1369
+ RGraph.SVG.addCustomEventListener(this, type, func);
1370
+
1371
+ return this;
1372
+ };
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1381
+ //
1382
+ // Used in chaining. Runs a function there and then - not waiting for
1383
+ // the events to fire (eg the onbeforedraw event)
1384
+ //
1385
+ // @param function func The function to execute
1386
+ //
1387
+ this.exec = function (func)
1388
+ {
1389
+ func(this);
1390
+
1391
+ return this;
1392
+ };
1393
+
1394
+
1395
+
1396
+
1397
+
1398
+
1399
+
1400
+
1401
+ //
1402
+ // This function returns the pertinent angle for a particular click (or other mouse event)
1403
+ //
1404
+ // @param obj e The event object
1405
+ // OR
1406
+ // int e An integer value for
1407
+ // which to the relevant
1408
+ // angle
1409
+ //
1410
+ this.getAngle = function (e)
1411
+ {
1412
+ if (typeof e === 'number') {
1413
+ var angle = ((e - this.min) / (this.max - this.min)) * RGraph.SVG.TRIG.TWOPI;
1414
+ angle -= RGraph.SVG.TRIG.HALFPI;
1415
+
1416
+ } else {
1417
+ var mouseX = e.offsetX,
1418
+ mouseY = e.offsetY;
1419
+
1420
+ var angle = RGraph.SVG.TRIG.getAngleByXY({
1421
+ cx: this.centerx,
1422
+ cy: this.centery,
1423
+ x: mouseX,
1424
+ y: mouseY
1425
+ });
1426
+
1427
+ angle -= RGraph.SVG.TRIG.HALFPI;
1428
+ }
1429
+
1430
+ return angle;
1431
+ };
1432
+
1433
+
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+
1440
+ //
1441
+ // This function returns the pertinent value for a particular click (or other mouse event)
1442
+ //
1443
+ // @param obj e The event object
1444
+ //
1445
+ //
1446
+ this.getValue = function (e)
1447
+ {
1448
+ // Treat the argument as an angle (given in radians)
1449
+ if (typeof e === 'number') {
1450
+ var angle = e;
1451
+
1452
+ // Treat the argument as an event object
1453
+ } else {
1454
+ // Get the angle of the click
1455
+ var angle = this.getAngle(e);
1456
+ }
1457
+
1458
+ // Calculate the value based on the angle and min/max values
1459
+ var value = (((angle + RGraph.SVG.TRIG.HALFPI) / RGraph.SVG.TRIG.TWOPI) * (this.max - this.min)) + this.min;
1460
+
1461
+ // Ensure that the value is in range
1462
+ value = Math.max(value, this.min);
1463
+ value = Math.min(value, this.max);
1464
+
1465
+ return value;
1466
+ };
1467
+
1468
+
1469
+
1470
+
1471
+
1472
+
1473
+
1474
+
1475
+ //
1476
+ // This function returns the pertinent radius (from the centerx/y) of a given event object
1477
+ // (eg from a click or mouse event).
1478
+ //
1479
+ // @param obj e The event object
1480
+ //
1481
+ this.getRadius = function (e)
1482
+ {
1483
+ var x = e.offsetX,
1484
+ y = e.offsetY;
1485
+
1486
+ var radius = RGraph.SVG.TRIG.getHypLength({
1487
+ x1: x,
1488
+ y1: y,
1489
+ x2: this.centerx,
1490
+ y2: this.centery
1491
+ });
1492
+
1493
+ return radius;
1494
+ };
1495
+
1496
+
1497
+
1498
+
1499
+
1500
+
1501
+
1502
+
1503
+ //
1504
+ // SVG Activity meter grow()
1505
+ //
1506
+ // This effect gradually increases the represented value
1507
+ //
1508
+ // @param An object of options - eg: {frames: 60}
1509
+ // @param function An optional callback function
1510
+ //
1511
+ this.grow = function ()
1512
+ {
1513
+ var obj = this;
1514
+
1515
+
1516
+ //
1517
+ // Convert the value to an array if its a number
1518
+ //
1519
+ if (typeof this.value === 'number') {
1520
+ this.value = [this.value];
1521
+ }
1522
+
1523
+ //this.currentValue = this.currentValue || obj.min;
1524
+ if (RGraph.SVG.isNull(this.currentValue)) {
1525
+
1526
+ this.currentValue = [];
1527
+
1528
+ for (var i=0; i<this.value.length; ++i) {
1529
+ this.currentValue[i] = this.min;
1530
+ }
1531
+ }
1532
+
1533
+ var opt = arguments[0] || {},
1534
+ frames = opt.frames || 30,
1535
+ frame = 0,
1536
+ diff = [],
1537
+ step = [],
1538
+ callback = arguments[1] || function () {},
1539
+ initial = [];
1540
+
1541
+ // Set a few properties too by looping through the data
1542
+ for (var i=0; i<this.value.length; ++i) {
1543
+ diff[i] = this.value[i] - this.currentValue[i];
1544
+ step[i] = diff[i] / frames;
1545
+ initial[i] = this.currentValue[i];
1546
+ }
1547
+
1548
+
1549
+
1550
+
1551
+
1552
+ function iterator ()
1553
+ {
1554
+ for (var i=0; i<obj.value.length; ++i) {
1555
+ obj.value[i] = initial[i] + (frame * step[i]);
1556
+ }
1557
+
1558
+ // Increment the frame
1559
+ frame++;
1560
+
1561
+ RGraph.SVG.clear(obj.svg);
1562
+ RGraph.SVG.redraw();
1563
+
1564
+ if (frame <= frames) {
1565
+ RGraph.SVG.FX.update(iterator);
1566
+ } else {
1567
+ callback(obj);
1568
+ }
1569
+ }
1570
+
1571
+ iterator();
1572
+
1573
+ return this;
1574
+ };
1575
+
1576
+
1577
+
1578
+
1579
+
1580
+
1581
+
1582
+
1583
+ //
1584
+ // A worker function that handles Bar chart specific tooltip substitutions
1585
+ //
1586
+ this.tooltipSubstitutions = function (opt)
1587
+ {
1588
+ var indexes = [0, opt.index];
1589
+
1590
+ return {
1591
+ index: indexes[1],
1592
+ dataset: indexes[0],
1593
+ sequentialIndex: indexes[1],
1594
+ value: this.value[indexes[1]],
1595
+ values: [this.value[indexes[1]]]
1596
+ };
1597
+ };
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+ //
1607
+ // A worker function that returns the correct color/label/value
1608
+ //
1609
+ // @param object specific The indexes that are applicable
1610
+ // @param number index The appropriate index
1611
+ //
1612
+ this.tooltipsFormattedCustom = function (specific, index)
1613
+ {
1614
+ return {
1615
+ label: (RGraph.SVG.isArray(properties.tooltipsFormattedKeyLabels) && typeof properties.tooltipsFormattedKeyLabels[specific.index] === 'string') ? properties.tooltipsFormattedKeyLabels[specific.index] : properties.labels[specific.index],
1616
+ color: (RGraph.SVG.isArray(properties.tooltipsFormattedKeyColors) && properties.tooltipsFormattedKeyColors[specific.index]) ? properties.tooltipsFormattedKeyColors[specific.index] : properties.colors[specific.index],
1617
+ value: this.value[specific.index]
1618
+ };
1619
+ };
1620
+
1621
+
1622
+
1623
+
1624
+
1625
+
1626
+
1627
+
1628
+ //
1629
+ // This allows for static tooltip positioning
1630
+ //
1631
+ this.positionTooltipStatic = function (args)
1632
+ {
1633
+ var obj = args.object,
1634
+ e = args.event,
1635
+ tooltip = args.tooltip,
1636
+ index = args.index,
1637
+ svgXY = RGraph.SVG.getSVGXY(obj.svg),
1638
+ radiusOuter = parseFloat(this.nodes.bars[index].firstChild.getAttribute('data-radius-outer')),
1639
+ radiusInner = parseFloat(this.nodes.bars[index].firstChild.getAttribute('data-radius-inner')),
1640
+ start = parseFloat(this.nodes.bars[index].firstChild.getAttribute('data-start-angle')) - RGraph.SVG.TRIG.HALFPI;
1641
+ end = parseFloat(this.nodes.bars[index].firstChild.getAttribute('data-end-angle')) - RGraph.SVG.TRIG.HALFPI;
1642
+
1643
+
1644
+
1645
+ var endpoint = RGraph.SVG.TRIG.getRadiusEndPoint({
1646
+ cx: this.centerx,
1647
+ cy: this.centery,
1648
+ radius: radiusInner + ((radiusOuter - radiusInner) / 2) ,
1649
+ angle: ((end - start) / 2) + start
1650
+ });
1651
+
1652
+ // Position the tooltip in the X direction
1653
+ args.tooltip.style.left = (
1654
+ svgXY[0] // The X coordinate of the canvas
1655
+ + (this.centerx + endpoint[0])
1656
+ - (tooltip.offsetWidth / 2) // Subtract half of the tooltip width
1657
+ ) + 'px';
1658
+
1659
+ // Position the tooltip in the Y direction
1660
+ args.tooltip.style.top = (
1661
+ svgXY[1] // The Y coordinate of the canvas
1662
+ + (this.centery + endpoint[1]) // The Y coordinate of the position
1663
+ - tooltip.offsetHeight // The height of the tooltip
1664
+ - 10 // An arbitrary amount
1665
+ ) + 'px';
1666
+ };
1667
+
1668
+
1669
+
1670
+
1671
+
1672
+
1673
+
1674
+ //
1675
+ // Set the options that the user has provided
1676
+ //
1677
+ for (i in conf.options) {
1678
+ if (typeof i === 'string') {
1679
+ this.set(i, conf.options[i]);
1680
+ }
1681
+ }
1682
+
1683
+
1684
+
1685
+ return this;
1686
+ };
1687
+
1688
+
1689
+
1690
+
1691
+
1692
+
1693
+
1694
+
1695
+ // End module pattern
1696
+ })(window, document);