rgraph-rails 1.0.5 → 1.0.6
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.
- checksums.yaml +8 -8
- data/.travis.yml +0 -1
- data/README.md +3 -3
- data/lib/rgraph-rails/version.rb +1 -1
- data/vendor/assets/javascripts/RGraph.bar.js +239 -3764
- data/vendor/assets/javascripts/RGraph.bipolar.js +115 -1986
- data/vendor/assets/javascripts/RGraph.common.annotate.js +35 -399
- data/vendor/assets/javascripts/RGraph.common.context.js +30 -600
- data/vendor/assets/javascripts/RGraph.common.core.js +403 -5187
- data/vendor/assets/javascripts/RGraph.common.csv.js +19 -275
- data/vendor/assets/javascripts/RGraph.common.deprecated.js +35 -454
- data/vendor/assets/javascripts/RGraph.common.dynamic.js +84 -1189
- data/vendor/assets/javascripts/RGraph.common.effects.js +90 -1548
- data/vendor/assets/javascripts/RGraph.common.key.js +54 -755
- data/vendor/assets/javascripts/RGraph.common.resizing.js +37 -567
- data/vendor/assets/javascripts/RGraph.common.sheets.js +29 -356
- data/vendor/assets/javascripts/RGraph.common.tooltips.js +32 -614
- data/vendor/assets/javascripts/RGraph.common.zoom.js +14 -223
- data/vendor/assets/javascripts/RGraph.cornergauge.js +71 -0
- data/vendor/assets/javascripts/RGraph.drawing.background.js +35 -620
- data/vendor/assets/javascripts/RGraph.drawing.circle.js +35 -576
- data/vendor/assets/javascripts/RGraph.drawing.image.js +52 -807
- data/vendor/assets/javascripts/RGraph.drawing.marker1.js +41 -717
- data/vendor/assets/javascripts/RGraph.drawing.marker2.js +37 -668
- data/vendor/assets/javascripts/RGraph.drawing.marker3.js +36 -563
- data/vendor/assets/javascripts/RGraph.drawing.poly.js +40 -608
- data/vendor/assets/javascripts/RGraph.drawing.rect.js +35 -597
- data/vendor/assets/javascripts/RGraph.drawing.text.js +34 -642
- data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +50 -809
- data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +51 -856
- data/vendor/assets/javascripts/RGraph.fuel.js +58 -964
- data/vendor/assets/javascripts/RGraph.funnel.js +55 -984
- data/vendor/assets/javascripts/RGraph.gantt.js +75 -1241
- data/vendor/assets/javascripts/RGraph.gauge.js +87 -1397
- data/vendor/assets/javascripts/RGraph.hbar.js +143 -2376
- data/vendor/assets/javascripts/RGraph.hprogress.js +80 -1397
- data/vendor/assets/javascripts/RGraph.line.js +241 -4162
- data/vendor/assets/javascripts/RGraph.meter.js +74 -1278
- metadata +3 -30
- data/vendor/assets/images/bg.png +0 -0
- data/vendor/assets/images/bullet.png +0 -0
- data/vendor/assets/images/facebook-large.png +0 -0
- data/vendor/assets/images/google-plus-large.png +0 -0
- data/vendor/assets/images/logo.png +0 -0
- data/vendor/assets/images/meter-image-sd-needle.png +0 -0
- data/vendor/assets/images/meter-image-sd.png +0 -0
- data/vendor/assets/images/meter-sketch-needle.png +0 -0
- data/vendor/assets/images/meter-sketch.png +0 -0
- data/vendor/assets/images/odometer-background.png +0 -0
- data/vendor/assets/images/rgraph.jpg +0 -0
- data/vendor/assets/images/title.png +0 -0
- data/vendor/assets/images/twitter-large.png +0 -0
- data/vendor/assets/javascripts/RGraph.modaldialog.js +0 -301
- data/vendor/assets/javascripts/RGraph.odo.js +0 -1265
- data/vendor/assets/javascripts/RGraph.pie.js +0 -2272
- data/vendor/assets/javascripts/RGraph.radar.js +0 -1847
- data/vendor/assets/javascripts/RGraph.rose.js +0 -1877
- data/vendor/assets/javascripts/RGraph.rscatter.js +0 -1425
- data/vendor/assets/javascripts/RGraph.scatter.js +0 -2970
- data/vendor/assets/javascripts/RGraph.semicircularprogress.js +0 -1015
- data/vendor/assets/javascripts/RGraph.thermometer.js +0 -1129
- data/vendor/assets/javascripts/RGraph.vprogress.js +0 -1452
- data/vendor/assets/javascripts/RGraph.waterfall.js +0 -1252
- data/vendor/assets/javascripts/financial-data.js +0 -1067
- data/vendor/assets/stylesheets/ModalDialog.css +0 -90
- data/vendor/assets/stylesheets/animations.css +0 -3347
- data/vendor/assets/stylesheets/website.css +0 -446
@@ -1,643 +1,35 @@
|
|
1
|
-
// version: 2016-06-04
|
2
|
-
/**
|
3
|
-
* o--------------------------------------------------------------------------------o
|
4
|
-
* | This file is part of the RGraph package - you can learn more at: |
|
5
|
-
* | |
|
6
|
-
* | http://www.rgraph.net |
|
7
|
-
* | |
|
8
|
-
* | RGraph is dual licensed under the Open Source GPL (General Public License) |
|
9
|
-
* | v2.0 license and a commercial license which means that you're not bound by |
|
10
|
-
* | the terms of the GPL. The commercial license is just 99 GBP and you can |
|
11
|
-
* | read about it here: |
|
12
|
-
* | http://www.rgraph.net/license |
|
13
|
-
* o--------------------------------------------------------------------------------o
|
14
|
-
*/
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Having this here means that the RGraph libraries can be included in any order, instead of you having
|
18
|
-
* to include the common core library first.
|
19
|
-
*/
|
20
1
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
var x = arguments[1];
|
56
|
-
var y = arguments[2];
|
57
|
-
var text = arguments[3];
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
this.id = id;
|
64
|
-
this.canvas = document.getElementById(id);
|
65
|
-
this.context = this.canvas.getContext('2d');
|
66
|
-
this.colorsParsed = false;
|
67
|
-
this.canvas.__object__ = this;
|
68
|
-
this.x = x;
|
69
|
-
this.y = y;
|
70
|
-
this.text = String(text);
|
71
|
-
this.coords = [];
|
72
|
-
this.coordsText = [];
|
73
|
-
this.original_colors = [];
|
74
|
-
this.firstDraw = true; // After the first draw this will be false
|
75
|
-
|
76
|
-
|
77
|
-
/**
|
78
|
-
* This defines the type of this shape
|
79
|
-
*/
|
80
|
-
this.type = 'drawing.text';
|
81
|
-
|
82
|
-
|
83
|
-
/**
|
84
|
-
* This facilitates easy object identification, and should always be true
|
85
|
-
*/
|
86
|
-
this.isRGraph = true;
|
87
|
-
|
88
|
-
|
89
|
-
/**
|
90
|
-
* This adds a uid to the object that you can use for identification purposes
|
91
|
-
*/
|
92
|
-
this.uid = RGraph.CreateUID();
|
93
|
-
|
94
|
-
|
95
|
-
/**
|
96
|
-
* This adds a UID to the canvas for identification purposes
|
97
|
-
*/
|
98
|
-
this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
/**
|
104
|
-
* Some example background properties
|
105
|
-
*/
|
106
|
-
this.properties =
|
107
|
-
{
|
108
|
-
'chart.size': 10,
|
109
|
-
'chart.font': 'Segoe UI, Arial, Verdana, sans-serif',
|
110
|
-
'chart.bold': false,
|
111
|
-
'chart.angle': 0,
|
112
|
-
'chart.colors': ['black'],
|
113
|
-
'chart.events.click': null,
|
114
|
-
'chart.events.mousemove': null,
|
115
|
-
'chart.highlight.stroke': '#ccc',
|
116
|
-
'chart.highlight.fill': 'rgba(255,255,255,0.7)',
|
117
|
-
'chart.tooltips': null,
|
118
|
-
'chart.tooltips.effect': 'fade',
|
119
|
-
'chart.tooltips.css.class': 'RGraph_tooltip',
|
120
|
-
'chart.tooltips.event': 'onclick',
|
121
|
-
'chart.tooltips.highlight': true,
|
122
|
-
'chart.tooltips.coords.page': false,
|
123
|
-
'chart.bounding': false,
|
124
|
-
'chart.bounding.fill': 'rgba(255,255,255,0.7)',
|
125
|
-
'chart.bounding.stroke': '#777',
|
126
|
-
'chart.bounding.shadow': false,
|
127
|
-
'chart.bounding.shadow.color': '#ccc',
|
128
|
-
'chart.bounding.shadow.blur': 3,
|
129
|
-
'chart.bounding.shadow.offsetx': 3,
|
130
|
-
'chart.bounding.shadow.offsety': 3,
|
131
|
-
'chart.marker': false,
|
132
|
-
'chart.halign': 'left',
|
133
|
-
'chart.valign': 'bottom',
|
134
|
-
'chart.link': null,
|
135
|
-
'chart.link.target': '_self',
|
136
|
-
'chart.link.options': '',
|
137
|
-
'chart.text.accessible': true,
|
138
|
-
'chart.text.accessible.overflow': 'visible',
|
139
|
-
'chart.text.accessible.pointerevents': false,
|
140
|
-
'chart.clearto': 'rgba(0,0,0,0)'
|
141
|
-
}
|
142
|
-
|
143
|
-
/**
|
144
|
-
* A simple check that the browser has canvas support
|
145
|
-
*/
|
146
|
-
if (!this.canvas) {
|
147
|
-
alert('[DRAWING.TEXT] No canvas support');
|
148
|
-
return;
|
149
|
-
}
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Create the dollar object so that functions can be added to them
|
153
|
-
*/
|
154
|
-
this.$0 = {};
|
155
|
-
|
156
|
-
|
157
|
-
/**
|
158
|
-
* Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
|
159
|
-
* done already
|
160
|
-
*/
|
161
|
-
if (!this.canvas.__rgraph_aa_translated__) {
|
162
|
-
this.context.translate(0.5,0.5);
|
163
|
-
|
164
|
-
this.canvas.__rgraph_aa_translated__ = true;
|
165
|
-
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
// Short variable names
|
173
|
-
var RG = RGraph,
|
174
|
-
ca = this.canvas,
|
175
|
-
co = ca.getContext('2d'),
|
176
|
-
prop = this.properties,
|
177
|
-
pa2 = RG.path2,
|
178
|
-
win = window,
|
179
|
-
doc = document,
|
180
|
-
ma = Math
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
/**
|
185
|
-
* "Decorate" the object with the generic effects if the effects library has been included
|
186
|
-
*/
|
187
|
-
if (RG.Effects && typeof RG.Effects.decorate === 'function') {
|
188
|
-
RG.Effects.decorate(this);
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
/**
|
196
|
-
* A setter method for setting properties.
|
197
|
-
*
|
198
|
-
* @param name string The name of the property to set OR it can be a map
|
199
|
-
* of name/value settings like what you set in the constructor
|
200
|
-
*/
|
201
|
-
this.set =
|
202
|
-
this.Set = function (name)
|
203
|
-
{
|
204
|
-
var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
|
205
|
-
|
206
|
-
/**
|
207
|
-
* the number of arguments is only one and it's an
|
208
|
-
* object - parse it for configuration data and return.
|
209
|
-
*/
|
210
|
-
if (arguments.length === 1 && typeof name === 'object') {
|
211
|
-
RG.parseObjectStyleConfig(this, name);
|
212
|
-
return this;
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
/**
|
220
|
-
* This should be done first - prepend the property name with "chart." if necessary
|
221
|
-
*/
|
222
|
-
if (name.substr(0,6) != 'chart.') {
|
223
|
-
name = 'chart.' + name;
|
224
|
-
}
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
// Convert uppercase letters to dot+lower case letter
|
230
|
-
while(name.match(/([A-Z])/)) {
|
231
|
-
name = name.replace(/([A-Z])/, '.' + RegExp.$1.toLowerCase());
|
232
|
-
}
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
prop[name] = value;
|
240
|
-
|
241
|
-
return this;
|
242
|
-
};
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
/**
|
248
|
-
* A getter method for retrieving graph properties. It can be used like this: obj.Get('chart.strokestyle');
|
249
|
-
*
|
250
|
-
* @param name string The name of the property to get
|
251
|
-
*/
|
252
|
-
this.get =
|
253
|
-
this.Get = function (name)
|
254
|
-
{
|
255
|
-
/**
|
256
|
-
* This should be done first - prepend the property name with "chart." if necessary
|
257
|
-
*/
|
258
|
-
if (name.substr(0,6) != 'chart.') {
|
259
|
-
name = 'chart.' + name;
|
260
|
-
}
|
261
|
-
|
262
|
-
// Convert uppercase letters to dot+lower case letter
|
263
|
-
name = name.replace(/([A-Z])/g, function (str)
|
264
|
-
{
|
265
|
-
return '.' + String(RegExp.$1).toLowerCase()
|
266
|
-
});
|
267
|
-
|
268
|
-
return prop[name.toLowerCase()];
|
269
|
-
};
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
/**
|
275
|
-
* Draws the rectangle
|
276
|
-
*/
|
277
|
-
this.draw =
|
278
|
-
this.Draw = function ()
|
279
|
-
{
|
280
|
-
/**
|
281
|
-
* Fire the onbeforedraw event
|
282
|
-
*/
|
283
|
-
RG.FireCustomEvent(this, 'onbeforedraw');
|
284
|
-
|
285
|
-
|
286
|
-
/**
|
287
|
-
* Parse the colors. This allows for simple gradient syntax
|
288
|
-
*/
|
289
|
-
if (!this.colorsParsed) {
|
290
|
-
|
291
|
-
this.parseColors();
|
292
|
-
|
293
|
-
// Don't want to do this again
|
294
|
-
this.colorsParsed = true;
|
295
|
-
}
|
296
|
-
|
297
|
-
|
298
|
-
/**
|
299
|
-
* Stop the coods array from growing
|
300
|
-
*/
|
301
|
-
this.coords = [];
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
/**
|
306
|
-
* Stop this growing uncntrollably
|
307
|
-
*/
|
308
|
-
this.coordsText = [];
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
/**
|
314
|
-
* The font, its size and whether its bold or not can be set by properties,
|
315
|
-
* so now they have been (potentiall) set - measure the text
|
316
|
-
*/
|
317
|
-
/**
|
318
|
-
* Measure the text and add the width/height
|
319
|
-
*
|
320
|
-
* text, bold, font, size
|
321
|
-
*
|
322
|
-
*/
|
323
|
-
var dimensions = RG.MeasureText(this.text, prop['chart.text.bold'],prop['chart.text.font'], prop['chart.text.size']);
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
// ------------- DRAW TEXT HERE -------------
|
328
|
-
co.fillStyle = prop['chart.colors'][0];
|
329
|
-
|
330
|
-
var ret = RG.text2(this, {
|
331
|
-
font: prop['chart.font'],
|
332
|
-
size: prop['chart.size'],
|
333
|
-
x: this.x,
|
334
|
-
y: this.y,
|
335
|
-
text: this.text,
|
336
|
-
bold: prop['chart.bold'],
|
337
|
-
angle: prop['chart.angle'],
|
338
|
-
bounding: prop['chart.bounding'],
|
339
|
-
'bounding.fill': prop['chart.bounding.fill'],
|
340
|
-
'bounding.stroke': prop['chart.bounding.stroke'],
|
341
|
-
'bounding.shadow': prop['chart.bounding.shadow'],
|
342
|
-
'bounding.shadow.color': prop['chart.bounding.shadow.color'],
|
343
|
-
'bounding.shadow.blur': prop['chart.bounding.shadow.blur'],
|
344
|
-
'bounding.shadow.offsetx': prop['chart.bounding.shadow.offsetx'],
|
345
|
-
'bounding.shadow.offsety': prop['chart.bounding.shadow.offsety'],
|
346
|
-
marker: prop['chart.marker'],
|
347
|
-
halign: prop['chart.halign'],
|
348
|
-
valign: prop['chart.valign']
|
349
|
-
});
|
350
|
-
|
351
|
-
|
352
|
-
// store the dimensions
|
353
|
-
this.coords.push({
|
354
|
-
0: ret.x, 'x': ret.x,
|
355
|
-
1: ret.y, 'y': ret.y,
|
356
|
-
2: ret.width, 'width': ret.width,
|
357
|
-
3: ret.height, 'height': ret.height
|
358
|
-
});
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
/**
|
363
|
-
* This installs the event listeners
|
364
|
-
*/
|
365
|
-
RG.InstallEventListeners(this);
|
366
|
-
|
367
|
-
|
368
|
-
/**
|
369
|
-
* Fire the onfirstdraw event
|
370
|
-
*/
|
371
|
-
if (this.firstDraw) {
|
372
|
-
RG.fireCustomEvent(this, 'onfirstdraw');
|
373
|
-
this.firstDraw = false;
|
374
|
-
this.firstDrawFunc();
|
375
|
-
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
/**
|
381
|
-
* Fire the ondraw event
|
382
|
-
*/
|
383
|
-
RG.FireCustomEvent(this, 'ondraw');
|
384
|
-
|
385
|
-
return this;
|
386
|
-
};
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
/**
|
391
|
-
* Used in chaining. Runs a function there and then - not waiting for
|
392
|
-
* the events to fire (eg the onbeforedraw event)
|
393
|
-
*
|
394
|
-
* @param function func The function to execute
|
395
|
-
*/
|
396
|
-
this.exec = function (func)
|
397
|
-
{
|
398
|
-
func(this);
|
399
|
-
|
400
|
-
return this;
|
401
|
-
};
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
/**
|
407
|
-
* The getObjectByXY() worker method
|
408
|
-
*/
|
409
|
-
this.getObjectByXY = function (e)
|
410
|
-
{
|
411
|
-
if (this.getShape(e)) {
|
412
|
-
return this;
|
413
|
-
}
|
414
|
-
};
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
/**
|
420
|
-
* Not used by the class during creating the graph, but is used by event handlers
|
421
|
-
* to get the coordinates (if any) of the selected bar
|
422
|
-
*
|
423
|
-
* @param object e The event object
|
424
|
-
*/
|
425
|
-
this.getShape = function (e)
|
426
|
-
{
|
427
|
-
var prop = this.properties;
|
428
|
-
var coords = this.coords;
|
429
|
-
var mouseXY = RGraph.getMouseXY(e);
|
430
|
-
var mouseX = mouseXY[0];
|
431
|
-
var mouseY = mouseXY[1];
|
432
|
-
|
433
|
-
for (var i=0,len=this.coords.length; i<len; i++) {
|
434
|
-
|
435
|
-
var left = coords[i].x;
|
436
|
-
var top = coords[i].y;
|
437
|
-
var width = coords[i].width;
|
438
|
-
var height = coords[i].height;
|
439
|
-
|
440
|
-
if (mouseX >= left && mouseX <= (left + width) && mouseY >= top && mouseY <= (top + height)) {
|
441
|
-
|
442
|
-
return {
|
443
|
-
0: this, 1: left, 2: top, 3: width, 4: height, 5: 0,
|
444
|
-
'object': this, 'x': left, 'y': top, 'width': width, 'height': height, 'index': 0, 'tooltip': prop['chart.tooltips'] ? prop['chart.tooltips'][0] : null
|
445
|
-
};
|
446
|
-
}
|
447
|
-
}
|
448
|
-
|
449
|
-
return null;
|
450
|
-
};
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
/**
|
456
|
-
* This function positions a tooltip when it is displayed
|
457
|
-
*
|
458
|
-
* @param obj object The chart object
|
459
|
-
* @param int x The X coordinate specified for the tooltip
|
460
|
-
* @param int y The Y coordinate specified for the tooltip
|
461
|
-
* @param objec tooltip The tooltips DIV element
|
462
|
-
*/
|
463
|
-
this.positionTooltip = function (obj, x, y, tooltip, idx)
|
464
|
-
{
|
465
|
-
var coords = obj.coords[0];
|
466
|
-
var coordX = parseFloat(coords.x);
|
467
|
-
var coordY = parseFloat(coords.y);
|
468
|
-
var coordW = coords.width;
|
469
|
-
var coordH = coords.height;
|
470
|
-
var canvasXY = RG.getCanvasXY(obj.canvas);
|
471
|
-
var mouseXY = RG.getMouseXY(window.event);
|
472
|
-
var width = tooltip.offsetWidth;
|
473
|
-
var height = tooltip.offsetHeight;
|
474
|
-
|
475
|
-
// Set the top position
|
476
|
-
tooltip.style.left = 0;
|
477
|
-
tooltip.style.top = window.event.pageY - height - 5 + 'px';
|
478
|
-
|
479
|
-
// By default any overflow is hidden
|
480
|
-
tooltip.style.overflow = '';
|
481
|
-
|
482
|
-
// Reposition the tooltip if at the edges:
|
483
|
-
|
484
|
-
// LEFT edge
|
485
|
-
if (canvasXY[0] + mouseXY[0] - (width / 2) < 0) {
|
486
|
-
tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.1) + 'px';
|
487
|
-
|
488
|
-
// RIGHT edge
|
489
|
-
} else if (canvasXY[0] + mouseXY[0] + (width / 2) > doc.body.offsetWidth) {
|
490
|
-
tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.9) + 'px';
|
491
|
-
|
492
|
-
// Default positioning - CENTERED
|
493
|
-
} else {
|
494
|
-
tooltip.style.left = canvasXY[0] + mouseXY[0] - (width / 2) + 'px';
|
495
|
-
}
|
496
|
-
};
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
/**
|
502
|
-
* Each object type has its own Highlight() function which highlights the appropriate shape
|
503
|
-
*
|
504
|
-
* @param object shape The shape to highlight
|
505
|
-
*/
|
506
|
-
this.highlight =
|
507
|
-
this.Highlight = function (shape)
|
508
|
-
{
|
509
|
-
if (typeof prop['chart.highlight.style'] === 'function') {
|
510
|
-
(prop['chart.highlight.style'])(shape);
|
511
|
-
} else {
|
512
|
-
RG.Highlight.Rect(this, shape);
|
513
|
-
}
|
514
|
-
};
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
/**
|
520
|
-
* This allows for easy specification of gradients
|
521
|
-
*/
|
522
|
-
this.parseColors = function ()
|
523
|
-
{
|
524
|
-
// Save the original colors so that they can be restored when the canvas is reset
|
525
|
-
if (this.original_colors.length === 0) {
|
526
|
-
this.original_colors['chart.colors'] = RG.array_clone(prop['chart.colors'])[0];
|
527
|
-
this.original_colors['chart.fillstyle'] = RG.array_clone(prop['chart.fillstyle']);
|
528
|
-
this.original_colors['chart.strokestyle'] = RG.array_clone(prop['chart.strokestyle']);
|
529
|
-
this.original_colors['chart.highlight.stroke'] = RG.array_clone(prop['chart.highlight.stroke']);
|
530
|
-
this.original_colors['chart.highlight.fill'] = RG.array_clone(prop['chart.highlight.fill']);
|
531
|
-
}
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
/**
|
537
|
-
* Parse various properties for colors
|
538
|
-
*/
|
539
|
-
prop['chart.colors'][0] = this.parseSingleColorForGradient(prop['chart.colors'][0]);
|
540
|
-
prop['chart.fillstyle'] = this.parseSingleColorForGradient(prop['chart.fillstyle']);
|
541
|
-
prop['chart.strokestyle'] = this.parseSingleColorForGradient(prop['chart.strokestyle']);
|
542
|
-
prop['chart.highlight.stroke'] = this.parseSingleColorForGradient(prop['chart.highlight.stroke']);
|
543
|
-
prop['chart.highlight.fill'] = this.parseSingleColorForGradient(prop['chart.highlight.fill']);
|
544
|
-
};
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
/**
|
550
|
-
* Use this function to reset the object to the post-constructor state. Eg reset colors if
|
551
|
-
* need be etc
|
552
|
-
*/
|
553
|
-
this.reset = function ()
|
554
|
-
{
|
555
|
-
};
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
/**
|
561
|
-
* This parses a single color value
|
562
|
-
*/
|
563
|
-
this.parseSingleColorForGradient = function (color)
|
564
|
-
{
|
565
|
-
if (!color) {
|
566
|
-
return color;
|
567
|
-
}
|
568
|
-
|
569
|
-
if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
|
570
|
-
|
571
|
-
var parts = RegExp.$1.split(':');
|
572
|
-
|
573
|
-
// Create the gradient
|
574
|
-
var grad = co.createLinearGradient(0,0,ca.width,0);
|
575
|
-
|
576
|
-
var diff = 1 / (parts.length - 1);
|
577
|
-
|
578
|
-
grad.addColorStop(0, RGraph.trim(parts[0]));
|
579
|
-
|
580
|
-
for (var j=1,len=parts.length; j<len; ++j) {
|
581
|
-
grad.addColorStop(j * diff, RG.trim(parts[j]));
|
582
|
-
}
|
583
|
-
}
|
584
|
-
|
585
|
-
return grad ? grad : color;
|
586
|
-
};
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
/**
|
592
|
-
* Using a function to add events makes it easier to facilitate method chaining
|
593
|
-
*
|
594
|
-
* @param string type The type of even to add
|
595
|
-
* @param function func
|
596
|
-
*/
|
597
|
-
this.on = function (type, func)
|
598
|
-
{
|
599
|
-
if (type.substr(0,2) !== 'on') {
|
600
|
-
type = 'on' + type;
|
601
|
-
}
|
602
|
-
|
603
|
-
this[type] = func;
|
604
|
-
|
605
|
-
return this;
|
606
|
-
};
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
/**
|
612
|
-
* This function runs once only
|
613
|
-
* (put at the end of the file (before any effects))
|
614
|
-
*/
|
615
|
-
this.firstDrawFunc = function ()
|
616
|
-
{
|
617
|
-
};
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
RG.att(ca);
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
/**
|
629
|
-
* Objects are now always registered so that the chart is redrawn if need be.
|
630
|
-
*/
|
631
|
-
RG.Register(this);
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
/**
|
637
|
-
* This is the 'end' of the constructor so if the first argument
|
638
|
-
* contains configuration data - handle that.
|
639
|
-
*/
|
640
|
-
if (parseConfObjectForOptions) {
|
641
|
-
RG.parseObjectStyleConfig(this, conf.options);
|
642
|
-
}
|
643
|
-
};
|
2
|
+
RGraph=window.RGraph||{isRGraph:true};RGraph.Drawing=RGraph.Drawing||{};RGraph.Drawing.Text=function(conf)
|
3
|
+
{if(typeof conf==='object'&&typeof conf.x==='number'&&typeof conf.y==='number'&&typeof conf.id==='string'){var id=conf.id
|
4
|
+
var x=conf.x;var y=conf.y;var text=String(conf.text);var parseConfObjectForOptions=true;}else{var id=conf;var x=arguments[1];var y=arguments[2];var text=arguments[3];}
|
5
|
+
this.id=id;this.canvas=document.getElementById(id);this.context=this.canvas.getContext('2d');this.colorsParsed=false;this.canvas.__object__=this;this.x=x;this.y=y;this.text=String(text);this.coords=[];this.coordsText=[];this.original_colors=[];this.firstDraw=true;this.type='drawing.text';this.isRGraph=true;this.uid=RGraph.CreateUID();this.canvas.uid=this.canvas.uid?this.canvas.uid:RGraph.CreateUID();this.properties={'chart.size':10,'chart.font':'Segoe UI, Arial, Verdana, sans-serif','chart.bold':false,'chart.angle':0,'chart.colors':['black'],'chart.events.click':null,'chart.events.mousemove':null,'chart.highlight.stroke':'#ccc','chart.highlight.fill':'rgba(255,255,255,0.7)','chart.tooltips':null,'chart.tooltips.effect':'fade','chart.tooltips.css.class':'RGraph_tooltip','chart.tooltips.event':'onclick','chart.tooltips.highlight':true,'chart.tooltips.coords.page':false,'chart.bounding':false,'chart.bounding.fill':'rgba(255,255,255,0.7)','chart.bounding.stroke':'#777','chart.bounding.shadow':false,'chart.bounding.shadow.color':'#ccc','chart.bounding.shadow.blur':3,'chart.bounding.shadow.offsetx':3,'chart.bounding.shadow.offsety':3,'chart.marker':false,'chart.halign':'left','chart.valign':'bottom','chart.link':null,'chart.link.target':'_self','chart.link.options':'','chart.text.accessible':true,'chart.text.accessible.overflow':'visible','chart.text.accessible.pointerevents':true,'chart.clearto':'rgba(0,0,0,0)'}
|
6
|
+
if(!this.canvas){alert('[DRAWING.TEXT] 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');if(!this.colorsParsed){this.parseColors();this.colorsParsed=true;}
|
19
|
+
this.coords=[];this.coordsText=[];var dimensions=RG.MeasureText(this.text,prop['chart.text.bold'],prop['chart.text.font'],prop['chart.text.size']);co.fillStyle=prop['chart.colors'][0];var ret=RG.text2(this,{font:prop['chart.font'],size:prop['chart.size'],x:this.x,y:this.y,text:this.text,bold:prop['chart.bold'],angle:prop['chart.angle'],bounding:prop['chart.bounding'],'bounding.fill':prop['chart.bounding.fill'],'bounding.stroke':prop['chart.bounding.stroke'],'bounding.shadow':prop['chart.bounding.shadow'],'bounding.shadow.color':prop['chart.bounding.shadow.color'],'bounding.shadow.blur':prop['chart.bounding.shadow.blur'],'bounding.shadow.offsetx':prop['chart.bounding.shadow.offsetx'],'bounding.shadow.offsety':prop['chart.bounding.shadow.offsety'],marker:prop['chart.marker'],halign:prop['chart.halign'],valign:prop['chart.valign']});this.coords.push({0:ret.x,'x':ret.x,1:ret.y,'y':ret.y,2:ret.width,'width':ret.width,3:ret.height,'height':ret.height});RG.InstallEventListeners(this);if(this.firstDraw){RG.fireCustomEvent(this,'onfirstdraw');this.firstDraw=false;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 prop=this.properties;var coords=this.coords;var mouseXY=RGraph.getMouseXY(e);var mouseX=mouseXY[0];var mouseY=mouseXY[1];for(var i=0,len=this.coords.length;i<len;i++){var left=coords[i].x;var top=coords[i].y;var width=coords[i].width;var height=coords[i].height;if(mouseX>=left&&mouseX<=(left+width)&&mouseY>=top&&mouseY<=(top+height)){return{0:this,1:left,2:top,3:width,4:height,5:0,'object':this,'x':left,'y':top,'width':width,'height':height,'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);}else{RG.Highlight.Rect(this,shape);}};this.parseColors=function()
|
26
|
+
{if(this.original_colors.length===0){this.original_colors['chart.colors']=RG.array_clone(prop['chart.colors'])[0];this.original_colors['chart.fillstyle']=RG.array_clone(prop['chart.fillstyle']);this.original_colors['chart.strokestyle']=RG.array_clone(prop['chart.strokestyle']);this.original_colors['chart.highlight.stroke']=RG.array_clone(prop['chart.highlight.stroke']);this.original_colors['chart.highlight.fill']=RG.array_clone(prop['chart.highlight.fill']);}
|
27
|
+
prop['chart.colors'][0]=this.parseSingleColorForGradient(prop['chart.colors'][0]);prop['chart.fillstyle']=this.parseSingleColorForGradient(prop['chart.fillstyle']);prop['chart.strokestyle']=this.parseSingleColorForGradient(prop['chart.strokestyle']);prop['chart.highlight.stroke']=this.parseSingleColorForGradient(prop['chart.highlight.stroke']);prop['chart.highlight.fill']=this.parseSingleColorForGradient(prop['chart.highlight.fill']);};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,0,ca.width,0);var diff=1/(parts.length-1);grad.addColorStop(0,RGraph.trim(parts[0]));for(var j=1,len=parts.length;j<len;++j){grad.addColorStop(j*diff,RG.trim(parts[j]));}}
|
31
|
+
return grad?grad:color;};this.on=function(type,func)
|
32
|
+
{if(type.substr(0,2)!=='on'){type='on'+type;}
|
33
|
+
if(typeof this[type]!=='function'){this[type]=func;}else{RG.addCustomEventListener(this,type,func);}
|
34
|
+
return this;};this.firstDrawFunc=function()
|
35
|
+
{};RG.att(ca);RG.Register(this);if(parseConfObjectForOptions){RG.parseObjectStyleConfig(this,conf.options);}};
|