RGraph.fuel.js
29.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
// version: 2014-08-16
/**
* o--------------------------------------------------------------------------------o
* | This file is part of the RGraph package - you can learn more at: |
* | |
* | http://www.rgraph.net |
* | |
* | This package is licensed under the Creative Commons BY-NC license. That means |
* | that for non-commercial purposes it's free to use and for business use there's |
* | a 99 GBP per-company fee to pay. You can read the full license here: |
* | |
* | http://www.rgraph.net/license |
* o--------------------------------------------------------------------------------o
*/
RGraph = window.RGraph || {isRGraph: true};
/**
* The Fuel widget constructor
*
* @param object canvas The canvas object
* @param int min The minimum value
* @param int max The maximum value
* @param int value The indicated value
*/
RGraph.Fuel = function (conf)
{
/**
* Allow for object config style
*/
if ( typeof conf === 'object'
&& typeof conf.min === 'number'
&& typeof conf.max === 'number'
&& typeof conf.id === 'string') {
var id = conf.id
var canvas = document.getElementById(id);
var min = conf.min;
var max = conf.max;
var value = conf.value;
var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor)
} else {
var id = conf;
var canvas = document.getElementById(id);
var min = arguments[1];
var max = arguments[2];
var value = arguments[3];
}
// Get the canvas and context objects
this.id = id;
this.canvas = canvas;
this.context = this.canvas.getContext ? this.canvas.getContext("2d", {alpha: (typeof id === 'object' && id.alpha === false) ? false : true}) : null;
this.canvas.__object__ = this;
this.type = 'fuel';
this.isRGraph = true;
this.min = min;
this.max = max;
this.value = RGraph.stringsToNumbers(value);
this.angles = {};
this.currentValue = null;
this.uid = RGraph.CreateUID();
this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
this.coordsText = [];
this.original_colors = [];
this.firstDraw = true; // After the first draw this will be false
/**
* Compatibility with older browsers
*/
//RGraph.OldBrowserCompat(this.context);
// Check for support
if (!this.canvas) {
alert('[FUEL] No canvas support');
return;
}
/**
* The funnel charts properties
*/
this.properties =
{
'chart.colors': ['Gradient(white:red)'],
'chart.needle.color': 'red',
'chart.gutter.left': 5,
'chart.gutter.right': 5,
'chart.gutter.top': 5,
'chart.gutter.bottom': 5,
'chart.text.size': 10,
'chart.text.color': 'black', // Does not support gradients
'chart.text.font': 'Arial',
'chart.contextmenu': null,
'chart.annotatable': false,
'chart.annotate.color': 'black',
'chart.zoom.factor': 1.5,
'chart.zoom.fade.in': true,
'chart.zoom.fade.out': true,
'chart.zoom.factor': 1.5,
'chart.zoom.fade.in': true,
'chart.zoom.fade.out': true,
'chart.zoom.hdir': 'right',
'chart.zoom.vdir': 'down',
'chart.zoom.frames': 25,
'chart.zoom.delay': 16.666,
'chart.zoom.shadow': true,
'chart.zoom.background': true,
'chart.zoom.action': 'zoom',
'chart.adjustable': false,
'chart.resizable': false,
'chart.resize.handle.background': null,
'chart.icon': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAfCAYAAAD0ma06AAAEGElEQVRIS7VXSyhtYRT+jnfe5FEMjAwUBiQGHikzRWIkkgy8YyDK+xnJK5JCeZSUGKBMiAyYkMxMJAMpSfJ+2/d8695/33NunSPnHqt2Z5+91/9/' + '/' + '/et9a/1b8Pn56dmMBhg/IWDgwNoNzc38PHxkXtN0+Tiexp9eH18fIDj1Bj63N/fw8vLS/wsmcHoqKmXT09PuL29RVFREU5OTvTJ6UIAgioQ+vLe09MTb29v8PX1RWBgICYnJ+XXIqDRWXN0dJT3nIDsWlpadP+lpSWZlD4KmL/8/' + '/7+Ls/S09N1/7y8PISHh+sK/QssDJWcHEyGCnB1dRUDAwPIzMzUx5GpAnZ1dcXy8jK2trbM5j06OsLc3JzISx8q4OzsLOOsAq6treHg4AAeHh4WJbq7u0Nzc7P+PiYmBnt7ezg9PcXExAQCAgLg5OSEx8dHuLu7Wwfc3t7G/v6+yEcjO8rIROGKaWdnZ+jr6zMDjI6OxvT0tDzr6uqS2KtksspwZ2cHjY2NuqSUhnHmilUCraysmElaWloKJpQCjI2NRX5+Pl5eXr6WlCv08/MTEMVOZDH+Zzw4CdlfX1/rDHt7ezE1NQXGkcYEKi4ulkVKYlpLGouBs/JiaGgIZL25uSlecXFxohAz/ccAz8/P4e/vj7q6Ojw8PMje5DNRy94MQ0JCUFtbK2wqKipE+sHBQbi4uPwMQ86ak5ODxMREVFdXIywsDCUlJRJDXnZlmJqaip6eHuTm5kqikGlycjIyMjL+ZrY9JSUgMzQiIgINDQ2ypaqqqkCZWXHsnjQEHB8fR0pKigAxabq7uyWOlJNxtLukTJDs7GxUVlZKDNl5oqKi8Pr6+jOAIyMjiI+Pl5JGQG4F1Qy+LN7f3fiUdGZmBsHBwRgbG8Pw8LD01ba2NmlX0rTtnTQLCwvSjEdHR3FxcSExLCwsRGRkpBR9vePzeMDyw3bT1NT0XXLiT4a7u7s4Pj4GGzd7K8GCgoKEsRR8I4Cm6hwHXV5eiv62GAE5npMTmFuBTCkzmzT7qs5Q9TlW/o6ODlvwhCHPM5SVPZIxYzNeXFxEa2srvL29YTC2GI3aMm3Zeq6urv4LMC0tDRsbG1K8k5KS9DgS0IwhKVFjSsJA22r9/f0oKCgQdvPz83JEmZ2dlcpD9maSshow0KZnlO8Csx9yK3BLKCMJPpf2xGMigdi9WXooaWdn53dxdP+amhrZh4eHh1hfX5cTW319vZyBnp+ffzNkBWBmhYaGysB/j322oCckJCArK0uGMlsJ5ubmBoPxRiMzFlomjr2MGdne3i5ANILRJEtJt6ysTG8h9gDl4am8vFwSUWron1O9LulXIOqk9pWftfdSS40yyj5Uh101wPRryuR7R1ZMX/U1pfy5IF40xcgUnGAc9wsGYxsFhy87kwAAAABJRU5ErkJggg==',
'chart.icon.redraw': true,
'chart.background.image.stretch': false,
'chart.background.image.x': null,
'chart.background.image.y': null,
'chart.labels.full': 'F',
'chart.labels.empty': 'E',
'chart.labels.count': 5,
'chart.centerx': null,
'chart.centery': null,
'chart.radius': null,
'chart.scale.visible': false,
'chart.scale.decimals': 0,
'chart.units.pre': '',
'chart.units.post': ''
}
/**
* Bounds checking - if the value is outside the scale
*/
if (this.value > this.max) this.value = this.max;
if (this.value < this.min) this.value = this.min;
/*
* Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
* done already
*/
if (!this.canvas.__rgraph_aa_translated__) {
this.context.translate(0.5,0.5);
this.canvas.__rgraph_aa_translated__ = true;
}
// Short variable names
var RG = RGraph;
var ca = this.canvas;
var co = ca.getContext('2d');
var prop = this.properties;
var jq = jQuery;
var pa = RG.Path;
var win = window;
var doc = document;
var ma = Math;
/**
* "Decorate" the object with the generic effects if the effects library has been included
*/
if (RG.Effects && typeof RG.Effects.decorate === 'function') {
RG.Effects.decorate(this);
}
/**
* A setter
*
* @param name string The name of the property to set
* @param value mixed The value of the property
*/
this.set =
this.Set = function (name)
{
var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
/**
* the number of arguments is only one and it's an
* object - parse it for configuration data and return.
*/
if (arguments.length === 1 && typeof name === 'object') {
RG.parseObjectStyleConfig(this, name);
return this;
}
name = name.toLowerCase();
/**
* This should be done first - prepend the propertyy name with "chart." if necessary
*/
if (name.substr(0,6) != 'chart.') {
name = 'chart.' + name;
}
prop[name] = value;
return this;
};
/**
* A getter
*
* @param name string The name of the property to get
*/
this.get =
this.Get = function (name)
{
/**
* This should be done first - prepend the property name with "chart." if necessary
*/
if (name.substr(0,6) != 'chart.') {
name = 'chart.' + name;
}
return prop[name.toLowerCase()];
};
/**
* The function you call to draw the bar chart
*/
this.draw =
this.Draw = function ()
{
/**
* Fire the onbeforedraw event
*/
RG.FireCustomEvent(this, 'onbeforedraw');
/**
* Set the current value
*/
this.currentValue = this.value;
/**
* This is new in May 2011 and facilitates indiviual gutter settings,
* eg chart.gutter.left
*/
this.gutterLeft = prop['chart.gutter.left'];
this.gutterRight = prop['chart.gutter.right'];
this.gutterTop = prop['chart.gutter.top'];
this.gutterBottom = prop['chart.gutter.bottom'];
/**
* Get the center X and Y of the chart. This is the center of the needle bulb
*/
this.centerx = ((ca.width - this.gutterLeft - this.gutterRight) / 2) + this.gutterLeft;
this.centery = ca.height - 20 - this.gutterBottom
/**
* Work out the radius of the chart
*/
this.radius = ca.height - this.gutterTop - this.gutterBottom - 20;
/**
* Stop this growing uncntrollably
*/
this.coordsText = [];
/**
* You can now specify chart.centerx, chart.centery and chart.radius
*/
if (typeof(prop['chart.centerx']) == 'number') this.centerx = prop['chart.centerx'];
if (typeof(prop['chart.centery']) == 'number') this.centery = prop['chart.centery'];
if (typeof(prop['chart.radius']) == 'number') this.radius = prop['chart.radius'];
/**
* Parse the colors. This allows for simple gradient syntax
*/
if (!this.colorsParsed) {
this.parseColors();
// Don't want to do this again
this.colorsParsed = true;
}
/**
* The start and end angles of the chart
*/
this.angles.start = (RG.PI + RG.HALFPI) - 0.5;
this.angles.end = (RG.PI + RG.HALFPI) + 0.5;
this.angles.needle = this.getAngle(this.value);
/**
* Draw the labels on the chart
*/
this.DrawLabels();
/**
* Draw the fuel guage
*/
this.DrawChart();
/**
* Setup the context menu if required
*/
if (prop['chart.contextmenu']) {
RG.ShowContext(this);
}
/**
* This function enables resizing
*/
if (prop['chart.resizable']) {
RG.AllowResizing(this);
}
/**
* This installs the event listeners
*/
RG.InstallEventListeners(this);
/**
* Fire the onfirstdraw event
*/
if (this.firstDraw) {
RG.fireCustomEvent(this, 'onfirstdraw');
this.firstDraw = false;
this.firstDrawFunc();
}
/**
* Fire the RGraph ondraw event
*/
RG.FireCustomEvent(this, 'ondraw');
return this;
};
/**
* This function actually draws the chart
*/
this.drawChart =
this.DrawChart = function ()
{
/**
* Draw the "Scale"
*/
this.DrawScale();
/**
* Place the icon on the canvas
*/
if (!RG.ISOLD) {
this.DrawIcon();
}
/**
* Draw the needle
*/
this.DrawNeedle();
};
/**
* Draws the labels
*/
this.drawLabels =
this.DrawLabels = function ()
{
if (!prop['chart.scale.visible']) {
var radius = (this.radius - 20);
co.fillStyle = prop['chart.text.color'];
// Draw the left label
var y = this.centery - Math.sin(this.angles.start - RG.PI) * (this.radius - 25);
var x = this.centerx - Math.cos(this.angles.start - RG.PI) * (this.radius - 25);
RG.Text2(this, {'font':prop['chart.text.font'],
'size':prop['chart.text.size'],
'x':x,
'y':y,
'text':prop['chart.labels.empty'],
'halign': 'center',
'valign':'center',
'tag': 'labels'
});
// Draw the right label
var y = this.centery - Math.sin(this.angles.start - RG.PI) * (this.radius - 25);
var x = this.centerx + Math.cos(this.angles.start - RG.PI) * (this.radius - 25);
RG.Text2(this, {'font':prop['chart.text.font'],
'size':prop['chart.text.size'],
'x':x,
'y':y,
'text':prop['chart.labels.full'],
'halign': 'center',
'valign':'center',
'tag': 'labels'
});
}
};
/**
* Draws the needle
*/
this.drawNeedle =
this.DrawNeedle = function ()
{
// Draw the actual needle
co.beginPath();
co.lineWidth = 5;
co.lineCap = 'round';
co.strokeStyle = prop['chart.needle.color'];
/**
* The angle for the needle
*/
var angle = this.angles.needle;
co.arc(this.centerx, this.centery, this.radius - 30, angle, angle + 0.0001, false);
co.lineTo(this.centerx, this.centery);
co.stroke();
co.lineWidth = 1;
// Create the gradient for the bulb
var cx = this.centerx + 10;
var cy = this.centery - 10
var grad = co.createRadialGradient(cx, cy, 35, cx, cy, 0);
grad.addColorStop(0, 'black');
grad.addColorStop(1, '#eee');
if (navigator.userAgent.indexOf('Firefox/6.0') > 0) {
grad = co.createLinearGradient(cx + 10, cy - 10, cx - 10, cy + 10);
grad.addColorStop(1, '#666');
grad.addColorStop(0.5, '#ccc');
}
// Draw the bulb
co.beginPath();
co.fillStyle = grad;
co.moveTo(this.centerx, this.centery);
co.arc(this.centerx, this.centery, 20, 0, RG.TWOPI, 0);
co.fill();
};
/**
* Draws the "scale"
*/
this.drawScale =
this.DrawScale = function ()
{
var a, x, y;
//First draw the fill background
co.beginPath();
co.strokeStyle = 'black';
co.fillStyle = 'white';
co.arc(this.centerx, this.centery, this.radius, this.angles.start, this.angles.end, false);
co.arc(this.centerx, this.centery, this.radius - 10, this.angles.end, this.angles.start, true);
co.closePath();
co.stroke();
co.fill();
//First draw the fill itself
var start = this.angles.start;
var end = this.angles.needle;
co.beginPath();
co.fillStyle = prop['chart.colors'][0];
co.arc(this.centerx, this.centery, this.radius, start, end, false);
co.arc(this.centerx, this.centery, this.radius - 10, end, start, true);
co.closePath();
//co.stroke();
co.fill();
// This draws the tickmarks
for (a = this.angles.start; a<=this.angles.end+0.01; a+=((this.angles.end - this.angles.start) / 5)) {
co.beginPath();
co.arc(this.centerx, this.centery, this.radius - 10, a, a + 0.0001, false);
co.arc(this.centerx, this.centery, this.radius - 15, a + 0.0001, a, true);
co.stroke();
}
/**
* If chart.scale.visible is specified draw the textual scale
*/
if (prop['chart.scale.visible']) {
co.fillStyle = prop['chart.text.color'];
// The labels
var numLabels = prop['chart.labels.count'];
var decimals = prop['chart.scale.decimals'];
var font = prop['chart.text.font'];
var size = prop['chart.text.size'];
var units_post = prop['chart.units.post'];
var units_pre = prop['chart.units.pre'];
for (var i=0; i<=numLabels; ++i) {
a = ((this.angles.end - this.angles.start) * (i/numLabels)) + this.angles.start;
y = this.centery - Math.sin(a - RG.PI) * (this.radius - 25);
x = this.centerx - Math.cos(a - RG.PI) * (this.radius - 25);
RG.Text2(this, {'font':font,
'size':size,
'x':x,
'y':y,
'text': RG.number_format(this, (this.min + ((this.max - this.min) * (i/numLabels))).toFixed(decimals),units_pre,units_post),
'halign': 'center',
'valign':'center',
'tag': 'scale'
});
}
}
};
/**
* A placeholder function that is here to prevent errors
*/
this.getShape = function (e) {};
/**
* This function returns the pertinent value based on a click
*
* @param object e An event object
* @return number The relevant value at the point of click
*/
this.getValue = function (e)
{
var mouseXY = RG.getMouseXY(e);
var angle = RG.getAngleByXY(this.centerx, this.centery, mouseXY[0], mouseXY[1]);
/**
* Boundary checking
*/
if (angle >= this.angles.end) {
return this.max;
} else if (angle <= this.angles.start) {
return this.min;
}
var value = (angle - this.angles.start) / (this.angles.end - this.angles.start);
value = value * (this.max - this.min);
value = value + this.min;
return value;
};
/**
* The getObjectByXY() worker method. Don't call this call:
*
* RG.ObjectRegistry.getObjectByXY(e)
*
* @param object e The event object
*/
this.getObjectByXY = function (e)
{
var mouseXY = RG.getMouseXY(e);
var angle = RG.getAngleByXY(this.centerx, this.centery, mouseXY[0], mouseXY[1]);
var accuracy = 15;
var leftMin = this.centerx - this.radius;
var rightMax = this.centerx + this.radius;
var topMin = this.centery - this.radius;
var bottomMax = this.centery + this.radius;
if (
mouseXY[0] > leftMin
&& mouseXY[0] < rightMax
&& mouseXY[1] > topMin
&& mouseXY[1] < bottomMax
) {
return this;
}
};
/**
* Draws the icon
*/
this.drawIcon =
this.DrawIcon = function ()
{
if (!RG.ISOLD) {
if (!this.__icon__ || !this.__icon__.__loaded__) {
var img = new Image();
img.src = prop['chart.icon'];
img.__object__ = this;
this.__icon__ = img;
img.onload = function (e)
{
img.__loaded__ = true;
var obj = img.__object__;
//var co = obj.context;
//var prop = obj.properties;
co.drawImage(img,obj.centerx - (img.width / 2), obj.centery - obj.radius + 35);
obj.DrawNeedle();
if (prop['chart.icon.redraw']) {
obj.Set('chart.icon.redraw', false);
RG.Clear(obj.canvas);
RG.RedrawCanvas(ca);
}
}
} else {
var img = this.__icon__;
co.drawImage(img,this.centerx - (img.width / 2), this.centery - this.radius + 35);
}
}
this.DrawNeedle();
};
/**
* This method handles the adjusting calculation for when the mouse is moved
*
* @param object e The event object
*/
this.adjusting_mousemove =
this.Adjusting_mousemove = function (e)
{
/**
* Handle adjusting for the Fuel gauge
*/
if (prop['chart.adjustable'] && RG.Registry.Get('chart.adjusting') && RG.Registry.Get('chart.adjusting').uid == this.uid) {
this.value = this.getValue(e);
//RG.Clear(ca);
RG.redrawCanvas(ca);
RG.fireCustomEvent(this, 'onadjust');
}
};
/**
* This method gives you the relevant angle (in radians) that a particular value is
*
* @param number value The relevant angle
*/
this.getAngle = function (value)
{
// Range checking
if (value < this.min || value > this.max) {
return null;
}
var angle = (((value - this.min) / (this.max - this.min)) * (this.angles.end - this.angles.start)) + this.angles.start;
return angle;
};
/**
* This allows for easy specification of gradients
*/
this.parseColors = function ()
{
// Save the original colors so that they can be restored when the canvas is reset
if (this.original_colors.length === 0) {
this.original_colors['chart.colors'] = RG.array_clone(prop['chart.colors']);
this.original_colors['chart.needle.color'] = RG.array_clone(prop['chart.needle.color']);
}
var props = this.properties;
var colors = props['chart.colors'];
for (var i=0; i<colors.length; ++i) {
colors[i] = this.parseSingleColorForLinearGradient(colors[i]);
}
props['chart.needle.color'] = this.parseSingleColorForRadialGradient(props['chart.needle.color']);
};
/**
* Use this function to reset the object to the post-constructor state. Eg reset colors if
* need be etc
*/
this.reset = function ()
{
};
/**
* This parses a single color value
*/
this.parseSingleColorForLinearGradient = function (color)
{
if (!color || typeof(color) != 'string') {
return color;
}
if (color.match(/^gradient\((.*)\)$/i)) {
var parts = RegExp.$1.split(':');
// Create the gradient
var grad = co.createLinearGradient(prop['chart.gutter.left'],0,ca.width - prop['chart.gutter.right'],0);
var diff = 1 / (parts.length - 1);
grad.addColorStop(0, RG.trim(parts[0]));
for (var j=1; j<parts.length; ++j) {
grad.addColorStop(j * diff, RG.trim(parts[j]));
}
}
return grad ? grad : color;
};
/**
* This parses a single color value
*/
this.parseSingleColorForRadialGradient = function (color)
{
if (!color || typeof color != 'string') {
return color;
}
if (color.match(/^gradient\((.*)\)$/i)) {
var parts = RegExp.$1.split(':');
// Create the gradient
var grad = co.createRadialGradient(this.centerx, this.centery, 0, this.centerx, this.centery, this.radius);
var diff = 1 / (parts.length - 1);
grad.addColorStop(0, RG.trim(parts[0]));
for (var j=1; j<parts.length; ++j) {
grad.addColorStop(j * diff, RG.trim(parts[j]));
}
}
return grad ? grad : color;
};
/**
* Using a function to add events makes it easier to facilitate method chaining
*
* @param string type The type of even to add
* @param function func
*/
this.on = function (type, func)
{
if (type.substr(0,2) !== 'on') {
type = 'on' + type;
}
this[type] = func;
return this;
};
/**
* This function runs once only
* (put at the end of the file (before any effects))
*/
this.firstDrawFunc = function ()
{
};
/**
* Grow
*
* The Fuel chart Grow effect gradually increases the values of the Fuel chart
*
* @param object obj The graph object
*/
this.grow = function ()
{
var callback = arguments[1] || function () {};
var opt = arguments[0] || {};
var numFrames = opt.frames || 30;
var frame = 0;
var obj = this;
var origValue = Number(this.currentValue);
if (this.currentValue == null) {
this.currentValue = this.min;
origValue = this.min;
}
var newValue = this.value;
var diff = newValue - origValue;
var step = (diff / numFrames);
var frame = 0;
function iterator ()
{
frame++;
obj.value = ((frame / numFrames) * diff) + origValue
if (obj.value > obj.max) obj.value = obj.max;
if (obj.value < obj.min) obj.value = obj.min;
RGraph.clear(obj.canvas);
RGraph.redrawCanvas(obj.canvas);
if (frame < numFrames) {
RGraph.Effects.updateCanvas(iterator);
// The callback variable is always function
} else {
callback(obj);
}
}
iterator();
return this;
};
/**
* Now need to register all chart types. MUST be after the setters/getters are defined
*
* *** MUST BE LAST IN THE CONSTRUCTOR ***
*/
RG.Register(this);
/**
* This is the 'end' of the constructor so if the first argument
* contains configuration data - handle that.
*/
if (parseConfObjectForOptions) {
RG.parseObjectStyleConfig(this, conf.options);
}
};