rgraph-rails 4.62 → 4.64

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3 -4
  3. data/lib/rgraph-rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/RGraph.bar.js +240 -3742
  5. data/vendor/assets/javascripts/RGraph.bipolar.js +165 -2005
  6. data/vendor/assets/javascripts/RGraph.common.annotate.js +35 -395
  7. data/vendor/assets/javascripts/RGraph.common.context.js +30 -595
  8. data/vendor/assets/javascripts/RGraph.common.core.js +418 -5359
  9. data/vendor/assets/javascripts/RGraph.common.csv.js +20 -276
  10. data/vendor/assets/javascripts/RGraph.common.deprecated.js +35 -450
  11. data/vendor/assets/javascripts/RGraph.common.dynamic.js +88 -1395
  12. data/vendor/assets/javascripts/RGraph.common.effects.js +90 -1545
  13. data/vendor/assets/javascripts/RGraph.common.key.js +52 -753
  14. data/vendor/assets/javascripts/RGraph.common.resizing.js +37 -563
  15. data/vendor/assets/javascripts/RGraph.common.sheets.js +29 -352
  16. data/vendor/assets/javascripts/RGraph.common.tooltips.js +32 -450
  17. data/vendor/assets/javascripts/RGraph.common.zoom.js +14 -219
  18. data/vendor/assets/javascripts/RGraph.cornergauge.js +71 -0
  19. data/vendor/assets/javascripts/RGraph.drawing.background.js +34 -570
  20. data/vendor/assets/javascripts/RGraph.drawing.circle.js +33 -544
  21. data/vendor/assets/javascripts/RGraph.drawing.image.js +51 -755
  22. data/vendor/assets/javascripts/RGraph.drawing.marker1.js +37 -645
  23. data/vendor/assets/javascripts/RGraph.drawing.marker2.js +36 -633
  24. data/vendor/assets/javascripts/RGraph.drawing.marker3.js +35 -514
  25. data/vendor/assets/javascripts/RGraph.drawing.poly.js +37 -559
  26. data/vendor/assets/javascripts/RGraph.drawing.rect.js +33 -548
  27. data/vendor/assets/javascripts/RGraph.drawing.text.js +36 -664
  28. data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +50 -812
  29. data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +51 -856
  30. data/vendor/assets/javascripts/RGraph.fuel.js +58 -964
  31. data/vendor/assets/javascripts/RGraph.funnel.js +55 -984
  32. data/vendor/assets/javascripts/RGraph.gantt.js +77 -1354
  33. data/vendor/assets/javascripts/RGraph.gauge.js +85 -1421
  34. data/vendor/assets/javascripts/RGraph.hbar.js +162 -2788
  35. data/vendor/assets/javascripts/RGraph.hprogress.js +80 -1401
  36. data/vendor/assets/javascripts/RGraph.line.js +249 -4248
  37. data/vendor/assets/javascripts/RGraph.meter.js +74 -1280
  38. data/vendor/assets/javascripts/RGraph.modaldialog.js +19 -301
  39. data/vendor/assets/javascripts/RGraph.odo.js +71 -1264
  40. data/vendor/assets/javascripts/RGraph.pie.js +137 -2288
  41. data/vendor/assets/javascripts/RGraph.radar.js +110 -1847
  42. data/vendor/assets/javascripts/RGraph.rose.js +108 -1977
  43. data/vendor/assets/javascripts/RGraph.rscatter.js +80 -1432
  44. data/vendor/assets/javascripts/RGraph.scatter.js +172 -3163
  45. data/vendor/assets/javascripts/RGraph.semicircularprogress.js +60 -1120
  46. data/vendor/assets/javascripts/RGraph.svg.bar.js +66 -1735
  47. data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +21 -246
  48. data/vendor/assets/javascripts/RGraph.svg.common.core.js +255 -3937
  49. data/vendor/assets/javascripts/RGraph.svg.common.csv.js +20 -276
  50. data/vendor/assets/javascripts/RGraph.svg.common.fx.js +68 -1303
  51. data/vendor/assets/javascripts/RGraph.svg.common.key.js +19 -205
  52. data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +29 -352
  53. data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +22 -273
  54. data/vendor/assets/javascripts/RGraph.svg.funnel.js +32 -0
  55. data/vendor/assets/javascripts/RGraph.svg.hbar.js +59 -1400
  56. data/vendor/assets/javascripts/RGraph.svg.line.js +70 -1580
  57. data/vendor/assets/javascripts/RGraph.svg.pie.js +55 -1131
  58. data/vendor/assets/javascripts/RGraph.svg.radar.js +57 -1502
  59. data/vendor/assets/javascripts/RGraph.svg.rose.js +66 -1817
  60. data/vendor/assets/javascripts/RGraph.svg.scatter.js +58 -1261
  61. data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +28 -865
  62. data/vendor/assets/javascripts/RGraph.svg.waterfall.js +45 -1252
  63. data/vendor/assets/javascripts/RGraph.thermometer.js +63 -1136
  64. data/vendor/assets/javascripts/RGraph.vprogress.js +83 -1470
  65. data/vendor/assets/javascripts/RGraph.waterfall.js +83 -1347
  66. metadata +5 -4
  67. data/vendor/assets/javascripts/financial-data.js +0 -1067
@@ -1,813 +1,51 @@
1
- // version: 2017-05-08
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 licensed under the Open Source MIT license. That means that it's |
9
- * | totally free to use! |
10
- * o--------------------------------------------------------------------------------o
11
- */
12
1
 
13
- /**
14
- * Having this here means that the RGraph libraries can be included in any order, instead of you having
15
- * to include the common core library first.
16
- */
17
-
18
- // Define the RGraph global variable
19
- RGraph = window.RGraph || {isRGraph: true};
20
- RGraph.Drawing = RGraph.Drawing || {};
21
-
22
- /**
23
- * The constructor. This function sets up the object. It takes the ID (the HTML attribute) of the canvas as the
24
- * first argument and the Y coordinate of the axes as the second
25
- *
26
- * @param string id The canvas tag ID
27
- * @param number y The Y coordinate
28
- */
29
- RGraph.Drawing.XAxis = function (conf)
30
- {
31
- /**
32
- * Allow for object config style
33
- */
34
- if ( typeof conf === 'object'
35
- && typeof conf.y === 'number'
36
- && typeof conf.id === 'string') {
37
-
38
- var id = conf.id
39
- var y = conf.y;
40
-
41
- var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor)
42
-
43
- } else {
44
-
45
- var id = conf;
46
- var y = arguments[1];
47
- }
48
-
49
-
50
-
51
-
52
- this.id = id;
53
- this.canvas = document.getElementById(this.id);
54
- this.context = this.canvas.getContext('2d');
55
- this.canvas.__object__ = this;
56
- this.y = y;
57
- this.coords = [];
58
- this.coordsText = [];
59
- this.original_colors = [];
60
- this.firstDraw = true; // After the first draw this will be false
61
-
62
-
63
- /**
64
- * This defines the type of this shape
65
- */
66
- this.type = 'drawing.xaxis';
67
-
68
-
69
- /**
70
- * This facilitates easy object identification, and should always be true
71
- */
72
- this.isRGraph = true;
73
-
74
-
75
- /**
76
- * This adds a uid to the object that you can use for identification purposes
77
- */
78
- this.uid = RGraph.CreateUID();
79
-
80
-
81
- /**
82
- * This adds a UID to the canvas for identification purposes
83
- */
84
- this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
85
-
86
-
87
-
88
-
89
- /**
90
- * Some example background properties
91
- */
92
- this.properties =
93
- {
94
- 'chart.gutter.left': 25,
95
- 'chart.gutter.right': 25,
96
- 'chart.labels': null,
97
- 'chart.labels.position': 'section',
98
- 'chart.colors': ['black'],
99
- 'chart.title.color': null, // Defaults to same as chart.colors
100
- 'chart.text.color': null, // Defaults to same as chart.colors
101
- 'chart.text.font': 'Segoe UI, Arial, Verdana, sans-serif',
102
- 'chart.text.size': 12,
103
- 'chart.text.accessible': true,
104
- 'chart.text.accessible.overflow':'visible',
105
- 'chart.text.accessible.pointerevents': true,
106
- 'chart.align': 'bottom',
107
- 'chart.numlabels': 5,
108
- 'chart.scale.visible': true,
109
- 'chart.scale.formatter': null,
110
- 'chart.scale.decimals': 0,
111
- 'chart.scale.point': '.',
112
- 'chart.scale.thousand': ',',
113
- 'chart.scale.invert': false,
114
- 'chart.scale.zerostart': true,
115
- 'chart.units.pre': '',
116
- 'chart.units.post': '',
117
- 'chart.title': '',
118
- 'chart.numticks': null,
119
- 'chart.hmargin': 0,
120
- 'chart.linewidth': 1,
121
- 'chart.noendtick.left': false,
122
- 'chart.noendtick.right': false,
123
- 'chart.noxaxis': false,
124
- 'chart.max': null,
125
- 'chart.min': 0,
126
- 'chart.tooltips': null,
127
- 'chart.tooltips.effect': 'fade',
128
- 'chart.tooltips.css.class':'RGraph_tooltip',
129
- 'chart.tooltips.event': 'onclick',
130
- 'chart.events.click': null,
131
- 'chart.events.mousemove': null,
132
- 'chart.xaxispos': 'bottom',
133
- 'chart.yaxispos': 'left',
134
- 'chart.clearto': 'rgba(0,0,0,0)'
135
- }
136
-
137
- /**
138
- * A simple check that the browser has canvas support
139
- */
140
- if (!this.canvas) {
141
- alert('[DRAWING.XAXIS] No canvas support');
142
- return;
143
- }
144
-
145
- /**
146
- * Create the dollar object so that functions can be added to them
147
- */
148
- this.$0 = {};
149
-
150
-
151
- /**
152
- * Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
153
- * done already
154
- */
155
- if (!this.canvas.__rgraph_aa_translated__) {
156
- this.context.translate(0.5,0.5);
157
-
158
- this.canvas.__rgraph_aa_translated__ = true;
159
- }
160
-
161
-
162
-
163
-
164
- // Short variable names
165
- var RG = RGraph,
166
- ca = this.canvas,
167
- co = ca.getContext('2d'),
168
- prop = this.properties,
169
- pa2 = RG.path2,
170
- win = window,
171
- doc = document,
172
- ma = Math
173
-
174
-
175
-
176
- /**
177
- * "Decorate" the object with the generic effects if the effects library has been included
178
- */
179
- if (RG.Effects && typeof RG.Effects.decorate === 'function') {
180
- RG.Effects.decorate(this);
181
- }
182
-
183
-
184
-
185
-
186
- /**
187
- * A setter method for setting graph properties. It can be used like this: obj.Set('chart.strokestyle', '#666');
188
- *
189
- * @param name string The name of the property to set
190
- * @param value mixed The value of the property
191
- */
192
- this.set =
193
- this.Set = function (name)
194
- {
195
- var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
196
-
197
- /**
198
- * the number of arguments is only one and it's an
199
- * object - parse it for configuration data and return.
200
- */
201
- if (arguments.length === 1 && typeof name === 'object') {
202
- RG.parseObjectStyleConfig(this, name);
203
- return this;
204
- }
205
-
206
-
207
-
208
- /**
209
- * This should be done first - prepend the property name with "chart." if necessary
210
- */
211
- if (name.substr(0,6) != 'chart.') {
212
- name = 'chart.' + name;
213
- }
214
-
215
-
216
-
217
-
218
- // Convert uppercase letters to dot+lower case letter
219
- while(name.match(/([A-Z])/)) {
220
- name = name.replace(/([A-Z])/, '.' + RegExp.$1.toLowerCase());
221
- }
222
-
223
- /**
224
- * Make the tickmarks align if labels are specified
225
- */
226
- if (name == 'chart.labels' && !prop['chart.numxticks']) {
227
- prop['chart.numxticks'] = value.length;
228
- }
229
-
230
-
231
-
232
-
233
-
234
-
235
- prop[name] = value;
236
-
237
- return this;
238
- };
239
-
240
-
241
-
242
-
243
- /**
244
- * A getter method for retrieving graph properties. It can be used like this: obj.Get('chart.strokestyle');
245
- *
246
- * @param name string The name of the property to get
247
- */
248
- this.get =
249
- this.Get = function (name)
250
- {
251
- /**
252
- * This should be done first - prepend the property name with "chart." if necessary
253
- */
254
- if (name.substr(0,6) != 'chart.') {
255
- name = 'chart.' + name;
256
- }
257
-
258
- // Convert uppercase letters to dot+lower case letter
259
- while(name.match(/([A-Z])/)) {
260
- name = name.replace(/([A-Z])/, '.' + RegExp.$1.toLowerCase());
261
- }
262
-
263
- return prop[name.toLowerCase()];
264
- };
265
-
266
-
267
-
268
-
269
- /**
270
- * Draws the rectangle
271
- */
272
- this.draw =
273
- this.Draw = function ()
274
- {
275
- /**
276
- * Fire the onbeforedraw event
277
- */
278
- RG.FireCustomEvent(this, 'onbeforedraw');
279
-
280
-
281
-
282
- /**
283
- * Stop this growing uncntrollably
284
- */
285
- this.coordsText = [];
286
-
287
-
288
-
289
-
290
- /**
291
- * Some defaults
292
- */
293
- this.gutterLeft = prop['chart.gutter.left'];
294
- this.gutterRight = prop['chart.gutter.right'];
295
- if (!prop['chart.text.color']) prop['chart.text.color'] = prop['chart.colors'][0];
296
- if (!prop['chart.title.color']) prop['chart.title.color'] = prop['chart.colors'][0];
297
-
298
- /**
299
- * Parse the colors. This allows for simple gradient syntax
300
- */
301
- if (!this.colorsParsed) {
302
-
303
- this.parseColors();
304
-
305
- // Don't want to do this again
306
- this.colorsParsed = true;
307
- }
308
-
309
-
310
-
311
- // DRAW X AXIS HERE
312
- this.DrawXAxis();
313
-
314
-
315
- /**
316
- * This installs the event listeners
317
- */
318
- RG.InstallEventListeners(this);
319
-
320
-
321
-
322
- /**
323
- * Fire the onfirstdraw event
324
- */
325
- if (this.firstDraw) {
326
- RG.fireCustomEvent(this, 'onfirstdraw');
327
- this.firstDraw = false;
328
- this.firstDrawFunc();
329
- }
330
-
331
-
332
-
333
-
334
- /**
335
- * Fire the ondraw event
336
- */
337
- RG.FireCustomEvent(this, 'ondraw');
338
-
339
- return this;
340
- };
341
-
342
-
343
-
344
- /**
345
- * Used in chaining. Runs a function there and then - not waiting for
346
- * the events to fire (eg the onbeforedraw event)
347
- *
348
- * @param function func The function to execute
349
- */
350
- this.exec = function (func)
351
- {
352
- func(this);
353
-
354
- return this;
355
- };
356
-
357
-
358
-
359
-
360
- /**
361
- * The getObjectByXY() worker method
362
- */
363
- this.getObjectByXY = function (e)
364
- {
365
- if (this.getShape(e)) {
366
- return this;
367
- }
368
- };
369
-
370
-
371
-
372
-
373
- /**
374
- * Not used by the class during creating the graph, but is used by event handlers
375
- * to get the coordinates (if any) of the selected shape
376
- *
377
- * @param object e The event object
378
- */
379
- this.getShape = function (e)
380
- {
381
- var mouseXY = RG.getMouseXY(e);
382
- var mouseX = mouseXY[0];
383
- var mouseY = mouseXY[1];
384
-
385
- if ( mouseX >= this.gutterLeft
386
- && mouseX <= (ca.width - this.gutterRight)
387
- && mouseY >= this.y - (prop['chart.align'] == 'top' ? (prop['chart.text.size'] * 1.5) + 5 : 0)
388
- && mouseY <= (this.y + (prop['chart.align'] == 'top' ? 0 : (prop['chart.text.size'] * 1.5) + 5))
389
- ) {
390
-
391
- var x = this.gutterLeft;
392
- var y = this.y;
393
- var w = ca.width - this.gutterLeft - this.gutterRight;
394
- var h = 15;
395
-
396
- return {
397
- 0: this, 1: x, 2: y, 3: w, 4: h, 5: 0,
398
- 'object': this, 'x': x, 'y': y, 'width': w, 'height': h, 'index': 0, 'tooltip': prop['chart.tooltips'] ? prop['chart.tooltips'][0] : null
399
- };
400
- }
401
-
402
- return null;
403
- };
404
-
405
-
406
-
407
-
408
- /**
409
- * This function positions a tooltip when it is displayed
410
- *
411
- * @param obj object The chart object
412
- * @param int x The X coordinate specified for the tooltip
413
- * @param int y The Y coordinate specified for the tooltip
414
- * @param objec tooltip The tooltips DIV element
415
- *
416
- this.positionTooltip = function (obj, x, y, tooltip, idx)
417
- {
418
- var coordX = obj.gutterLeft;
419
- var coordY = obj.y;
420
- var coordW = ca.width - obj.gutterLeft - obj.gutterRight;
421
- var coordH = prop['chart.text.size'] * 1.5;
422
- var canvasXY = RG.getCanvasXY(ca);
423
- var mouseXY = RG.getMouseXY(window.event);
424
- var width = tooltip.offsetWidth;
425
- var height = tooltip.offsetHeight;
426
-
427
-
428
- // Set the top position
429
- tooltip.style.left = 0;
430
- tooltip.style.top = window.event.pageY - height - 5 + 'px';
431
-
432
- // By default any overflow is hidden
433
- tooltip.style.overflow = '';
434
-
435
- // Reposition the tooltip if at the edges:
436
-
437
- // LEFT edge
438
- if (canvasXY[0] + mouseXY[0] - (width / 2) < 0) {
439
- tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.1) + 'px';
440
-
441
- // RIGHT edge
442
- } else if (canvasXY[0] + mouseXY[0] + (width / 2) > doc.body.offsetWidth) {
443
- tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.9) + 'px';
444
-
445
- // Default positioning - CENTERED
446
- } else {
447
- tooltip.style.left = canvasXY[0] + mouseXY[0] - (width / 2) + 'px';
448
- }
449
- };*/
450
-
451
-
452
-
453
-
454
- /**
455
- * Each object type has its own Highlight() function which highlights the appropriate shape
456
- *
457
- * @param object shape The shape to highlight
458
- */
459
- this.highlight =
460
- this.Highlight = function (shape)
461
- {
462
- if (typeof prop['chart.highlight.style'] === 'function') {
463
- (prop['chart.highlight.style'])(shape);
464
- }
465
- };
466
-
467
-
468
-
469
-
470
- /**
471
- * This allows for easy specification of gradients
472
- */
473
- this.parseColors = function ()
474
- {
475
-
476
- // Save the original colors so that they can be restored when the canvas is reset
477
- if (this.original_colors.length === 0) {
478
- this.original_colors['chart.colors'] = RG.array_clone(prop['chart.colors']);
479
- }
480
-
481
-
482
-
483
-
484
- /**
485
- * Parse various properties for colors
486
- */
487
- //this.properties['chart.title.color'] = this.parseSingleColorForGradient(this.properties['chart.title.color']);
488
- //this.properties['chart.text.color'] = this.parseSingleColorForGradient(this.properties['chart.text.color']);
489
- prop['chart.colors'][0] = this.parseSingleColorForGradient(prop['chart.colors'][0]);
490
- };
491
-
492
-
493
-
494
-
495
- /**
496
- * Use this function to reset the object to the post-constructor state. Eg reset colors if
497
- * need be etc
498
- */
499
- this.reset = function ()
500
- {
501
- };
502
-
503
-
504
-
505
-
506
- /**
507
- * This parses a single color value
508
- */
509
- this.parseSingleColorForGradient = function (color)
510
- {
511
- if (!color) {
512
- return color;
513
- }
514
-
515
- if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
516
-
517
- var parts = RegExp.$1.split(':');
518
-
519
- // Create the gradient
520
- var grad = co.createLinearGradient(prop['chart.gutter.left'],0,ca.width - prop['chart.gutter.right'],0);
521
-
522
- var diff = 1 / (parts.length - 1);
523
-
524
- grad.addColorStop(0, RG.trim(parts[0]));
525
-
526
- for (var j=1,len=parts.length; j<len; ++j) {
527
- grad.addColorStop(j * diff, RG.trim(parts[j]));
528
- }
529
- }
530
-
531
- return grad ? grad : color;
532
- };
533
-
534
-
535
-
536
-
537
- /**
538
- * The function that draws the X axis
539
- */
540
- this.drawXAxis =
541
- this.DrawXAxis = function ()
542
- {
543
- var gutterLeft = prop['chart.gutter.left'],
544
- gutterRight = prop['chart.gutter.right'],
545
- x = this.gutterLeft,
546
- y = this.y,
547
- min = +prop['chart.min'],
548
- max = +prop['chart.max'],
549
- labels = prop['chart.labels'],
550
- labels_position = prop['chart.labels.position'],
551
- color = prop['chart.colors'][0],
552
- title_color = prop['chart.title.color'],
553
- label_color = prop['chart.text.color'],
554
- width = ca.width - this.gutterLeft - this.gutterRight,
555
- font = prop['chart.text.font'],
556
- size = prop['chart.text.size'],
557
- align = prop['chart.align'],
558
- numlabels = prop['chart.numlabels'],
559
- formatter = prop['chart.scale.formatter'],
560
- decimals = Number(prop['chart.scale.decimals']),
561
- invert = prop['chart.scale.invert'],
562
- scale_visible = prop['chart.scale.visible'],
563
- units_pre = prop['chart.units.pre'],
564
- units_post = prop['chart.units.post'],
565
- title = prop['chart.title']
566
- numticks = prop['chart.numticks'],
567
- hmargin = prop['chart.hmargin'],
568
- linewidth = prop['chart.linewidth'],
569
- noleftendtick = prop['chart.noendtick.left'],
570
- norightendtick = prop['chart.noendtick.right'],
571
- noxaxis = prop['chart.noxaxis'],
572
- xaxispos = prop['chart.xaxispos'],
573
- yaxispos = prop['chart.yaxispos']
574
-
575
-
576
- if (RG.is_null(numticks)) {
577
- if (labels && labels.length) {
578
- numticks = labels.length;
579
- } else if (!labels && max != 0) {
580
- numticks = 10;
581
- } else {
582
- numticks = numlabels;
583
- }
584
- }
585
-
586
-
587
-
588
- /**
589
- * Set the linewidth
590
- */
591
- co.lineWidth = linewidth + 0.001;
592
-
593
- /**
594
- * Set the color
595
- */
596
- co.strokeStyle = color;
597
-
598
- if (!noxaxis) {
599
- /**
600
- * Draw the main horizontal line
601
- */
602
- pa2(co, ['b','m',x, ma.round(y),'l',x + width, ma.round(y),'s',co.strokeStyle]);
603
-
604
- /**
605
- * Draw the axis tickmarks
606
- */
607
- co.beginPath();
608
- for (var i=(noleftendtick ? 1 : 0); i<=(numticks - (norightendtick ? 1 : 0)); ++i) {
609
- co.moveTo(ma.round(x + ((width / numticks) * i)), xaxispos == 'center' ? (align == 'bottom' ? y - 3 : y + 3) : y);
610
- co.lineTo(ma.round(x + ((width / numticks) * i)), y + (align == 'bottom' ? 3 : -3));
611
- }
612
- co.stroke();
613
- }
614
-
615
-
616
-
617
- /**
618
- * Draw the labels
619
- */
620
- co.fillStyle = label_color;
621
-
622
- if (labels) {
623
- /**
624
- * Draw the labels
625
- */
626
- numlabels = labels.length;
627
- var h = 0;
628
- var l = 0;
629
- var single_line = RG.MeasureText('Mg', false, font, size);
630
-
631
- // Measure the maximum height
632
- for (var i=0,len=labels.length; i<len; ++i) {
633
- var dimensions = RG.MeasureText(labels[i], false, font, size);
634
- var h = ma.max(h, dimensions[1]);
635
- var l = ma.max(l, labels[i].split('\r\n').length);
636
- }
637
-
638
-
639
- for (var i=0,len=labels.length; i<len; ++i) {
640
- RG.text2(this,{
641
- 'font': font,
642
- 'size': size,
643
- 'x': labels_position == 'edge' ? ((((width - hmargin - hmargin) / (labels.length - 1)) * i) + gutterLeft + hmargin) : ((((width - hmargin - hmargin) / labels.length) * i) + ((width / labels.length) / 2) + gutterLeft + hmargin),
644
- 'y':align == 'bottom' ? y + 3 : y - 3 - h + single_line[1],
645
- 'text':String(labels[i]),
646
- 'valign': align == 'bottom' ? 'top' : 'bottom',
647
- 'halign':'center',
648
- 'tag': 'labels'
649
- });
650
- }
651
-
652
-
653
-
654
-
655
-
656
- /**
657
- * No specific labels - draw a scale
658
- */
659
- } else if (scale_visible){
660
-
661
- if (max === null) {
662
- alert('[DRAWING.XAXIS] If not specifying axis.labels you must specify axis.max!');
663
- }
664
-
665
- // yaxispos
666
- if (yaxispos == 'center') {
667
- width /= 2;
668
- var additionalX = width;
669
- } else {
670
- var additionalX = 0;
671
- }
672
-
673
- for (var i=0; i<=numlabels; ++i) {
674
-
675
- // Don't show zero if the chart.scale.zerostart option is false
676
- if (i == 0 && !prop['chart.scale.zerostart']) {
677
- continue;
678
- }
679
-
680
- var original = (((max - min) / numlabels) * i) + min;
681
- var hmargin = prop['chart.hmargin'];
682
-
683
- var text = String(typeof(formatter) == 'function' ? formatter(this, original) : RG.numberFormat(this, original.toFixed(original === 0 ? 0 : decimals), units_pre, units_post));
684
-
685
- if (invert) {
686
- var x = ((width - hmargin - ((width - hmargin - hmargin) / numlabels) * i)) + gutterLeft + additionalX;
687
- } else {
688
- var x = (((width - hmargin - hmargin) / numlabels) * i) + gutterLeft + hmargin + additionalX;
689
- }
690
-
691
- RG.Text2(this,{
692
- 'font': font,
693
- 'size': size,
694
- 'x': x,
695
- 'y': align == 'bottom' ? y + 3 : y - 3,
696
- 'text':text,
697
- 'valign':align == 'bottom' ? 'top' : 'bottom',
698
- 'halign':'center',
699
- 'tag': 'scale'
700
- });
701
- }
702
-
703
- /**
704
- * If the Y axis is in the center - this draws the left half of the labels
705
- */
706
- if (yaxispos == 'center') {
707
- for (var i=0; i<numlabels; ++i) {
708
-
709
- var original = (((max - min) / numlabels) * (numlabels - i)) + min;
710
- var hmargin = prop['chart.hmargin'];
711
-
712
- var text = String(typeof(formatter) == 'function' ? formatter(this, original) : RG.number_format(this, original.toFixed(decimals), units_pre, units_post));
713
-
714
- if (invert) {
715
- var x = ((width - hmargin - ((width - hmargin - hmargin) / numlabels) * i)) + gutterLeft;
716
- } else {
717
- var x = (((width - hmargin - hmargin) / numlabels) * i) + gutterLeft + hmargin;
718
- }
719
-
720
- RG.text2(this, {
721
- 'font':font,
722
- 'size':size,
723
- 'x':x,
724
- 'y':align == 'bottom' ? y + size + 2 : y - size - 2,'text':'-' + text,
725
- 'valign':'center',
726
- 'halign':'center',
727
- 'tag': 'scale'
728
- });
729
- }
730
- }
731
- }
732
-
733
-
734
-
735
- /**
736
- * Draw the title for the axes
737
- */
738
- if (title) {
739
-
740
- var dimensions = RG.MeasureText(title, false, font, size + 2);
741
-
742
- co.fillStyle = title_color
743
- RG.Text2(this,{'font': font,
744
- 'size': size + 2,
745
- 'x': (ca.width - this.gutterLeft - this.gutterRight) / 2 + this.gutterLeft,
746
- 'y': align == 'bottom' ? y + dimensions[1] + 10 : y - dimensions[1] - 10,
747
- 'text': title,
748
- 'valign': 'center',
749
- 'halign':'center',
750
- 'tag': 'title'
751
- });
752
- }
753
- };
754
-
755
-
756
-
757
-
758
- /**
759
- * Using a function to add events makes it easier to facilitate method chaining
760
- *
761
- * @param string type The type of even to add
762
- * @param function func
763
- */
764
- this.on = function (type, func)
765
- {
766
- if (type.substr(0,2) !== 'on') {
767
- type = 'on' + type;
768
- }
769
-
770
- if (typeof this[type] !== 'function') {
771
- this[type] = func;
772
- } else {
773
- RG.addCustomEventListener(this, type, func);
774
- }
775
-
776
- return this;
777
- };
778
-
779
-
780
-
781
-
782
- /**
783
- * This function runs once only
784
- * (put at the end of the file (before any effects))
785
- */
786
- this.firstDrawFunc = function ()
787
- {
788
- };
789
-
790
-
791
- RG.att(ca);
792
-
793
-
794
-
795
-
796
-
797
-
798
- /**
799
- * Objects are now always registered so that the chart is redrawn if need be.
800
- */
801
- RG.Register(this);
802
-
803
-
804
-
805
-
806
- /**
807
- * This is the 'end' of the constructor so if the first argument
808
- * contains configuration data - handle that.
809
- */
810
- if (parseConfObjectForOptions) {
811
- RG.parseObjectStyleConfig(this, conf.options);
812
- }
813
- };
2
+ RGraph=window.RGraph||{isRGraph:true};RGraph.Drawing=RGraph.Drawing||{};RGraph.Drawing.XAxis=function(conf)
3
+ {if(typeof conf==='object'&&typeof conf.y==='number'&&typeof conf.id==='string'){var id=conf.id
4
+ var y=conf.y;var parseConfObjectForOptions=true;}else{var id=conf;var y=arguments[1];}
5
+ this.id=id;this.canvas=document.getElementById(this.id);this.context=this.canvas.getContext('2d');this.canvas.__object__=this;this.y=y;this.coords=[];this.coordsText=[];this.original_colors=[];this.firstDraw=true;this.type='drawing.xaxis';this.isRGraph=true;this.uid=RGraph.CreateUID();this.canvas.uid=this.canvas.uid?this.canvas.uid:RGraph.CreateUID();this.properties={'chart.gutter.left':25,'chart.gutter.right':25,'chart.labels':null,'chart.labels.position':'section','chart.colors':['black'],'chart.title.color':null,'chart.text.color':null,'chart.text.font':'Segoe UI, Arial, Verdana, sans-serif','chart.text.size':12,'chart.text.accessible':true,'chart.text.accessible.overflow':'visible','chart.text.accessible.pointerevents':true,'chart.align':'bottom','chart.numlabels':5,'chart.scale.visible':true,'chart.scale.formatter':null,'chart.scale.decimals':0,'chart.scale.point':'.','chart.scale.thousand':',','chart.scale.invert':false,'chart.scale.zerostart':true,'chart.units.pre':'','chart.units.post':'','chart.title':'','chart.numticks':null,'chart.hmargin':0,'chart.linewidth':1,'chart.noendtick.left':false,'chart.noendtick.right':false,'chart.noxaxis':false,'chart.max':null,'chart.min':0,'chart.tooltips':null,'chart.tooltips.effect':'fade','chart.tooltips.css.class':'RGraph_tooltip','chart.tooltips.event':'onclick','chart.events.click':null,'chart.events.mousemove':null,'chart.xaxispos':'bottom','chart.yaxispos':'left','chart.clearto':'rgba(0,0,0,0)'}
6
+ if(!this.canvas){alert('[DRAWING.XAXIS] No canvas support');return;}
7
+ this.$0={};if(!this.canvas.__rgraph_aa_translated__){this.context.translate(0.5,0.5);this.canvas.__rgraph_aa_translated__=true;}
8
+ var RG=RGraph,ca=this.canvas,co=ca.getContext('2d'),prop=this.properties,pa2=RG.path2,win=window,doc=document,ma=Math
9
+ if(RG.Effects&&typeof RG.Effects.decorate==='function'){RG.Effects.decorate(this);}
10
+ this.set=this.Set=function(name)
11
+ {var value=typeof arguments[1]==='undefined'?null:arguments[1];if(arguments.length===1&&typeof name==='object'){RG.parseObjectStyleConfig(this,name);return this;}
12
+ if(name.substr(0,6)!='chart.'){name='chart.'+name;}
13
+ while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
14
+ if(name=='chart.labels'&&!prop['chart.numxticks']){prop['chart.numxticks']=value.length;}
15
+ prop[name]=value;return this;};this.get=this.Get=function(name)
16
+ {if(name.substr(0,6)!='chart.'){name='chart.'+name;}
17
+ while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
18
+ return prop[name.toLowerCase()];};this.draw=this.Draw=function()
19
+ {RG.FireCustomEvent(this,'onbeforedraw');this.coordsText=[];this.gutterLeft=prop['chart.gutter.left'];this.gutterRight=prop['chart.gutter.right'];if(!prop['chart.text.color'])prop['chart.text.color']=prop['chart.colors'][0];if(!prop['chart.title.color'])prop['chart.title.color']=prop['chart.colors'][0];if(!this.colorsParsed){this.parseColors();this.colorsParsed=true;}
20
+ this.DrawXAxis();RG.InstallEventListeners(this);if(this.firstDraw){this.firstDraw=false;RG.fireCustomEvent(this,'onfirstdraw');this.firstDrawFunc();}
21
+ RG.FireCustomEvent(this,'ondraw');return this;};this.exec=function(func)
22
+ {func(this);return this;};this.getObjectByXY=function(e)
23
+ {if(this.getShape(e)){return this;}};this.getShape=function(e)
24
+ {var mouseXY=RG.getMouseXY(e);var mouseX=mouseXY[0];var mouseY=mouseXY[1];if(mouseX>=this.gutterLeft&&mouseX<=(ca.width-this.gutterRight)&&mouseY>=this.y-(prop['chart.align']=='top'?(prop['chart.text.size']*1.5)+5:0)&&mouseY<=(this.y+(prop['chart.align']=='top'?0:(prop['chart.text.size']*1.5)+5))){var x=this.gutterLeft;var y=this.y;var w=ca.width-this.gutterLeft-this.gutterRight;var h=15;return{0:this,1:x,2:y,3:w,4:h,5:0,'object':this,'x':x,'y':y,'width':w,'height':h,'index':0,'tooltip':prop['chart.tooltips']?prop['chart.tooltips'][0]:null};}
25
+ return null;};this.highlight=this.Highlight=function(shape)
26
+ {if(typeof prop['chart.highlight.style']==='function'){(prop['chart.highlight.style'])(shape);}};this.parseColors=function()
27
+ {if(this.original_colors.length===0){this.original_colors['chart.colors']=RG.array_clone(prop['chart.colors']);}
28
+ prop['chart.colors'][0]=this.parseSingleColorForGradient(prop['chart.colors'][0]);};this.reset=function()
29
+ {};this.parseSingleColorForGradient=function(color)
30
+ {if(!color){return color;}
31
+ if(typeof color==='string'&&color.match(/^gradient\((.*)\)$/i)){var parts=RegExp.$1.split(':');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,len=parts.length;j<len;++j){grad.addColorStop(j*diff,RG.trim(parts[j]));}}
32
+ return grad?grad:color;};this.drawXAxis=this.DrawXAxis=function()
33
+ {var gutterLeft=prop['chart.gutter.left'],gutterRight=prop['chart.gutter.right'],x=this.gutterLeft,y=this.y,min=+prop['chart.min'],max=+prop['chart.max'],labels=prop['chart.labels'],labels_position=prop['chart.labels.position'],color=prop['chart.colors'][0],title_color=prop['chart.title.color'],label_color=prop['chart.text.color'],width=ca.width-this.gutterLeft-this.gutterRight,font=prop['chart.text.font'],size=prop['chart.text.size'],align=prop['chart.align'],numlabels=prop['chart.numlabels'],formatter=prop['chart.scale.formatter'],decimals=Number(prop['chart.scale.decimals']),invert=prop['chart.scale.invert'],scale_visible=prop['chart.scale.visible'],units_pre=prop['chart.units.pre'],units_post=prop['chart.units.post'],title=prop['chart.title']
34
+ numticks=prop['chart.numticks'],hmargin=prop['chart.hmargin'],linewidth=prop['chart.linewidth'],noleftendtick=prop['chart.noendtick.left'],norightendtick=prop['chart.noendtick.right'],noxaxis=prop['chart.noxaxis'],xaxispos=prop['chart.xaxispos'],yaxispos=prop['chart.yaxispos']
35
+ if(RG.is_null(numticks)){if(labels&&labels.length){numticks=labels.length;}else if(!labels&&max!=0){numticks=10;}else{numticks=numlabels;}}
36
+ co.lineWidth=linewidth+0.001;co.strokeStyle=color;if(!noxaxis){pa2(co,['b','m',x,ma.round(y),'l',x+width,ma.round(y),'s',co.strokeStyle]);co.beginPath();for(var i=(noleftendtick?1:0);i<=(numticks-(norightendtick?1:0));++i){co.moveTo(ma.round(x+((width/numticks)*i)),xaxispos=='center'?(align=='bottom'?y-3:y+3):y);co.lineTo(ma.round(x+((width/numticks)*i)),y+(align=='bottom'?3:-3));}
37
+ co.stroke();}
38
+ co.fillStyle=label_color;if(labels){numlabels=labels.length;var h=0;var l=0;var single_line=RG.MeasureText('Mg',false,font,size);for(var i=0,len=labels.length;i<len;++i){var dimensions=RG.MeasureText(labels[i],false,font,size);var h=ma.max(h,dimensions[1]);var l=ma.max(l,labels[i].split('\r\n').length);}
39
+ for(var i=0,len=labels.length;i<len;++i){RG.text2(this,{'font':font,'size':size,'x':labels_position=='edge'?((((width-hmargin-hmargin)/(labels.length-1))*i)+gutterLeft+hmargin):((((width-hmargin-hmargin)/labels.length)*i)+((width/labels.length)/2)+gutterLeft+hmargin),'y':align=='bottom'?y+3:y-3-h+single_line[1],'text':String(labels[i]),'valign':align=='bottom'?'top':'bottom','halign':'center','tag':'labels'});}}else if(scale_visible){if(max===null){alert('[DRAWING.XAXIS] If not specifying axis.labels you must specify axis.max!');}
40
+ if(yaxispos=='center'){width/=2;var additionalX=width;}else{var additionalX=0;}
41
+ for(var i=0;i<=numlabels;++i){if(i==0&&!prop['chart.scale.zerostart']){continue;}
42
+ var original=(((max-min)/numlabels)*i)+min;var hmargin=prop['chart.hmargin'];var text=String(typeof(formatter)=='function'?formatter(this,original):RG.numberFormat(this,original.toFixed(original===0?0:decimals),units_pre,units_post));if(invert){var x=((width-hmargin-((width-hmargin-hmargin)/numlabels)*i))+gutterLeft+additionalX;}else{var x=(((width-hmargin-hmargin)/numlabels)*i)+gutterLeft+hmargin+additionalX;}
43
+ RG.Text2(this,{'font':font,'size':size,'x':x,'y':align=='bottom'?y+3:y-3,'text':text,'valign':align=='bottom'?'top':'bottom','halign':'center','tag':'scale'});}
44
+ if(yaxispos=='center'){for(var i=0;i<numlabels;++i){var original=(((max-min)/numlabels)*(numlabels-i))+min;var hmargin=prop['chart.hmargin'];var text=String(typeof(formatter)=='function'?formatter(this,original):RG.number_format(this,original.toFixed(decimals),units_pre,units_post));if(invert){var x=((width-hmargin-((width-hmargin-hmargin)/numlabels)*i))+gutterLeft;}else{var x=(((width-hmargin-hmargin)/numlabels)*i)+gutterLeft+hmargin;}
45
+ RG.text2(this,{'font':font,'size':size,'x':x,'y':align=='bottom'?y+size+2:y-size-2,'text':'-'+text,'valign':'center','halign':'center','tag':'scale'});}}}
46
+ if(title){var dimensions=RG.MeasureText(title,false,font,size+2);co.fillStyle=title_color
47
+ RG.Text2(this,{'font':font,'size':size+2,'x':(ca.width-this.gutterLeft-this.gutterRight)/2+this.gutterLeft,'y':align=='bottom'?y+dimensions[1]+10:y-dimensions[1]-10,'text':title,'valign':'center','halign':'center','tag':'title'});}};this.on=function(type,func)
48
+ {if(type.substr(0,2)!=='on'){type='on'+type;}
49
+ if(typeof this[type]!=='function'){this[type]=func;}else{RG.addCustomEventListener(this,type,func);}
50
+ return this;};this.firstDrawFunc=function()
51
+ {};RG.att(ca);RG.Register(this);if(parseConfObjectForOptions){RG.parseObjectStyleConfig(this,conf.options);}};