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