rgraph-rails 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/README.md +73 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/lib/rgraph-rails/version.rb +3 -0
  12. data/lib/rgraph-rails.rb +8 -0
  13. data/license.txt +19 -0
  14. data/rgraph-rails.gemspec +26 -0
  15. data/vendor/assets/images/bg.png +0 -0
  16. data/vendor/assets/images/bullet.png +0 -0
  17. data/vendor/assets/images/facebook-large.png +0 -0
  18. data/vendor/assets/images/google-plus-large.png +0 -0
  19. data/vendor/assets/images/logo.png +0 -0
  20. data/vendor/assets/images/meter-image-sd-needle.png +0 -0
  21. data/vendor/assets/images/meter-image-sd.png +0 -0
  22. data/vendor/assets/images/meter-sketch-needle.png +0 -0
  23. data/vendor/assets/images/meter-sketch.png +0 -0
  24. data/vendor/assets/images/odometer-background.png +0 -0
  25. data/vendor/assets/images/rgraph.jpg +0 -0
  26. data/vendor/assets/images/title.png +0 -0
  27. data/vendor/assets/images/twitter-large.png +0 -0
  28. data/vendor/assets/javascripts/RGraph.bar.js +3246 -0
  29. data/vendor/assets/javascripts/RGraph.bipolar.js +2003 -0
  30. data/vendor/assets/javascripts/RGraph.common.annotate.js +399 -0
  31. data/vendor/assets/javascripts/RGraph.common.context.js +600 -0
  32. data/vendor/assets/javascripts/RGraph.common.core.js +4751 -0
  33. data/vendor/assets/javascripts/RGraph.common.csv.js +275 -0
  34. data/vendor/assets/javascripts/RGraph.common.deprecated.js +454 -0
  35. data/vendor/assets/javascripts/RGraph.common.dynamic.js +1194 -0
  36. data/vendor/assets/javascripts/RGraph.common.effects.js +1524 -0
  37. data/vendor/assets/javascripts/RGraph.common.key.js +735 -0
  38. data/vendor/assets/javascripts/RGraph.common.resizing.js +550 -0
  39. data/vendor/assets/javascripts/RGraph.common.tooltips.js +605 -0
  40. data/vendor/assets/javascripts/RGraph.common.zoom.js +223 -0
  41. data/vendor/assets/javascripts/RGraph.drawing.background.js +636 -0
  42. data/vendor/assets/javascripts/RGraph.drawing.circle.js +579 -0
  43. data/vendor/assets/javascripts/RGraph.drawing.image.js +810 -0
  44. data/vendor/assets/javascripts/RGraph.drawing.marker1.js +710 -0
  45. data/vendor/assets/javascripts/RGraph.drawing.marker2.js +672 -0
  46. data/vendor/assets/javascripts/RGraph.drawing.marker3.js +568 -0
  47. data/vendor/assets/javascripts/RGraph.drawing.poly.js +623 -0
  48. data/vendor/assets/javascripts/RGraph.drawing.rect.js +603 -0
  49. data/vendor/assets/javascripts/RGraph.drawing.text.js +648 -0
  50. data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +815 -0
  51. data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +860 -0
  52. data/vendor/assets/javascripts/RGraph.fuel.js +965 -0
  53. data/vendor/assets/javascripts/RGraph.funnel.js +988 -0
  54. data/vendor/assets/javascripts/RGraph.gantt.js +1242 -0
  55. data/vendor/assets/javascripts/RGraph.gauge.js +1391 -0
  56. data/vendor/assets/javascripts/RGraph.hbar.js +1794 -0
  57. data/vendor/assets/javascripts/RGraph.hprogress.js +1307 -0
  58. data/vendor/assets/javascripts/RGraph.line.js +3940 -0
  59. data/vendor/assets/javascripts/RGraph.meter.js +1242 -0
  60. data/vendor/assets/javascripts/RGraph.modaldialog.js +292 -0
  61. data/vendor/assets/javascripts/RGraph.odo.js +1265 -0
  62. data/vendor/assets/javascripts/RGraph.pie.js +1979 -0
  63. data/vendor/assets/javascripts/RGraph.radar.js +1840 -0
  64. data/vendor/assets/javascripts/RGraph.rose.js +1860 -0
  65. data/vendor/assets/javascripts/RGraph.rscatter.js +1332 -0
  66. data/vendor/assets/javascripts/RGraph.scatter.js +3029 -0
  67. data/vendor/assets/javascripts/RGraph.thermometer.js +1131 -0
  68. data/vendor/assets/javascripts/RGraph.vprogress.js +1326 -0
  69. data/vendor/assets/javascripts/RGraph.waterfall.js +1252 -0
  70. data/vendor/assets/javascripts/financial-data.js +1067 -0
  71. data/vendor/assets/stylesheets/ModalDialog.css +90 -0
  72. data/vendor/assets/stylesheets/animations.css +3347 -0
  73. data/vendor/assets/stylesheets/website.css +402 -0
  74. metadata +175 -0
@@ -0,0 +1,579 @@
1
+ // version: 2015-11-02
2
+ /**
3
+ * o--------------------------------------------------------------------------------o
4
+ * | This file is part of the RGraph package - you can learn more at: |
5
+ * | |
6
+ * | http://www.rgraph.net |
7
+ * | |
8
+ * | RGraph is dual licensed under the Open Source GPL (General Public License) |
9
+ * | v2.0 license and a commercial license which means that you're not bound by |
10
+ * | the terms of the GPL. The commercial license is just �99 (GBP) and you can |
11
+ * | read about it here: |
12
+ * | http://www.rgraph.net/license |
13
+ * o--------------------------------------------------------------------------------o
14
+ */
15
+
16
+ /**
17
+ * Having this here means that the RGraph libraries can be included in any order, instead of you having
18
+ * to include the common core library first.
19
+ */
20
+
21
+ // Define the RGraph global variable
22
+ RGraph = window.RGraph || {isRGraph: true};
23
+ RGraph.Drawing = RGraph.Drawing || {};
24
+
25
+ /**
26
+ * The constructor. This function sets up the object. It takes the ID (the HTML attribute) of the canvas as the
27
+ * first argument and the data as the second. If you need to change this, you can.
28
+ *
29
+ * @param string id The canvas tag ID
30
+ * @param number x The X position of the circle
31
+ * @param number y The Y position of the circle
32
+ * @param number r The radius of the circle
33
+ */
34
+ RGraph.Drawing.Circle = function (conf)
35
+ {
36
+ /**
37
+ * Allow for object config style
38
+ */
39
+ if ( typeof conf === 'object'
40
+ && typeof conf.x === 'number'
41
+ && typeof conf.y === 'number'
42
+ && typeof conf.radius === 'number'
43
+ && typeof conf.id === 'string') {
44
+
45
+ var id = conf.id
46
+ var canvas = document.getElementById(id);
47
+ var x = conf.x;
48
+ var y = conf.y;
49
+ var radius = conf.radius;
50
+
51
+ var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor)
52
+
53
+ } else {
54
+
55
+ var id = conf;
56
+ var canvas = document.getElementById(id);
57
+ var x = arguments[1];
58
+ var y = arguments[2];
59
+ var radius = arguments[3];
60
+ }
61
+
62
+
63
+
64
+
65
+ this.id = id;
66
+ this.canvas = document.getElementById(this.id);
67
+ this.context = this.canvas.getContext('2d');
68
+ this.canvas.__object__ = this;
69
+ this.original_colors = [];
70
+ this.firstDraw = true; // After the first draw this will be false
71
+
72
+
73
+ /**
74
+ * Store the properties
75
+ */
76
+ this.centerx = x;
77
+ this.centery = y;
78
+ this.radius = radius;
79
+
80
+ /**
81
+ * This defines the type of this shape
82
+ */
83
+ this.type = 'drawing.circle';
84
+
85
+
86
+ /**
87
+ * This facilitates easy object identification, and should always be true
88
+ */
89
+ this.isRGraph = true;
90
+
91
+
92
+ /**
93
+ * This adds a uid to the object that you can use for identification purposes
94
+ */
95
+ this.uid = RGraph.CreateUID();
96
+
97
+
98
+ /**
99
+ * This adds a UID to the canvas for identification purposes
100
+ */
101
+ this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
102
+
103
+
104
+
105
+
106
+ /**
107
+ * Some example background properties
108
+ */
109
+ this.properties =
110
+ {
111
+ 'chart.strokestyle': 'rgba(0,0,0,0)',
112
+ 'chart.fillstyle': 'red',
113
+ 'chart.events.click': null,
114
+ 'chart.events.mousemove': null,
115
+ 'chart.shadow': false,
116
+ 'chart.shadow.color': 'gray',
117
+ 'chart.shadow.offsetx': 3,
118
+ 'chart.shadow.offsety': 3,
119
+ 'chart.shadow.blur': 5,
120
+ 'chart.highlight.stroke': 'black',
121
+ 'chart.highlight.fill': 'rgba(255,255,255,0.7)',
122
+ 'chart.tooltips': null,
123
+ 'chart.tooltips.highlight': true,
124
+ 'chart.tooltips.event': 'onclick',
125
+ 'chart.linewidth': 2
126
+ }
127
+
128
+ /**
129
+ * A simple check that the browser has canvas support
130
+ */
131
+ if (!this.canvas) {
132
+ alert('[DRAWING.CIRCLE] No canvas support');
133
+ return;
134
+ }
135
+
136
+ /**
137
+ * This can be used to store the coordinates of shapes on the graph
138
+ */
139
+ this.coords = [[this.centerx, this.centery, this.radius]];
140
+
141
+
142
+ /**
143
+ * Create the dollar object so that functions can be added to them
144
+ */
145
+ this.$0 = {};
146
+
147
+
148
+
149
+ /**
150
+ * Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
151
+ * done already
152
+ */
153
+ if (!this.canvas.__rgraph_aa_translated__) {
154
+ this.context.translate(0.5,0.5);
155
+
156
+ this.canvas.__rgraph_aa_translated__ = true;
157
+ }
158
+
159
+
160
+
161
+
162
+ // Short variable names
163
+ var RG = RGraph,
164
+ ca = this.canvas,
165
+ co = ca.getContext('2d'),
166
+ prop = this.properties,
167
+ pa = RG.Path,
168
+ pa2 = RG.path2,
169
+ win = window,
170
+ doc = document,
171
+ ma = Math
172
+
173
+
174
+
175
+ /**
176
+ * "Decorate" the object with the generic effects if the effects library has been included
177
+ */
178
+ if (RG.Effects && typeof RG.Effects.decorate === 'function') {
179
+ RG.Effects.decorate(this);
180
+ }
181
+
182
+
183
+
184
+
185
+ /**
186
+ * A setter method for setting graph properties. It can be used like this: obj.Set('chart.strokestyle', '#666');
187
+ *
188
+ * @param name string The name of the property to set OR it can be a map
189
+ * of name/value settings like what you set in the constructor
190
+ */
191
+ this.set =
192
+ this.Set = function (name)
193
+ {
194
+ var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
195
+
196
+ /**
197
+ * the number of arguments is only one and it's an
198
+ * object - parse it for configuration data and return.
199
+ */
200
+ if (arguments.length === 1 && typeof name === 'object') {
201
+ RG.parseObjectStyleConfig(this, name);
202
+ return this;
203
+ }
204
+
205
+
206
+
207
+
208
+
209
+ /**
210
+ * This should be done first - prepend the property name with "chart." if necessary
211
+ */
212
+ if (name.substr(0,6) != 'chart.') {
213
+ name = 'chart.' + name;
214
+ }
215
+
216
+
217
+
218
+
219
+ // Convert uppercase letters to dot+lower case letter
220
+ name = name.replace(/([A-Z])/g, function (str)
221
+ {
222
+ return '.' + String(RegExp.$1).toLowerCase();
223
+ });
224
+
225
+
226
+
227
+
228
+
229
+
230
+ prop[name] = value;
231
+
232
+ return this;
233
+ };
234
+
235
+
236
+
237
+
238
+ /**
239
+ * A getter method for retrieving graph properties. It can be used like this: obj.Get('chart.strokestyle');
240
+ *
241
+ * @param name string The name of the property to get
242
+ */
243
+ this.get =
244
+ this.Get = function (name)
245
+ {
246
+ /**
247
+ * This should be done first - prepend the property name with "chart." if necessary
248
+ */
249
+ if (name.substr(0,6) != 'chart.') {
250
+ name = 'chart.' + name;
251
+ }
252
+
253
+ // Convert uppercase letters to dot+lower case letter
254
+ name = name.replace(/([A-Z])/g, function (str)
255
+ {
256
+ return '.' + String(RegExp.$1).toLowerCase()
257
+ });
258
+
259
+ return prop[name.toLowerCase()];
260
+ };
261
+
262
+
263
+
264
+
265
+ /**
266
+ * Draws the circle
267
+ */
268
+ this.draw =
269
+ this.Draw = function ()
270
+ {
271
+ /**
272
+ * Fire the onbeforedraw event
273
+ */
274
+ RG.FireCustomEvent(this, 'onbeforedraw');
275
+
276
+
277
+ /**
278
+ * Parse the colors. This allows for simple gradient syntax
279
+ */
280
+ if (!this.colorsParsed) {
281
+
282
+ this.parseColors();
283
+
284
+ // Don't want to do this again
285
+ this.colorsParsed = true;
286
+ }
287
+
288
+ pa(co, ['b', 'lw',prop['chart.linewidth']]);
289
+
290
+ if (prop['chart.shadow']) {
291
+ RG.SetShadow(this, prop['chart.shadow.color'], prop['chart.shadow.offsetx'], prop['chart.shadow.offsety'], prop['chart.shadow.blur']);
292
+ }
293
+
294
+ pa(co, ['a',this.coords[0][0], this.coords[0][1], this.radius, 0, RGraph.TWOPI, false,'f',prop['chart.fillstyle'],'s', prop['chart.strokestyle']]);
295
+
296
+ // Must turn the shadow off before the fill is done
297
+ RG.NoShadow(this);
298
+
299
+
300
+ /**
301
+ * This installs the event listeners
302
+ */
303
+ RG.InstallEventListeners(this);
304
+
305
+
306
+ /**
307
+ * Fire the onfirstdraw event
308
+ */
309
+ if (this.firstDraw) {
310
+ RG.fireCustomEvent(this, 'onfirstdraw');
311
+ this.firstDraw = false;
312
+ this.firstDrawFunc();
313
+ }
314
+
315
+
316
+
317
+ /**
318
+ * Fire the ondraw event
319
+ */
320
+ RG.FireCustomEvent(this, 'ondraw');
321
+
322
+ return this;
323
+ };
324
+
325
+
326
+
327
+ /**
328
+ * Used in chaining. Runs a function there and then - not waiting for
329
+ * the events to fire (eg the onbeforedraw event)
330
+ *
331
+ * @param function func The function to execute
332
+ */
333
+ this.exec = function (func)
334
+ {
335
+ func(this);
336
+
337
+ return this;
338
+ };
339
+
340
+
341
+
342
+
343
+ /**
344
+ * The getObjectByXY() worker method
345
+ */
346
+ this.getObjectByXY = function (e)
347
+ {
348
+ if (this.getShape(e)) {
349
+ return this;
350
+ }
351
+ };
352
+
353
+
354
+
355
+
356
+ /**
357
+ * Not used by the class during creating the shape, but is used by event handlers
358
+ * to get the coordinates (if any) of the selected bar
359
+ *
360
+ * @param object e The event object
361
+ * @param object OPTIONAL You can pass in the bar object instead of the
362
+ * function using "this"
363
+ */
364
+ this.getShape = function (e)
365
+ {
366
+ var mouseXY = RGraph.getMouseXY(e);
367
+ var mouseX = mouseXY[0];
368
+ var mouseY = mouseXY[1];
369
+
370
+ if (RG.getHypLength(this.centerx, this.centery, mouseXY[0], mouseXY[1]) <= this.radius) {
371
+
372
+ return {
373
+ 0: this, 1: this.centerx, 2: this.centery, 3: this.radius, 4: null, 5: 0,
374
+ 'object': this, 'x': this.centerx, 'y': this.centery, 'radius': this.radius, 'index': 0, 'tooltip': prop['chart.tooltips'] ? prop['chart.tooltips'][0] : null
375
+ };
376
+ }
377
+
378
+ return null;
379
+ };
380
+
381
+
382
+
383
+
384
+ /**
385
+ * This function positions a tooltip when it is displayed
386
+ *
387
+ * @param obj object The chart object
388
+ * @param int x The X coordinate specified for the tooltip
389
+ * @param int y The Y coordinate specified for the tooltip
390
+ * @param objec tooltip The tooltips DIV element
391
+ */
392
+ this.positionTooltip = function (obj, x, y, tooltip, idx)
393
+ {
394
+ var canvasXY = RG.getCanvasXY(obj.canvas);
395
+ var width = tooltip.offsetWidth;
396
+ var height = tooltip.offsetHeight;
397
+ var radius = this.radius;
398
+
399
+ // Set the top position
400
+ tooltip.style.left = 0;
401
+ tooltip.style.top = canvasXY[1] + obj.centery - height - 7 + 'px';
402
+
403
+ // By default any overflow is hidden
404
+ tooltip.style.overflow = '';
405
+
406
+ // The arrow
407
+ var img = new Image();
408
+ img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAFCAYAAACjKgd3AAAARUlEQVQYV2NkQAN79+797+RkhC4M5+/bd47B2dmZEVkBCgcmgcsgbAaA9GA1BCSBbhAuA/AagmwQPgMIGgIzCD0M0AMMAEFVIAa6UQgcAAAAAElFTkSuQmCC';
409
+ img.style.position = 'absolute';
410
+ img.id = '__rgraph_tooltip_pointer__';
411
+ img.style.top = (tooltip.offsetHeight - 2) + 'px';
412
+ tooltip.appendChild(img);
413
+
414
+ // Reposition the tooltip if at the edges:
415
+
416
+ // LEFT edge
417
+ if ((canvasXY[0] + obj.centerx - (width / 2)) < 10) {
418
+ tooltip.style.left = (canvasXY[0] + this.centerx - (width * 0.1)) + 'px';
419
+ img.style.left = ((width * 0.1) - 8.5) + 'px';
420
+
421
+ // RIGHT edge
422
+ } else if ((canvasXY[0] + obj.centerx + (width / 2)) > doc.body.offsetWidth) {
423
+ tooltip.style.left = canvasXY[0] + this.centerx - (width * 0.9) + 'px';
424
+ img.style.left = ((width * 0.9) - 8.5) + 'px';
425
+
426
+ // Default positioning - CENTERED
427
+ } else {
428
+ tooltip.style.left = (canvasXY[0] + this.centerx - (width * 0.5)) + 'px';
429
+ img.style.left = ((width * 0.5) - 8.5) + 'px';
430
+ }
431
+ };
432
+
433
+
434
+
435
+
436
+ /**
437
+ * Each object type has its own Highlight() function which highlights the appropriate shape
438
+ *
439
+ * @param object shape The shape to highlight
440
+ */
441
+ this.highlight =
442
+ this.Highlight = function (shape)
443
+ {
444
+ if (prop['chart.tooltips.highlight']) {
445
+ pa(co, ['b','a',this.centerx, this.centery, this.radius + 0.5, 0, RGraph.TWOPI, false,'f',prop['chart.highlight.fill'],'s',prop['chart.highlight.stroke']]);
446
+ }
447
+ };
448
+
449
+
450
+
451
+
452
+ /**
453
+ * This allows for easy specification of gradients
454
+ */
455
+ this.parseColors = function ()
456
+ {
457
+
458
+ // Save the original colors so that they can be restored when the canvas is reset
459
+ if (this.original_colors.length === 0) {
460
+ this.original_colors['chart.fillstyle'] = RG.array_clone(prop['chart.fillstyle']);
461
+ this.original_colors['chart.strokestyle'] = RG.array_clone(prop['chart.strokestyle']);
462
+ this.original_colors['chart.highlight.stroke'] = RG.array_clone(prop['chart.highlight.stroke']);
463
+ this.original_colors['chart.highlight.fill'] = RG.array_clone(prop['chart.highlight.fill']);
464
+ }
465
+
466
+
467
+
468
+
469
+ /**
470
+ * Parse various properties for colors
471
+ */
472
+ prop['chart.fillstyle'] = this.parseSingleColorForGradient(prop['chart.fillstyle']);
473
+ prop['chart.strokestyle'] = this.parseSingleColorForGradient(prop['chart.strokestyle']);
474
+ prop['chart.highlight.stroke'] = this.parseSingleColorForGradient(prop['chart.highlight.stroke']);
475
+ prop['chart.highlight.fill'] = this.parseSingleColorForGradient(prop['chart.highlight.fill']);
476
+ };
477
+
478
+
479
+
480
+
481
+ /**
482
+ * Use this function to reset the object to the post-constructor state. Eg reset colors if
483
+ * need be etc
484
+ */
485
+ this.reset = function ()
486
+ {
487
+ };
488
+
489
+
490
+
491
+
492
+ /**
493
+ * This parses a single color value
494
+ */
495
+ this.parseSingleColorForGradient = function (color)
496
+ {
497
+ if (!color) {
498
+ return color;
499
+ }
500
+
501
+ if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
502
+
503
+ var parts = RegExp.$1.split(':');
504
+
505
+ // Create the gradient
506
+ var grad = co.createRadialGradient(this.centerx, this.centery, 0, this.centerx, this.centery, this.radius);
507
+
508
+ var diff = 1 / (parts.length - 1);
509
+
510
+ //grad.addColorStop(0, RG.trim(parts[0]));
511
+
512
+ for (var j=0; j<parts.length; j+=1) {
513
+ grad.addColorStop(j * diff, RG.trim(parts[j]));
514
+ }
515
+ }
516
+
517
+ return grad ? grad : color;
518
+ };
519
+
520
+
521
+
522
+
523
+ /**
524
+ * Using a function to add events makes it easier to facilitate method chaining
525
+ *
526
+ * @param string type The type of even to add
527
+ * @param function func
528
+ */
529
+ this.on = function (type, func)
530
+ {
531
+ if (type.substr(0,2) !== 'on') {
532
+ type = 'on' + type;
533
+ }
534
+
535
+ this[type] = func;
536
+
537
+ return this;
538
+ };
539
+
540
+
541
+
542
+
543
+ /**
544
+ * This function runs once only
545
+ * (put at the end of the file (before any effects))
546
+ */
547
+ this.firstDrawFunc = function ()
548
+ {
549
+ };
550
+
551
+
552
+
553
+
554
+ RG.att(ca);
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+ /**
565
+ * Objects are now always registered so that the chart is redrawn if need be.
566
+ */
567
+ RG.Register(this);
568
+
569
+
570
+
571
+
572
+ /**
573
+ * This is the 'end' of the constructor so if the first argument
574
+ * contains configuration data - handle that.
575
+ */
576
+ if (parseConfObjectForOptions) {
577
+ RG.parseObjectStyleConfig(this, conf.options);
578
+ }
579
+ };