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