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,1194 @@
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
+ * Initialise the various objects
18
+ */
19
+ RGraph = window.RGraph || {isRGraph: true};
20
+
21
+ // Module pattern
22
+ (function (win, doc, undefined)
23
+ {
24
+ var RG = RGraph,
25
+ ua = navigator.userAgent,
26
+ ma = Math;
27
+
28
+
29
+
30
+
31
+ /**
32
+ * This is the window click event listener. It redraws all canvas tags on the page.
33
+ */
34
+ RGraph.installWindowMousedownListener =
35
+ RGraph.InstallWindowMousedownListener = function (obj)
36
+ {
37
+ if (!RGraph.window_mousedown_event_listener) {
38
+
39
+ RGraph.window_mousedown_event_listener = function (e)
40
+ {
41
+ /**
42
+ * For firefox add the window.event object
43
+ */
44
+ if (navigator.userAgent.indexOf('Firefox') >= 0) win.event = e;
45
+
46
+ e = RGraph.FixEventObject(e);
47
+
48
+
49
+ if (RGraph.HideTooltip && RGraph.Registry.Get('chart.tooltip')) {
50
+ RGraph.clear(RGraph.Registry.Get('chart.tooltip').__canvas__);
51
+ RGraph.redraw();
52
+ RGraph.hideTooltip();
53
+ }
54
+ };
55
+ win.addEventListener('mousedown', RGraph.window_mousedown_event_listener, false);
56
+ }
57
+ };
58
+
59
+
60
+
61
+
62
+ /**
63
+ * This is the window click event listener. It redraws all canvas tags on the page.
64
+ */
65
+ RGraph.installWindowMouseupListener =
66
+ RGraph.InstallWindowMouseupListener = function (obj)
67
+ {
68
+ if (!RGraph.window_mouseup_event_listener) {
69
+ RGraph.window_mouseup_event_listener = function (e)
70
+ {
71
+ /**
72
+ * For firefox add the window.event object
73
+ */
74
+ if (navigator.userAgent.indexOf('Firefox') >= 0) win.event = e;
75
+
76
+ e = RGraph.FixEventObject(e);
77
+
78
+
79
+ /**
80
+ * Stop any annotating that may be going on
81
+ */
82
+ if (RGraph.annotating_window_onmouseup) {
83
+ RGraph.annotating_window_onmouseup(e);
84
+ return;
85
+ }
86
+
87
+ /**
88
+ * End adjusting
89
+ */
90
+ if (RGraph.Registry.Get('chart.adjusting') || RGraph.Registry.Get('chart.adjusting.gantt')) {
91
+
92
+ var obj = RGraph.Registry.Get('chart.adjusting');
93
+
94
+ // If it's a line chart update the data_arr variable
95
+ if (obj && obj.type === 'line') {
96
+ obj.data_arr = RGraph.arrayLinearize(obj.data);
97
+ }
98
+
99
+ RGraph.FireCustomEvent(RGraph.Registry.Get('chart.adjusting'), 'onadjustend');
100
+ }
101
+
102
+ RGraph.Registry.Set('chart.adjusting', null);
103
+ RGraph.Registry.Set('chart.adjusting.shape', null);
104
+ RGraph.Registry.Set('chart.adjusting.gantt', null);
105
+
106
+
107
+ // ==============================================
108
+ // Finally, redraw the chart
109
+ // ==============================================
110
+
111
+ var tags = document.getElementsByTagName('canvas');
112
+ for (var i=0; i<tags.length; ++i) {
113
+ if (tags[i].__object__ && tags[i].__object__.isRGraph) {
114
+ if (!tags[i].__object__.Get('chart.annotatable')) {
115
+ if (!tags[i].__rgraph_trace_cover__ && !noredraw) {
116
+ RGraph.Clear(tags[i]);
117
+ } else {
118
+ var noredraw = true;
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ if (!noredraw) {
125
+ RGraph.Redraw();
126
+ }
127
+ };
128
+ win.addEventListener('mouseup', RGraph.window_mouseup_event_listener, false);
129
+ }
130
+ };
131
+
132
+
133
+
134
+
135
+ /**
136
+ * This is the canvas mouseup event listener. It installs the mouseup event for the
137
+ * canvas. The mouseup event then checks the relevant object.
138
+ *
139
+ * @param object obj The chart object
140
+ *
141
+ * RGraph.window_mouseup_event_listener
142
+ */
143
+ RGraph.installCanvasMouseupListener =
144
+ RGraph.InstallCanvasMouseupListener = function (obj)
145
+ {
146
+ if (!obj.canvas.rgraph_mouseup_event_listener) {
147
+ obj.canvas.rgraph_mouseup_event_listener = function (e)
148
+ {
149
+ /**
150
+ * For firefox add the window.event object
151
+ */
152
+ if (navigator.userAgent.indexOf('Firefox') >= 0) window.event = e;
153
+
154
+ e = RGraph.fixEventObject(e);
155
+
156
+
157
+ // *************************************************************************
158
+ // Tooltips
159
+ // *************************************************************************
160
+
161
+
162
+ // This causes things at the edge of the chart area - eg line chart hotspots - not to fire because the
163
+ // cursor is out of the chart area
164
+ var objects = RGraph.ObjectRegistry.getObjectsByXY(e);
165
+ //var objects = RGraph.ObjectRegistry.getObjectsByCanvasID(e.target.id);
166
+
167
+ if (objects) {
168
+ for (var i=0,len=objects.length; i<len; i+=1) {
169
+
170
+ var obj = objects[i];
171
+ var id = objects[i].id;
172
+
173
+
174
+ // =========================================================================
175
+ // The drawing API text object supports chart.link
176
+ // ========================================================================
177
+ var link = obj.Get('link');
178
+
179
+ if (obj.type == 'drawing.text' && typeof link === 'string') {
180
+
181
+ var link_target = obj.Get('link.target');
182
+ var link_options = obj.Get('link.options');
183
+
184
+ window.open(link, link_target ? link_target : null, link_options);
185
+ }
186
+
187
+
188
+ // ========================================================================
189
+ // Tooltips
190
+ // ========================================================================
191
+
192
+
193
+ if (!RG.isNull(obj) && RG.tooltip) {
194
+
195
+ var shape = obj.getShape(e);
196
+
197
+ if (shape && shape['tooltip']) {
198
+
199
+ var text = shape['tooltip'];
200
+
201
+ if (text) {
202
+
203
+ var type = shape['object'].type;
204
+
205
+ if ( type == 'line'
206
+ || type == 'rscatter'
207
+ || (type == 'scatter' && !obj.Get('chart.boxplot'))
208
+ || type == 'radar') {
209
+
210
+ var canvasXY = RGraph.getCanvasXY(obj.canvas);
211
+ var x = canvasXY[0] + shape['x'];
212
+ var y = canvasXY[1] + shape['y'];
213
+
214
+ } else {
215
+ var x = e.pageX;
216
+ var y = e.pageY;
217
+ }
218
+
219
+ RGraph.Clear(obj.canvas);
220
+ RGraph.Redraw();
221
+ obj.Highlight(shape);
222
+ RGraph.Registry.Set('chart.tooltip.shape', shape);
223
+ RGraph.Tooltip(obj, text, x, y, shape['index'], e);
224
+
225
+ // Add the shape that triggered the tooltip
226
+ if (RGraph.Registry.Get('chart.tooltip')) {
227
+
228
+ RGraph.Registry.Get('chart.tooltip').__shape__ = shape;
229
+
230
+ RGraph.EvaluateCursor(e);
231
+ }
232
+
233
+ e.cancelBubble = true;
234
+ e.stopPropagation();
235
+ return false;
236
+ }
237
+ }
238
+ }
239
+
240
+
241
+
242
+
243
+
244
+ // =========================================================================
245
+ // Adjusting
246
+ // ========================================================================
247
+
248
+
249
+
250
+ if (RGraph.Registry.Get('chart.adjusting') || RGraph.Registry.Get('chart.adjusting.gantt')) {
251
+
252
+ //var obj = RGraph.Registry.Get('chart.adjusting');
253
+
254
+ // If it's a line chart update the data_arr variable
255
+ if (obj && obj.type === 'line') {
256
+ obj.data_arr = RGraph.arrayLinearize(obj.data);
257
+ }
258
+
259
+ RGraph.FireCustomEvent(RGraph.Registry.Get('chart.adjusting'), 'onadjustend');
260
+ }
261
+
262
+ RGraph.Registry.Set('chart.adjusting', null);
263
+ RGraph.Registry.Set('chart.adjusting.shape', null);
264
+ RGraph.Registry.Set('chart.adjusting.gantt', null);
265
+
266
+ /**
267
+ * If the mouse pointer is over a "front" chart this prevents charts behind it
268
+ * from firing their events.
269
+ */
270
+ if (shape || (obj.overChartArea && obj.overChartArea(e)) ) {
271
+ break;
272
+ }
273
+ }
274
+ }
275
+ };
276
+ obj.canvas.addEventListener('mouseup', obj.canvas.rgraph_mouseup_event_listener, false);
277
+ }
278
+ };
279
+
280
+
281
+
282
+
283
+ /**
284
+ * This is the canvas mousemove event listener.
285
+ *
286
+ * @param object obj The chart object
287
+ */
288
+ RGraph.installCanvasMousemoveListener =
289
+ RGraph.InstallCanvasMousemoveListener = function (obj)
290
+ {
291
+ if (!obj.canvas.rgraph_mousemove_event_listener) {
292
+ obj.canvas.rgraph_mousemove_event_listener = function (e)
293
+ {
294
+ /**
295
+ * For firefox add the window.event object
296
+ */
297
+ if (navigator.userAgent.indexOf('Firefox') >= 0) window.event = e;
298
+ e = RGraph.FixEventObject(e);
299
+
300
+
301
+
302
+
303
+ /**
304
+ * Go through all the objects and check them to see if anything needs doing
305
+ */
306
+ var objects = RGraph.ObjectRegistry.getObjectsByXY(e);
307
+ //var objects = RGraph.ObjectRegistry.getObjectsByCanvasID(e.target.id);
308
+
309
+ if (objects && objects.length > 0) {
310
+ for (var i=0,len=objects.length; i<len; i+=1) {
311
+
312
+ var obj = objects[i];
313
+ var id = obj.id;
314
+
315
+ if (!obj.getShape) {
316
+ continue;
317
+ }
318
+
319
+
320
+ var shape = obj.getShape(e);
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+ //
329
+ // If the mouse is over a key element add the details
330
+ // of it to the Registry
331
+ //
332
+ if (obj.coords && obj.coords.key && obj.coords.key.length) {
333
+
334
+ var mouseXY = RG.getMouseXY(e);
335
+
336
+ for (var i=0,overkey=false; i<obj.coords.key.length; ++i) {
337
+
338
+ if (
339
+ mouseXY[0] >= obj.coords.key[i][0]
340
+ && mouseXY[0] <= (obj.coords.key[i][0] + obj.coords.key[i][2])
341
+ && mouseXY[1] >= obj.coords.key[i][1]
342
+ && mouseXY[1] <= (obj.coords.key[i][1] + obj.coords.key[i][3])
343
+ ) {
344
+
345
+ RG.Registry.set('key-element', obj.coords.key[i]);
346
+ overkey = true;
347
+ }
348
+
349
+ if (!overkey) {
350
+ RG.Registry.set('key-element', null);
351
+ }
352
+ }
353
+ }
354
+
355
+
356
+
357
+
358
+ // ================================================================================================ //
359
+ // This facilitates the chart.events.mousemove option
360
+ // ================================================================================================ //
361
+
362
+ var func = obj.Get('chart.events.mousemove');
363
+
364
+ if (!func && typeof obj.onmousemove == 'function') {
365
+ var func = obj.onmousemove;
366
+ }
367
+
368
+ /**
369
+ *
370
+ */
371
+ if (shape) {
372
+ var index = shape['object'].type == 'scatter' ? shape['index_adjusted'] : shape['index'];
373
+ if (typeof(obj['$' + index]) == 'object' && typeof(obj['$' + index].onmousemove) == 'function') {
374
+ var func2 = obj['$' + index].onmousemove;
375
+ }
376
+ }
377
+
378
+ /**
379
+ * This bit saves the current pointer style if there isn't one already saved
380
+ */
381
+ if (shape && (typeof(func) == 'function' || typeof(func2) == 'function' || typeof obj.Get('link') === 'string')) {
382
+
383
+ if (obj.Get('chart.events.mousemove.revertto') == null) {
384
+ obj.Set('chart.events.mousemove.revertto', e.target.style.cursor);
385
+ }
386
+
387
+ if (typeof(func) == 'function') func(e, shape);
388
+ if (typeof(func2) == 'function') func2(e, shape);
389
+
390
+
391
+ //return;
392
+
393
+ } else if (typeof(obj.Get('chart.events.mousemove.revertto')) == 'string') {
394
+
395
+ RGraph.cursor.push('default');
396
+ obj.Set('chart.events.mousemove.revertto', null);
397
+ }
398
+
399
+
400
+
401
+ // ================================================================================================ //
402
+ // Tooltips
403
+ // ================================================================================================ //
404
+
405
+
406
+ if ( shape
407
+ && (obj.Get('chart.tooltips') && obj.Get('chart.tooltips')[shape['index']] || shape['tooltip'])
408
+ && (obj.Get('chart.tooltips.event') == 'onmousemove' || obj.Get('chart.tooltips.event') == 'mousemove')
409
+ && (RGraph.is_null(RGraph.Registry.Get('chart.tooltip')) || RGraph.Registry.Get('chart.tooltip').__index__ != shape['index'] || (typeof(shape['dataset']) == 'number' && shape['dataset'] != RGraph.Registry.Get('chart.tooltip').__shape__['dataset']) || obj.uid != RGraph.Registry.Get('chart.tooltip').__object__.uid)
410
+ ) {
411
+
412
+ RGraph.Clear(obj.canvas);
413
+ RGraph.Redraw();
414
+ obj.canvas.rgraph_mouseup_event_listener(e);
415
+
416
+ return;
417
+ }
418
+
419
+
420
+ // ================================================================================================ //
421
+ // Adjusting
422
+ // ================================================================================================ //
423
+
424
+
425
+ if (obj && obj.Get('chart.adjustable')) {
426
+ obj.Adjusting_mousemove(e);
427
+ }
428
+
429
+
430
+ /**
431
+ * This facilitates breaking out of the loop when a shape has been found -
432
+ * ie the cursor is over a shape an upper chart
433
+ */
434
+ if (shape || (obj.overChartArea && obj.overChartArea(e) )) {
435
+ break;
436
+ }
437
+ }
438
+ }
439
+
440
+ // ================================================================================================ //
441
+ // Crosshairs
442
+ // ================================================================================================ //
443
+
444
+
445
+ if (e.target && e.target.__object__ && e.target.__object__.Get('chart.crosshairs')) {
446
+ RGraph.DrawCrosshairs(e, e.target.__object__);
447
+ }
448
+
449
+
450
+ // ================================================================================================ //
451
+ // Interactive key No LONGER REQUIRED
452
+ // ================================================================================================ //
453
+
454
+
455
+ //if (typeof InteractiveKey_line_mousemove == 'function') InteractiveKey_line_mousemove(e);
456
+ //if (typeof InteractiveKey_pie_mousemove == 'function') InteractiveKey_pie_mousemove(e);
457
+
458
+
459
+ // ================================================================================================ //
460
+ // Annotating
461
+ // ================================================================================================ //
462
+
463
+
464
+ if (e.target.__object__ && e.target.__object__.Get('chart.annotatable') && RGraph.annotating_canvas_onmousemove) {
465
+ RGraph.annotating_canvas_onmousemove(e);
466
+ }
467
+
468
+
469
+
470
+ /**
471
+ * Determine the pointer
472
+ */
473
+ RGraph.EvaluateCursor(e);
474
+ };
475
+ obj.canvas.addEventListener('mousemove', obj.canvas.rgraph_mousemove_event_listener, false);
476
+ }
477
+ };
478
+
479
+
480
+
481
+
482
+ /**
483
+ * This is the canvas mousedown event listener.
484
+ *
485
+ * @param object obj The chart object
486
+ */
487
+ RGraph.installCanvasMousedownListener =
488
+ RGraph.InstallCanvasMousedownListener = function (obj)
489
+ {
490
+ if (!obj.canvas.rgraph_mousedown_event_listener) {
491
+ obj.canvas.rgraph_mousedown_event_listener = function (e)
492
+ {
493
+ /**
494
+ * For firefox add the window.event object
495
+ */
496
+ if (navigator.userAgent.indexOf('Firefox') >= 0) window.event = e;
497
+
498
+ e = RG.fixEventObject(e);
499
+
500
+
501
+ /**
502
+ * Annotating
503
+ */
504
+ if (e.target.__object__ && e.target.__object__.Get('chart.annotatable') && RGraph.annotating_canvas_onmousedown) {
505
+ RGraph.annotating_canvas_onmousedown(e);
506
+ return;
507
+ }
508
+
509
+ var obj = RG.ObjectRegistry.getObjectByXY(e);
510
+
511
+ if (obj) {
512
+
513
+ var id = obj.id;
514
+
515
+
516
+
517
+ /*************************************************************
518
+ * Handle adjusting for all object types
519
+ *************************************************************/
520
+ if (obj && obj.isRGraph && obj.Get('chart.adjustable')) {
521
+
522
+ /**
523
+ * Check the cursor is in the correct area
524
+ */
525
+ var obj = RGraph.ObjectRegistry.getObjectByXY(e);
526
+
527
+ if (obj && obj.isRGraph) {
528
+
529
+ // If applicable, get the appropriate shape and store it in the registry
530
+ switch (obj.type) {
531
+ case 'bar': var shape = obj.getShapeByX(e); break;
532
+ case 'gantt':
533
+ var shape = obj.getShape(e);
534
+ if (shape) {
535
+ var mouseXY = RG.getMouseXY(e);
536
+ RG.Registry.Set('chart.adjusting.gantt', {
537
+ 'index': shape['index'],
538
+ 'object': obj,
539
+ 'mousex': mouseXY[0],
540
+ 'mousey': mouseXY[1],
541
+ 'event_start': obj.data[shape['index']][0],
542
+ 'event_duration': obj.data[shape['index']][1],
543
+ 'mode': (mouseXY[0] > (shape['x'] + shape['width'] - 5) ? 'resize' : 'move'),
544
+ 'shape': shape
545
+ });
546
+ }
547
+ break;
548
+ case 'line': var shape = obj.getShape(e); break;
549
+ default: var shape = null;
550
+ }
551
+
552
+ RG.Registry.Set('chart.adjusting.shape', shape);
553
+
554
+
555
+ // Fire the onadjustbegin event
556
+ RGraph.fireCustomEvent(obj, 'onadjustbegin');
557
+
558
+ RG.Registry.Set('chart.adjusting', obj);
559
+
560
+
561
+ // Liberally redraw the canvas
562
+ RGraph.Clear(obj.canvas);
563
+ RGraph.Redraw();
564
+
565
+ // Call the mousemove event listener so that the canvas
566
+ // is adjusted even though the mouse isn't moved
567
+ obj.canvas.rgraph_mousemove_event_listener(e);
568
+ }
569
+ }
570
+
571
+
572
+ RGraph.Clear(obj.canvas);
573
+ RGraph.Redraw();
574
+ }
575
+ };
576
+ obj.canvas.addEventListener('mousedown', obj.canvas.rgraph_mousedown_event_listener, false);
577
+ }
578
+ };
579
+
580
+
581
+
582
+
583
+ /**
584
+ * This is the canvas click event listener. Used by the pseudo event listener
585
+ *
586
+ * @param object obj The chart object
587
+ */
588
+ RGraph.installCanvasClickListener =
589
+ RGraph.InstallCanvasClickListener = function (obj)
590
+ {
591
+ if (!obj.canvas.rgraph_click_event_listener) {
592
+ obj.canvas.rgraph_click_event_listener = function (e)
593
+ {
594
+ /**
595
+ * For firefox add the window.event object
596
+ */
597
+ if (navigator.userAgent.indexOf('Firefox') >= 0) window.event = e;
598
+
599
+ e = RG.FixEventObject(e);
600
+
601
+ var objects = RG.ObjectRegistry.getObjectsByXY(e);
602
+
603
+ for (var i=0,len=objects.length; i<len; i+=1) {
604
+
605
+ var obj = objects[i];
606
+ var id = obj.id;
607
+ var shape = obj.getShape(e);
608
+
609
+ /**
610
+ * This bit saves the current pointer style if there isn't one already saved
611
+ */
612
+ var func = obj.Get('chart.events.click');
613
+
614
+ if (!func && typeof(obj.onclick) == 'function') {
615
+ func = obj.onclick;
616
+ }
617
+
618
+ if (shape && typeof func == 'function') {
619
+
620
+ func(e, shape);
621
+
622
+ /**
623
+ * If objects are layered on top of each other this return
624
+ * stops objects underneath from firing once the "top"
625
+ * objects user event has fired
626
+ */
627
+ return;
628
+ }
629
+
630
+
631
+
632
+ //
633
+ // Handle the key click event
634
+ //
635
+ var key = RG.Registry.get('key-element');
636
+ if (key) {
637
+ RG.fireCustomEvent(obj, 'onkeyclick');
638
+ }
639
+
640
+
641
+
642
+
643
+
644
+ /**
645
+ * The property takes priority over this.
646
+ */
647
+ if (shape) {
648
+
649
+ var index = shape['object'].type == 'scatter' ? shape['index_adjusted'] : shape['index'];
650
+
651
+ if (typeof(index) == 'number' && obj['$' + index]) {
652
+
653
+ var func = obj['$' + index].onclick;
654
+
655
+ if (typeof(func) == 'function') {
656
+
657
+ func(e, shape);
658
+
659
+ /**
660
+ * If objects are layered on top of each other this return
661
+ * stops objects underneath from firing once the "top"
662
+ * objects user event has fired
663
+ */
664
+ return;
665
+ }
666
+ }
667
+ }
668
+
669
+ /**
670
+ * This facilitates breaking out of the loop when a shape has been found -
671
+ * ie the cursor is over a shape an upper chart
672
+ */
673
+ if (shape || (obj.overChartArea && obj.overChartArea(e)) ) {
674
+ break;
675
+ }
676
+ }
677
+ };
678
+ obj.canvas.addEventListener('click', obj.canvas.rgraph_click_event_listener, false);
679
+ }
680
+ };
681
+
682
+
683
+
684
+
685
+ /**
686
+ * This function evaluates the various cursor settings and if there's one for pointer, changes it to that
687
+ */
688
+ //RGraph.evaluateCursor =
689
+ RGraph.evaluateCursor =
690
+ RGraph.EvaluateCursor = function (e)
691
+ {
692
+ var obj = null;
693
+ var mouseXY = RGraph.getMouseXY(e);
694
+ var mouseX = mouseXY[0];
695
+ var mouseY = mouseXY[1];
696
+ var canvas = e.target;
697
+
698
+ /**
699
+ * Tooltips cause the mouse pointer to change
700
+ */
701
+ var objects = RGraph.ObjectRegistry.getObjectsByCanvasID(canvas.id);
702
+
703
+ for (var i=0,len=objects.length; i<len; i+=1) {
704
+ if ((objects[i].getShape && objects[i].getShape(e)) || (objects[i].overChartArea && objects[i].overChartArea(e))) {
705
+ var obj = objects[i];
706
+ var id = obj.id;
707
+ }
708
+ }
709
+
710
+ if (!RGraph.is_null(obj)) {
711
+ if (obj.getShape && obj.getShape(e)) {
712
+
713
+ var shape = obj.getShape(e);
714
+
715
+ if (obj.Get('chart.tooltips')) {
716
+
717
+ var text = RGraph.parseTooltipText(obj.Get('chart.tooltips'), shape['index']);
718
+
719
+ if (!text && shape['object'].type == 'scatter' && shape['index_adjusted']) {
720
+ text = RGraph.parseTooltipText(obj.Get('chart.tooltips'), shape['index_adjusted']);
721
+ }
722
+
723
+ /**
724
+ * This essentially makes front charts "hide" the back charts
725
+ */
726
+ if (text) {
727
+ var pointer = true;
728
+ }
729
+ }
730
+ }
731
+
732
+ /**
733
+ * Now go through the key coords and see if it's over that.
734
+ */
735
+ if (!RGraph.is_null(obj) && obj.Get('chart.key.interactive')) {
736
+ for (var j=0; j<obj.coords.key.length; ++j) {
737
+ if (mouseX > obj.coords.key[j][0] && mouseX < (obj.coords.key[j][0] + obj.coords.key[j][2]) && mouseY > obj.coords.key[j][1] && mouseY < (obj.coords.key[j][1] + obj.coords.key[j][3])) {
738
+ var pointer = true;
739
+ }
740
+ }
741
+ }
742
+ }
743
+
744
+ /**
745
+ * It can be specified in the user mousemove event - remember it can now be specified in THREE ways
746
+ */
747
+ if (!RGraph.is_null(shape) && !RGraph.is_null(obj)) {
748
+
749
+ if (!RGraph.is_null(obj.Get('chart.events.mousemove')) && typeof(obj.Get('chart.events.mousemove')) == 'function') {
750
+ var str = (obj.Get('chart.events.mousemove')).toString();
751
+ if (str.match(/pointer/) && str.match(/cursor/) && str.match(/style/)) {
752
+ var pointer = true;
753
+ }
754
+ }
755
+
756
+ if (!RGraph.is_null(obj.onmousemove) && typeof(obj.onmousemove) == 'function') {
757
+ var str = (obj.onmousemove).toString();
758
+ if (str.match(/pointer/) && str.match(/cursor/) && str.match(/style/)) {
759
+ var pointer = true;
760
+ }
761
+ }
762
+
763
+ var index = shape['object'].type == 'scatter' ? shape['index_adjusted'] : shape['index'];
764
+ if (!RGraph.is_null(obj['$' + index]) && typeof(obj['$' + index].onmousemove) == 'function') {
765
+ var str = (obj['$' + index].onmousemove).toString();
766
+ if (str.match(/pointer/) && str.match(/cursor/) && str.match(/style/)) {
767
+ var pointer = true;
768
+ }
769
+ }
770
+ }
771
+
772
+ /**
773
+ * Is the chart resizable? Go through all the objects again
774
+ */
775
+ var objects = RGraph.ObjectRegistry.objects.byCanvasID;
776
+
777
+ for (var i=0,len=objects.length; i<len; i+=1) {
778
+ if (objects[i] && objects[i][1].Get('chart.resizable')) {
779
+ var resizable = true;
780
+ }
781
+ }
782
+
783
+ if (resizable && mouseX > (e.target.width - 32) && mouseY > (e.target.height - 16)) {
784
+ pointer = true;
785
+ }
786
+
787
+
788
+ if (pointer) {
789
+ e.target.style.cursor = 'pointer';
790
+ } else if (e.target.style.cursor == 'pointer') {
791
+ e.target.style.cursor = 'default';
792
+ } else {
793
+ e.target.style.cursor = null;
794
+ }
795
+
796
+
797
+
798
+ // =========================================================================
799
+ // Resize cursor - check mouseis in bottom left corner and if it is change it
800
+ // =========================================================================
801
+
802
+
803
+ if (resizable && mouseX >= (e.target.width - 15) && mouseY >= (e.target.height - 15)) {
804
+ e.target.style.cursor = 'move';
805
+
806
+ } else if (e.target.style.cursor === 'move') {
807
+ e.target.style.cursor = 'default';
808
+ }
809
+
810
+
811
+ // =========================================================================
812
+ // Interactive key
813
+ // =========================================================================
814
+
815
+
816
+
817
+ if (typeof mouse_over_key == 'boolean' && mouse_over_key) {
818
+ e.target.style.cursor = 'pointer';
819
+ }
820
+
821
+
822
+ // =========================================================================
823
+ // Gantt chart adjusting
824
+ // =========================================================================
825
+
826
+ //if (obj && obj.type == 'gantt' && obj.Get('chart.adjustable')) {
827
+ // if (obj.getShape && obj.getShape(e)) {
828
+ // e.target.style.cursor = 'ew-resize';
829
+ // } else {
830
+ // e.target.style.cursor = 'default';
831
+ // }
832
+ //} else if (!obj || !obj.type) {
833
+ // e.target.style.cursor = cursor;
834
+ //}
835
+
836
+
837
+ // =========================================================================
838
+ // Line chart adjusting
839
+ // =========================================================================
840
+
841
+
842
+ if (obj && obj.type == 'line' && obj.Get('chart.adjustable')) {
843
+ if (obj.getShape && obj.getShape(e)) {
844
+ e.target.style.cursor = 'ns-resize';
845
+ } else {
846
+ e.target.style.cursor = 'default';
847
+ }
848
+ }
849
+
850
+
851
+ // =========================================================================
852
+ // Annotatable
853
+ // =========================================================================
854
+
855
+
856
+ if (e.target.__object__ && e.target.__object__.Get('chart.annotatable')) {
857
+ e.target.style.cursor = 'crosshair';
858
+ }
859
+
860
+
861
+ // =========================================================================
862
+ // Drawing API link
863
+ // =========================================================================
864
+
865
+
866
+ if (obj && obj.type === 'drawing.text' && shape && typeof obj.Get('link') === 'string') {
867
+ e.target.style.cursor = 'pointer';
868
+ }
869
+ };
870
+
871
+
872
+
873
+
874
+ /**
875
+ * This function handles the tooltip text being a string, function
876
+ *
877
+ * @param mixed tooltip This could be a string or a function. If it's a function it's called and
878
+ * the return value is used as the tooltip text
879
+ * @param numbr idx The index of the tooltip.
880
+ */
881
+ RGraph.parseTooltipText = function (tooltips, idx)
882
+ {
883
+ // No tooltips
884
+ if (!tooltips) {
885
+ return null;
886
+ }
887
+
888
+ // Get the tooltip text
889
+ if (typeof tooltips == 'function') {
890
+ var text = tooltips(idx);
891
+
892
+ // A single tooltip. Only supported by the Scatter chart
893
+ } else if (typeof tooltips == 'string') {
894
+ var text = tooltips;
895
+
896
+ } else if (typeof tooltips == 'object' && typeof tooltips[idx] == 'function') {
897
+ var text = tooltips[idx](idx);
898
+
899
+ } else if (typeof tooltips[idx] == 'string' && tooltips[idx]) {
900
+ var text = tooltips[idx];
901
+
902
+ } else {
903
+ var text = '';
904
+ }
905
+
906
+ if (text == 'undefined') {
907
+ text = '';
908
+ } else if (text == 'null') {
909
+ text = '';
910
+ }
911
+
912
+ // Conditional in case the tooltip file isn't included
913
+ return RGraph.getTooltipTextFromDIV ? RGraph.getTooltipTextFromDIV(text) : text;
914
+ };
915
+
916
+
917
+
918
+
919
+ /**
920
+ * Draw crosshairs if enabled
921
+ *
922
+ * @param object obj The graph object (from which we can get the context and canvas as required)
923
+ */
924
+ RGraph.drawCrosshairs =
925
+ RGraph.DrawCrosshairs = function (e, obj)
926
+ {
927
+ var e = RGraph.FixEventObject(e);
928
+ var width = obj.canvas.width;
929
+ var height = obj.canvas.height;
930
+ var mouseXY = RGraph.getMouseXY(e);
931
+ var x = mouseXY[0];
932
+ var y = mouseXY[1];
933
+ var gutterLeft = obj.gutterLeft;
934
+ var gutterRight = obj.gutterRight;
935
+ var gutterTop = obj.gutterTop;
936
+ var gutterBottom = obj.gutterBottom;
937
+ var Mathround = Math.round;
938
+ var prop = obj.properties;
939
+ var co = obj.context;
940
+ var ca = obj.canvas;
941
+
942
+ RGraph.RedrawCanvas(ca);
943
+
944
+ if ( x >= gutterLeft
945
+ && y >= gutterTop
946
+ && x <= (width - gutterRight)
947
+ && y <= (height - gutterBottom)
948
+ ) {
949
+
950
+ var linewidth = prop['chart.crosshairs.linewidth'] ? prop['chart.crosshairs.linewidth'] : 1;
951
+ co.lineWidth = linewidth ? linewidth : 1;
952
+
953
+ co.beginPath();
954
+ co.strokeStyle = prop['chart.crosshairs.color'];
955
+
956
+
957
+
958
+
959
+
960
+ /**
961
+ * The chart.crosshairs.snap option
962
+ */
963
+ if (prop['chart.crosshairs.snap']) {
964
+
965
+ // Linear search for the closest point
966
+ var point = null;
967
+ var dist = null;
968
+ var len = null;
969
+
970
+ if (obj.type == 'line') {
971
+
972
+ for (var i=0; i<obj.coords.length; ++i) {
973
+
974
+ var length = RGraph.getHypLength(obj.coords[i][0], obj.coords[i][1], x, y);
975
+
976
+ // Check the mouse X coordinate
977
+ if (typeof dist != 'number' || length < dist) {
978
+ var point = i;
979
+ var dist = length;
980
+ }
981
+ }
982
+
983
+ x = obj.coords[point][0];
984
+ y = obj.coords[point][1];
985
+
986
+ // Get the dataset
987
+ for (var dataset=0; dataset<obj.coords2.length; ++dataset) {
988
+ for (var point=0; point<obj.coords2[dataset].length; ++point) {
989
+ if (obj.coords2[dataset][point][0] == x && obj.coords2[dataset][point][1] == y) {
990
+ ca.__crosshairs_snap_dataset__ = dataset;
991
+ ca.__crosshairs_snap_point__ = point;
992
+ }
993
+ }
994
+ }
995
+
996
+ } else {
997
+
998
+ for (var i=0; i<obj.coords.length; ++i) {
999
+ for (var j=0; j<obj.coords[i].length; ++j) {
1000
+
1001
+ // Check the mouse X coordinate
1002
+ var len = RGraph.getHypLength(obj.coords[i][j][0], obj.coords[i][j][1], x, y);
1003
+
1004
+ if (typeof(dist) != 'number' || len < dist) {
1005
+
1006
+ var dataset = i;
1007
+ var point = j;
1008
+ var dist = len;
1009
+ }
1010
+ }
1011
+
1012
+ }
1013
+ ca.__crosshairs_snap_dataset__ = dataset;
1014
+ ca.__crosshairs_snap_point__ = point;
1015
+
1016
+
1017
+ x = obj.coords[dataset][point][0];
1018
+ y = obj.coords[dataset][point][1];
1019
+ }
1020
+ }
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
1027
+ // Draw a top vertical line
1028
+ if (prop['chart.crosshairs.vline']) {
1029
+ co.moveTo(Mathround(x), Mathround(gutterTop));
1030
+ co.lineTo(Mathround(x), Mathround(height - gutterBottom));
1031
+ }
1032
+
1033
+ // Draw a horizontal line
1034
+ if (prop['chart.crosshairs.hline']) {
1035
+ co.moveTo(Mathround(gutterLeft), Mathround(y));
1036
+ co.lineTo(Mathround(width - gutterRight), Mathround(y));
1037
+ }
1038
+
1039
+ co.stroke();
1040
+
1041
+
1042
+ /**
1043
+ * Need to show the coords?
1044
+ */
1045
+ if (obj.type == 'scatter' && prop['chart.crosshairs.coords']) {
1046
+
1047
+ var xCoord = (((x - gutterLeft) / (width - gutterLeft - gutterRight)) * (prop['chart.xmax'] - prop['chart.xmin'])) + prop['chart.xmin'];
1048
+ xCoord = xCoord.toFixed(prop['chart.scale.decimals']);
1049
+ var yCoord = obj.max - (((y - prop['chart.gutter.top']) / (height - gutterTop - gutterBottom)) * obj.max);
1050
+
1051
+ if (obj.type == 'scatter' && obj.properties['chart.xaxispos'] == 'center') {
1052
+ yCoord = (yCoord - (obj.max / 2)) * 2;
1053
+ }
1054
+
1055
+ yCoord = yCoord.toFixed(prop['chart.scale.decimals']);
1056
+
1057
+ var div = RGraph.Registry.Get('chart.coordinates.coords.div');
1058
+ var mouseXY = RGraph.getMouseXY(e);
1059
+ var canvasXY = RGraph.getCanvasXY(ca);
1060
+
1061
+ if (!div) {
1062
+ var div = document.createElement('DIV');
1063
+ div.__object__ = obj;
1064
+ div.style.position = 'absolute';
1065
+ div.style.backgroundColor = 'white';
1066
+ div.style.border = '1px solid black';
1067
+ div.style.fontFamily = 'Arial, Verdana, sans-serif';
1068
+ div.style.fontSize = '10pt'
1069
+ div.style.padding = '2px';
1070
+ div.style.opacity = 1;
1071
+ div.style.WebkitBorderRadius = '3px';
1072
+ div.style.borderRadius = '3px';
1073
+ div.style.MozBorderRadius = '3px';
1074
+ document.body.appendChild(div);
1075
+
1076
+ RGraph.Registry.Set('chart.coordinates.coords.div', div);
1077
+ }
1078
+
1079
+ // Convert the X/Y pixel coords to correspond to the scale
1080
+ div.style.opacity = 1;
1081
+ div.style.display = 'inline';
1082
+
1083
+ if (!prop['chart.crosshairs.coords.fixed']) {
1084
+ div.style.left = Math.max(2, (e.pageX - div.offsetWidth - 3)) + 'px';
1085
+ div.style.top = Math.max(2, (e.pageY - div.offsetHeight - 3)) + 'px';
1086
+ } else {
1087
+ div.style.left = canvasXY[0] + gutterLeft + 3 + 'px';
1088
+ div.style.top = canvasXY[1] + gutterTop + 3 + 'px';
1089
+ }
1090
+
1091
+ div.innerHTML = '<span style="color: #666">' + prop['chart.crosshairs.coords.labels.x'] + ':</span> ' + xCoord + '<br><span style="color: #666">' + prop['chart.crosshairs.coords.labels.y'] + ':</span> ' + yCoord;
1092
+
1093
+ obj.canvas.addEventListener('mouseout', RGraph.HideCrosshairCoords, false);
1094
+
1095
+ ca.__crosshairs_labels__ = div;
1096
+ ca.__crosshairs_x__ = xCoord;
1097
+ ca.__crosshairs_y__ = yCoord;
1098
+
1099
+ } else if (prop['chart.crosshairs.coords']) {
1100
+ alert('[RGRAPH] Showing crosshair coordinates is only supported on the Scatter chart');
1101
+ }
1102
+
1103
+ /**
1104
+ * Fire the oncrosshairs custom event
1105
+ */
1106
+ RGraph.FireCustomEvent(obj, 'oncrosshairs');
1107
+
1108
+ } else {
1109
+ RGraph.HideCrosshairCoords();
1110
+ }
1111
+ };
1112
+
1113
+
1114
+
1115
+
1116
+ //
1117
+ // Adds a mousemove event listener that highlights a segment based on th
1118
+ // mousemove event. Used in the Rose and the RScatter charts
1119
+ //
1120
+ //@param int segments The number of segments to allow
1121
+ //
1122
+ RG.allowSegmentHighlight = function (opt)
1123
+ {
1124
+ var obj = opt.object;
1125
+ var count = opt.count;
1126
+ var fill = opt.fill;
1127
+ var stroke = opt.stroke;
1128
+
1129
+ if (!RGraph.segmentHighlightFunction) {
1130
+
1131
+ RGraph.segmentHighlightFunction = function (e)
1132
+ {
1133
+
1134
+ var mouseXY = RG.getMouseXY(e);
1135
+ var angle = RG.getAngleByXY(obj.centerx, obj.centery, mouseXY[0], mouseXY[1]);
1136
+
1137
+ angle += RG.HALFPI;
1138
+
1139
+ if (angle > RG.TWOPI) {
1140
+ angle -= RG.TWOPI;
1141
+ }
1142
+
1143
+ RG.redraw();
1144
+
1145
+ var start = 0;
1146
+ var end = 0;
1147
+ var a = (ma.PI * 2) / count;
1148
+
1149
+ //
1150
+ // Radius
1151
+ //
1152
+ var r = obj.radius;
1153
+
1154
+
1155
+ (function ()
1156
+ {
1157
+ for (i=0; i<count; i+=1) {
1158
+ if (angle < (a * (i + 1))) {
1159
+ start = i * a;
1160
+ end = (i + 1) * a;
1161
+
1162
+ return;
1163
+ }
1164
+ }
1165
+ })();
1166
+
1167
+ start -= RG.HALFPI;
1168
+ end -= RG.HALFPI;
1169
+
1170
+
1171
+ RG.path(obj.context, [
1172
+ 'b',
1173
+ 'm', obj.centerx, obj.centery,
1174
+ 'a',obj.centerx,
1175
+ obj.centery,
1176
+ r,
1177
+ start,
1178
+ end,
1179
+ false,
1180
+ 'c',
1181
+ 's', stroke,
1182
+ 'f', fill
1183
+ ]);
1184
+
1185
+ };
1186
+ obj.canvas.addEventListener('mousemove', RG.segmentHighlightFunction, false);
1187
+ }
1188
+ }
1189
+
1190
+
1191
+
1192
+
1193
+ // End module pattern
1194
+ })(window, document);