jquery_cheats 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/README.md +19 -2
  2. data/app/assets/javascripts/jqueryCheats.js +36 -1
  3. data/jquery_cheats.gemspec +2 -2
  4. data/lib/jquery_cheats.rb +4 -0
  5. data/vendor/assets/excanvas.js +1438 -0
  6. data/vendor/assets/jquery.jqplot.css +259 -0
  7. data/vendor/assets/jquery.jqplot.js +10901 -0
  8. data/vendor/assets/plugins/jqplot.BezierCurveRenderer.js +312 -0
  9. data/vendor/assets/plugins/jqplot.BezierCurveRenderer.min.js +57 -0
  10. data/vendor/assets/plugins/jqplot.barRenderer.js +747 -0
  11. data/vendor/assets/plugins/jqplot.barRenderer.min.js +57 -0
  12. data/vendor/assets/plugins/jqplot.blockRenderer.js +234 -0
  13. data/vendor/assets/plugins/jqplot.blockRenderer.min.js +57 -0
  14. data/vendor/assets/plugins/jqplot.bubbleRenderer.js +754 -0
  15. data/vendor/assets/plugins/jqplot.bubbleRenderer.min.js +57 -0
  16. data/vendor/assets/plugins/jqplot.canvasAxisLabelRenderer.js +202 -0
  17. data/vendor/assets/plugins/jqplot.canvasAxisLabelRenderer.min.js +57 -0
  18. data/vendor/assets/plugins/jqplot.canvasAxisTickRenderer.js +242 -0
  19. data/vendor/assets/plugins/jqplot.canvasAxisTickRenderer.min.js +57 -0
  20. data/vendor/assets/plugins/jqplot.canvasOverlay.js +864 -0
  21. data/vendor/assets/plugins/jqplot.canvasOverlay.min.js +57 -0
  22. data/vendor/assets/plugins/jqplot.canvasTextRenderer.js +448 -0
  23. data/vendor/assets/plugins/jqplot.canvasTextRenderer.min.js +57 -0
  24. data/vendor/assets/plugins/jqplot.categoryAxisRenderer.js +636 -0
  25. data/vendor/assets/plugins/jqplot.categoryAxisRenderer.min.js +57 -0
  26. data/vendor/assets/plugins/jqplot.ciParser.js +115 -0
  27. data/vendor/assets/plugins/jqplot.ciParser.min.js +57 -0
  28. data/vendor/assets/plugins/jqplot.cursor.js +1093 -0
  29. data/vendor/assets/plugins/jqplot.cursor.min.js +57 -0
  30. data/vendor/assets/plugins/jqplot.dateAxisRenderer.js +702 -0
  31. data/vendor/assets/plugins/jqplot.dateAxisRenderer.min.js +57 -0
  32. data/vendor/assets/plugins/jqplot.donutRenderer.js +800 -0
  33. data/vendor/assets/plugins/jqplot.donutRenderer.min.js +57 -0
  34. data/vendor/assets/plugins/jqplot.dragable.js +224 -0
  35. data/vendor/assets/plugins/jqplot.dragable.min.js +57 -0
  36. data/vendor/assets/plugins/jqplot.enhancedLegendRenderer.js +241 -0
  37. data/vendor/assets/plugins/jqplot.enhancedLegendRenderer.min.js +57 -0
  38. data/vendor/assets/plugins/jqplot.funnelRenderer.js +938 -0
  39. data/vendor/assets/plugins/jqplot.funnelRenderer.min.js +57 -0
  40. data/vendor/assets/plugins/jqplot.highlighter.js +454 -0
  41. data/vendor/assets/plugins/jqplot.highlighter.min.js +57 -0
  42. data/vendor/assets/plugins/jqplot.json2.js +475 -0
  43. data/vendor/assets/plugins/jqplot.json2.min.js +57 -0
  44. data/vendor/assets/plugins/jqplot.logAxisRenderer.js +528 -0
  45. data/vendor/assets/plugins/jqplot.logAxisRenderer.min.js +57 -0
  46. data/vendor/assets/plugins/jqplot.mekkoAxisRenderer.js +610 -0
  47. data/vendor/assets/plugins/jqplot.mekkoAxisRenderer.min.js +57 -0
  48. data/vendor/assets/plugins/jqplot.mekkoRenderer.js +436 -0
  49. data/vendor/assets/plugins/jqplot.mekkoRenderer.min.js +57 -0
  50. data/vendor/assets/plugins/jqplot.meterGaugeRenderer.js +1029 -0
  51. data/vendor/assets/plugins/jqplot.meterGaugeRenderer.min.js +57 -0
  52. data/vendor/assets/plugins/jqplot.ohlcRenderer.js +372 -0
  53. data/vendor/assets/plugins/jqplot.ohlcRenderer.min.js +57 -0
  54. data/vendor/assets/plugins/jqplot.pieRenderer.js +899 -0
  55. data/vendor/assets/plugins/jqplot.pieRenderer.min.js +57 -0
  56. data/vendor/assets/plugins/jqplot.pointLabels.js +362 -0
  57. data/vendor/assets/plugins/jqplot.pointLabels.min.js +57 -0
  58. data/vendor/assets/plugins/jqplot.pyramidAxisRenderer.js +730 -0
  59. data/vendor/assets/plugins/jqplot.pyramidAxisRenderer.min.js +57 -0
  60. data/vendor/assets/plugins/jqplot.pyramidGridRenderer.js +423 -0
  61. data/vendor/assets/plugins/jqplot.pyramidGridRenderer.min.js +57 -0
  62. data/vendor/assets/plugins/jqplot.pyramidRenderer.js +490 -0
  63. data/vendor/assets/plugins/jqplot.pyramidRenderer.min.js +57 -0
  64. data/vendor/assets/plugins/jqplot.trendline.js +222 -0
  65. data/vendor/assets/plugins/jqplot.trendline.min.js +57 -0
  66. metadata +64 -3
@@ -0,0 +1,754 @@
1
+ /**
2
+ * jqPlot
3
+ * Pure JavaScript plotting plugin using jQuery
4
+ *
5
+ * Version: 1.0.0b2_r1012
6
+ *
7
+ * Copyright (c) 2009-2011 Chris Leonello
8
+ * jqPlot is currently available for use in all personal or commercial projects
9
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
+ * choose the license that best suits your project and use it accordingly.
12
+ *
13
+ * Although not required, the author would appreciate an email letting him
14
+ * know of any substantial use of jqPlot. You can reach the author at:
15
+ * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
+ *
17
+ * If you are feeling kind and generous, consider supporting the project by
18
+ * making a donation at: http://www.jqplot.com/donate.php .
19
+ *
20
+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
+ *
22
+ * version 2007.04.27
23
+ * author Ash Searle
24
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
25
+ * http://hexmen.com/js/sprintf.js
26
+ * The author (Ash Searle) has placed this code in the public domain:
27
+ * "This code is unrestricted: you are free to use it however you like."
28
+ *
29
+ */
30
+ (function($) {
31
+ var arrayMax = function( array ){
32
+ return Math.max.apply( Math, array );
33
+ };
34
+ var arrayMin = function( array ){
35
+ return Math.min.apply( Math, array );
36
+ };
37
+
38
+ /**
39
+ * Class: $.jqplot.BubbleRenderer
40
+ * Plugin renderer to draw a bubble chart. A Bubble chart has data points displayed as
41
+ * colored circles with an optional text label inside. To use
42
+ * the bubble renderer, you must include the bubble renderer like:
43
+ *
44
+ * > <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.bubbleRenderer.js"></script>
45
+ *
46
+ * Data must be supplied in
47
+ * the form:
48
+ *
49
+ * > [[x1, y1, r1, <label or {label:'text', color:color}>], ...]
50
+ *
51
+ * where the label or options
52
+ * object is optional.
53
+ *
54
+ * Note that all bubble colors will be the same
55
+ * unless the "varyBubbleColors" option is set to true. Colors can be specified in the data array
56
+ * or in the seriesColors array option on the series. If no colors are defined, the default jqPlot
57
+ * series of 16 colors are used. Colors are automatically cycled around again if there are more
58
+ * bubbles than colors.
59
+ *
60
+ * Bubbles are autoscaled by default to fit within the chart area while maintaining
61
+ * relative sizes. If the "autoscaleBubbles" option is set to false, the r(adius) values
62
+ * in the data array a treated as literal pixel values for the radii of the bubbles.
63
+ *
64
+ * Properties are passed into the bubble renderer in the rendererOptions object of
65
+ * the series options like:
66
+ *
67
+ * > seriesDefaults: {
68
+ * > renderer: $.jqplot.BubbleRenderer,
69
+ * > rendererOptions: {
70
+ * > bubbleAlpha: 0.7,
71
+ * > varyBubbleColors: false
72
+ * > }
73
+ * > }
74
+ *
75
+ */
76
+ $.jqplot.BubbleRenderer = function(){
77
+ $.jqplot.LineRenderer.call(this);
78
+ };
79
+
80
+ $.jqplot.BubbleRenderer.prototype = new $.jqplot.LineRenderer();
81
+ $.jqplot.BubbleRenderer.prototype.constructor = $.jqplot.BubbleRenderer;
82
+
83
+ // called with scope of a series
84
+ $.jqplot.BubbleRenderer.prototype.init = function(options, plot) {
85
+ // Group: Properties
86
+ //
87
+ // prop: varyBubbleColors
88
+ // True to vary the color of each bubble in this series according to
89
+ // the seriesColors array. False to set each bubble to the color
90
+ // specified on this series. This has no effect if a css background color
91
+ // option is specified in the renderer css options.
92
+ this.varyBubbleColors = true;
93
+ // prop: autoscaleBubbles
94
+ // True to scale the bubble radius based on plot size.
95
+ // False will use the radius value as provided as a raw pixel value for
96
+ // bubble radius.
97
+ this.autoscaleBubbles = true;
98
+ // prop: autoscaleMultiplier
99
+ // Multiplier the bubble size if autoscaleBubbles is true.
100
+ this.autoscaleMultiplier = 1.0;
101
+ // prop: autoscalePointsFactor
102
+ // Factor which decreases bubble size based on how many bubbles on on the chart.
103
+ // 0 means no adjustment for number of bubbles. Negative values will decrease
104
+ // size of bubbles as more bubbles are added. Values between 0 and -0.2
105
+ // should work well.
106
+ this.autoscalePointsFactor = -0.07;
107
+ // prop: escapeHtml
108
+ // True to escape html in bubble label text.
109
+ this.escapeHtml = true;
110
+ // prop: highlightMouseOver
111
+ // True to highlight bubbles when moused over.
112
+ // This must be false to enable highlightMouseDown to highlight when clicking on a slice.
113
+ this.highlightMouseOver = true;
114
+ // prop: highlightMouseDown
115
+ // True to highlight when a mouse button is pressed over a bubble.
116
+ // This will be disabled if highlightMouseOver is true.
117
+ this.highlightMouseDown = false;
118
+ // prop: highlightColors
119
+ // An array of colors to use when highlighting a slice. Calculated automatically
120
+ // if not supplied.
121
+ this.highlightColors = [];
122
+ // prop: bubbleAlpha
123
+ // Alpha transparency to apply to all bubbles in this series.
124
+ this.bubbleAlpha = 1.0;
125
+ // prop: highlightAlpha
126
+ // Alpha transparency to apply when highlighting bubble.
127
+ // Set to value of bubbleAlpha by default.
128
+ this.highlightAlpha = null;
129
+ // prop: bubbleGradients
130
+ // True to color the bubbles with gradient fills instead of flat colors.
131
+ // NOT AVAILABLE IN IE due to lack of excanvas support for radial gradient fills.
132
+ // will be ignored in IE.
133
+ this.bubbleGradients = false;
134
+ // prop: showLabels
135
+ // True to show labels on bubbles (if any), false to not show.
136
+ this.showLabels = true;
137
+ // array of [point index, radius] which will be sorted in descending order to plot
138
+ // largest points below smaller points.
139
+ this.radii = [];
140
+ this.maxRadius = 0;
141
+ // index of the currenty highlighted point, if any
142
+ this._highlightedPoint = null;
143
+ // array of jQuery labels.
144
+ this.labels = [];
145
+ this.bubbleCanvases = [];
146
+ this._type = 'bubble';
147
+
148
+ // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
149
+ if (options.highlightMouseDown && options.highlightMouseOver == null) {
150
+ options.highlightMouseOver = false;
151
+ }
152
+
153
+ $.extend(true, this, options);
154
+
155
+ if (this.highlightAlpha == null) {
156
+ this.highlightAlpha = this.bubbleAlpha;
157
+ if (this.bubbleGradients) {
158
+ this.highlightAlpha = 0.35;
159
+ }
160
+ }
161
+
162
+ this.autoscaleMultiplier = this.autoscaleMultiplier * Math.pow(this.data.length, this.autoscalePointsFactor);
163
+
164
+ // index of the currenty highlighted point, if any
165
+ this._highlightedPoint = null;
166
+
167
+ // adjust the series colors for options colors passed in with data or for alpha.
168
+ // note, this can leave undefined holes in the seriesColors array.
169
+ var comps;
170
+ for (var i=0; i<this.data.length; i++) {
171
+ var color = null;
172
+ var d = this.data[i];
173
+ this.maxRadius = Math.max(this.maxRadius, d[2]);
174
+ if (d[3]) {
175
+ if (typeof(d[3]) == 'object') {
176
+ color = d[3]['color'];
177
+ }
178
+ }
179
+
180
+ if (color == null) {
181
+ if (this.seriesColors[i] != null) {
182
+ color = this.seriesColors[i];
183
+ }
184
+ }
185
+
186
+ if (color && this.bubbleAlpha < 1.0) {
187
+ comps = $.jqplot.getColorComponents(color);
188
+ color = 'rgba('+comps[0]+', '+comps[1]+', '+comps[2]+', '+this.bubbleAlpha+')';
189
+ }
190
+
191
+ if (color) {
192
+ this.seriesColors[i] = color;
193
+ }
194
+ }
195
+
196
+ if (!this.varyBubbleColors) {
197
+ this.seriesColors = [this.color];
198
+ }
199
+
200
+ this.colorGenerator = new $.jqplot.ColorGenerator(this.seriesColors);
201
+
202
+ // set highlight colors if none provided
203
+ if (this.highlightColors.length == 0) {
204
+ for (var i=0; i<this.seriesColors.length; i++){
205
+ var rgba = $.jqplot.getColorComponents(this.seriesColors[i]);
206
+ var newrgb = [rgba[0], rgba[1], rgba[2]];
207
+ var sum = newrgb[0] + newrgb[1] + newrgb[2];
208
+ for (var j=0; j<3; j++) {
209
+ // when darkening, lowest color component can be is 60.
210
+ newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
211
+ newrgb[j] = parseInt(newrgb[j], 10);
212
+ }
213
+ this.highlightColors.push('rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+', '+this.highlightAlpha+')');
214
+ }
215
+ }
216
+
217
+ this.highlightColorGenerator = new $.jqplot.ColorGenerator(this.highlightColors);
218
+
219
+ var sopts = {fill:true, isarc:true, angle:this.shadowAngle, alpha:this.shadowAlpha, closePath:true};
220
+
221
+ this.renderer.shadowRenderer.init(sopts);
222
+
223
+ this.canvas = new $.jqplot.DivCanvas();
224
+ this.canvas._plotDimensions = this._plotDimensions;
225
+
226
+ plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
227
+ plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
228
+ plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
229
+ plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
230
+ plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
231
+ plot.postDrawHooks.addOnce(postPlotDraw);
232
+
233
+ };
234
+
235
+
236
+ // converts the user data values to grid coordinates and stores them
237
+ // in the gridData array.
238
+ // Called with scope of a series.
239
+ $.jqplot.BubbleRenderer.prototype.setGridData = function(plot) {
240
+ // recalculate the grid data
241
+ var xp = this._xaxis.series_u2p;
242
+ var yp = this._yaxis.series_u2p;
243
+ var data = this._plotData;
244
+ this.gridData = [];
245
+ var radii = [];
246
+ this.radii = [];
247
+ var dim = Math.min(plot._height, plot._width);
248
+ for (var i=0; i<this.data.length; i++) {
249
+ if (data[i] != null) {
250
+ this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1]), data[i][2]]);
251
+ this.radii.push([i, data[i][2]]);
252
+ radii.push(data[i][2]);
253
+ }
254
+ }
255
+ var r, val, maxr = this.maxRadius = arrayMax(radii);
256
+ var l = this.gridData.length;
257
+ if (this.autoscaleBubbles) {
258
+ for (var i=0; i<l; i++) {
259
+ val = radii[i]/maxr;
260
+ r = this.autoscaleMultiplier * dim / 6;
261
+ this.gridData[i][2] = r * val;
262
+ }
263
+ }
264
+
265
+ this.radii.sort(function(a, b) { return b[1] - a[1]; });
266
+ };
267
+
268
+ // converts any arbitrary data values to grid coordinates and
269
+ // returns them. This method exists so that plugins can use a series'
270
+ // linerenderer to generate grid data points without overwriting the
271
+ // grid data associated with that series.
272
+ // Called with scope of a series.
273
+ $.jqplot.BubbleRenderer.prototype.makeGridData = function(data, plot) {
274
+ // recalculate the grid data
275
+ var xp = this._xaxis.series_u2p;
276
+ var yp = this._yaxis.series_u2p;
277
+ var gd = [];
278
+ var radii = [];
279
+ this.radii = [];
280
+ var dim = Math.min(plot._height, plot._width);
281
+ for (var i=0; i<data.length; i++) {
282
+ if (data[i] != null) {
283
+ gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1]), data[i][2]]);
284
+ radii.push(data[i][2]);
285
+ this.radii.push([i, data[i][2]]);
286
+ }
287
+ }
288
+ var r, val, maxr = this.maxRadius = arrayMax(radii);
289
+ var l = this.gridData.length;
290
+ if (this.autoscaleBubbles) {
291
+ for (var i=0; i<l; i++) {
292
+ val = radii[i]/maxr;
293
+ r = this.autoscaleMultiplier * dim / 6;
294
+ gd[i][2] = r * val;
295
+ }
296
+ }
297
+ this.radii.sort(function(a, b) { return b[1] - a[1]; });
298
+ return gd;
299
+ };
300
+
301
+ // called with scope of series
302
+ $.jqplot.BubbleRenderer.prototype.draw = function (ctx, gd, options) {
303
+ if (this.plugins.pointLabels) {
304
+ this.plugins.pointLabels.show = false;
305
+ }
306
+ var opts = (options != undefined) ? options : {};
307
+ var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
308
+ this.canvas._elem.empty();
309
+ for (var i=0; i<this.radii.length; i++) {
310
+ var idx = this.radii[i][0];
311
+ var t=null;
312
+ var color = null;
313
+ var el = null;
314
+ var tel = null;
315
+ var d = this.data[idx];
316
+ var gd = this.gridData[idx];
317
+ if (d[3]) {
318
+ if (typeof(d[3]) == 'object') {
319
+ t = d[3]['label'];
320
+ }
321
+ else if (typeof(d[3]) == 'string') {
322
+ t = d[3];
323
+ }
324
+ }
325
+
326
+ // color = (this.varyBubbleColors) ? this.colorGenerator.get(idx) : this.color;
327
+ color = this.colorGenerator.get(idx);
328
+
329
+ // If we're drawing a shadow, expand the canvas dimensions to accomodate.
330
+ var canvasRadius = gd[2];
331
+ var offset, depth;
332
+ if (this.shadow) {
333
+ offset = (0.7 + gd[2]/40).toFixed(1);
334
+ depth = 1 + Math.ceil(gd[2]/15);
335
+ canvasRadius += offset*depth;
336
+ }
337
+ this.bubbleCanvases[idx] = new $.jqplot.BubbleCanvas();
338
+ this.canvas._elem.append(this.bubbleCanvases[idx].createElement(gd[0], gd[1], canvasRadius));
339
+ this.bubbleCanvases[idx].setContext();
340
+ var ctx = this.bubbleCanvases[idx]._ctx;
341
+ var x = ctx.canvas.width/2;
342
+ var y = ctx.canvas.height/2;
343
+ if (this.shadow) {
344
+ this.renderer.shadowRenderer.draw(ctx, [x, y, gd[2], 0, 2*Math.PI], {offset: offset, depth: depth});
345
+ }
346
+ this.bubbleCanvases[idx].draw(gd[2], color, this.bubbleGradients, this.shadowAngle/180*Math.PI);
347
+
348
+ // now draw label.
349
+ if (t && this.showLabels) {
350
+ tel = $('<div style="position:absolute;" class="jqplot-bubble-label"></div>');
351
+ if (this.escapeHtml) {
352
+ tel.text(t);
353
+ }
354
+ else {
355
+ tel.html(t);
356
+ }
357
+ this.canvas._elem.append(tel);
358
+ var h = $(tel).outerHeight();
359
+ var w = $(tel).outerWidth();
360
+ var top = gd[1] - 0.5*h;
361
+ var left = gd[0] - 0.5*w;
362
+ tel.css({top: top, left: left});
363
+ this.labels[idx] = $(tel);
364
+ }
365
+ }
366
+ };
367
+
368
+
369
+ $.jqplot.DivCanvas = function() {
370
+ $.jqplot.ElemContainer.call(this);
371
+ this._ctx;
372
+ };
373
+
374
+ $.jqplot.DivCanvas.prototype = new $.jqplot.ElemContainer();
375
+ $.jqplot.DivCanvas.prototype.constructor = $.jqplot.DivCanvas;
376
+
377
+ $.jqplot.DivCanvas.prototype.createElement = function(offsets, clss, plotDimensions) {
378
+ this._offsets = offsets;
379
+ var klass = 'jqplot-DivCanvas';
380
+ if (clss != undefined) {
381
+ klass = clss;
382
+ }
383
+ var elem;
384
+ // if this canvas already has a dom element, don't make a new one.
385
+ if (this._elem) {
386
+ elem = this._elem.get(0);
387
+ }
388
+ else {
389
+ elem = document.createElement('div');
390
+ }
391
+ // if new plotDimensions supplied, use them.
392
+ if (plotDimensions != undefined) {
393
+ this._plotDimensions = plotDimensions;
394
+ }
395
+
396
+ var w = this._plotDimensions.width - this._offsets.left - this._offsets.right + 'px';
397
+ var h = this._plotDimensions.height - this._offsets.top - this._offsets.bottom + 'px';
398
+ this._elem = $(elem);
399
+ this._elem.css({ position: 'absolute', width:w, height:h, left: this._offsets.left, top: this._offsets.top });
400
+
401
+ this._elem.addClass(klass);
402
+ return this._elem;
403
+ };
404
+
405
+ $.jqplot.DivCanvas.prototype.setContext = function() {
406
+ this._ctx = {
407
+ canvas:{
408
+ width:0,
409
+ height:0
410
+ },
411
+ clearRect:function(){return null;}
412
+ };
413
+ return this._ctx;
414
+ };
415
+
416
+ $.jqplot.BubbleCanvas = function() {
417
+ $.jqplot.ElemContainer.call(this);
418
+ this._ctx;
419
+ };
420
+
421
+ $.jqplot.BubbleCanvas.prototype = new $.jqplot.ElemContainer();
422
+ $.jqplot.BubbleCanvas.prototype.constructor = $.jqplot.BubbleCanvas;
423
+
424
+ // initialize with the x,y pont of bubble center and the bubble radius.
425
+ $.jqplot.BubbleCanvas.prototype.createElement = function(x, y, r) {
426
+ var klass = 'jqplot-bubble-point';
427
+
428
+ var elem;
429
+ // if this canvas already has a dom element, don't make a new one.
430
+ if (this._elem) {
431
+ elem = this._elem.get(0);
432
+ }
433
+ else {
434
+ elem = document.createElement('canvas');
435
+ }
436
+
437
+ elem.width = (r != null) ? 2*r : elem.width;
438
+ elem.height = (r != null) ? 2*r : elem.height;
439
+ this._elem = $(elem);
440
+ var l = (x != null && r != null) ? x - r : this._elem.css('left');
441
+ var t = (y != null && r != null) ? y - r : this._elem.css('top');
442
+ this._elem.css({ position: 'absolute', left: l, top: t });
443
+
444
+ this._elem.addClass(klass);
445
+ if ($.jqplot.use_excanvas) {
446
+ window.G_vmlCanvasManager.init_(document);
447
+ elem = window.G_vmlCanvasManager.initElement(elem);
448
+ }
449
+
450
+ return this._elem;
451
+ };
452
+
453
+ $.jqplot.BubbleCanvas.prototype.draw = function(r, color, gradients, angle) {
454
+ var ctx = this._ctx;
455
+ // r = Math.floor(r*1.04);
456
+ // var x = Math.round(ctx.canvas.width/2);
457
+ // var y = Math.round(ctx.canvas.height/2);
458
+ var x = ctx.canvas.width/2;
459
+ var y = ctx.canvas.height/2;
460
+ ctx.save();
461
+ if (gradients && !$.jqplot.use_excanvas) {
462
+ r = r*1.04;
463
+ var comps = $.jqplot.getColorComponents(color);
464
+ var colorinner = 'rgba('+Math.round(comps[0]+0.8*(255-comps[0]))+', '+Math.round(comps[1]+0.8*(255-comps[1]))+', '+Math.round(comps[2]+0.8*(255-comps[2]))+', '+comps[3]+')';
465
+ var colorend = 'rgba('+comps[0]+', '+comps[1]+', '+comps[2]+', 0)';
466
+ // var rinner = Math.round(0.35 * r);
467
+ // var xinner = Math.round(x - Math.cos(angle) * 0.33 * r);
468
+ // var yinner = Math.round(y - Math.sin(angle) * 0.33 * r);
469
+ var rinner = 0.35 * r;
470
+ var xinner = x - Math.cos(angle) * 0.33 * r;
471
+ var yinner = y - Math.sin(angle) * 0.33 * r;
472
+ var radgrad = ctx.createRadialGradient(xinner, yinner, rinner, x, y, r);
473
+ radgrad.addColorStop(0, colorinner);
474
+ radgrad.addColorStop(0.93, color);
475
+ radgrad.addColorStop(0.96, colorend);
476
+ radgrad.addColorStop(1, colorend);
477
+ // radgrad.addColorStop(.98, colorend);
478
+ ctx.fillStyle = radgrad;
479
+ ctx.fillRect(0,0, ctx.canvas.width, ctx.canvas.height);
480
+ }
481
+ else {
482
+ ctx.fillStyle = color;
483
+ ctx.strokeStyle = color;
484
+ ctx.lineWidth = 1;
485
+ ctx.beginPath();
486
+ var ang = 2*Math.PI;
487
+ ctx.arc(x, y, r, 0, ang, 0);
488
+ ctx.closePath();
489
+ ctx.fill();
490
+ }
491
+ ctx.restore();
492
+ };
493
+
494
+ $.jqplot.BubbleCanvas.prototype.setContext = function() {
495
+ this._ctx = this._elem.get(0).getContext("2d");
496
+ return this._ctx;
497
+ };
498
+
499
+ $.jqplot.BubbleAxisRenderer = function() {
500
+ $.jqplot.LinearAxisRenderer.call(this);
501
+ };
502
+
503
+ $.jqplot.BubbleAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
504
+ $.jqplot.BubbleAxisRenderer.prototype.constructor = $.jqplot.BubbleAxisRenderer;
505
+
506
+ // called with scope of axis object.
507
+ $.jqplot.BubbleAxisRenderer.prototype.init = function(options){
508
+ $.extend(true, this, options);
509
+ var db = this._dataBounds;
510
+ var minsidx = 0,
511
+ minpidx = 0,
512
+ maxsidx = 0,
513
+ maxpidx = 0,
514
+ maxr = 0,
515
+ minr = 0,
516
+ minMaxRadius = 0,
517
+ maxMaxRadius = 0,
518
+ maxMult = 0,
519
+ minMult = 0;
520
+ // Go through all the series attached to this axis and find
521
+ // the min/max bounds for this axis.
522
+ for (var i=0; i<this._series.length; i++) {
523
+ var s = this._series[i];
524
+ var d = s._plotData;
525
+
526
+ for (var j=0; j<d.length; j++) {
527
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
528
+ if (d[j][0] < db.min || db.min == null) {
529
+ db.min = d[j][0];
530
+ minsidx=i;
531
+ minpidx=j;
532
+ minr = d[j][2];
533
+ minMaxRadius = s.maxRadius;
534
+ minMult = s.autoscaleMultiplier;
535
+ }
536
+ if (d[j][0] > db.max || db.max == null) {
537
+ db.max = d[j][0];
538
+ maxsidx=i;
539
+ maxpidx=j;
540
+ maxr = d[j][2];
541
+ maxMaxRadius = s.maxRadius;
542
+ maxMult = s.autoscaleMultiplier;
543
+ }
544
+ }
545
+ else {
546
+ if (d[j][1] < db.min || db.min == null) {
547
+ db.min = d[j][1];
548
+ minsidx=i;
549
+ minpidx=j;
550
+ minr = d[j][2];
551
+ minMaxRadius = s.maxRadius;
552
+ minMult = s.autoscaleMultiplier;
553
+ }
554
+ if (d[j][1] > db.max || db.max == null) {
555
+ db.max = d[j][1];
556
+ maxsidx=i;
557
+ maxpidx=j;
558
+ maxr = d[j][2];
559
+ maxMaxRadius = s.maxRadius;
560
+ maxMult = s.autoscaleMultiplier;
561
+ }
562
+ }
563
+ }
564
+ }
565
+
566
+ var minRatio = minr/minMaxRadius;
567
+ var maxRatio = maxr/maxMaxRadius;
568
+
569
+ // need to estimate the effect of the radius on total axis span and adjust axis accordingly.
570
+ var span = db.max - db.min;
571
+ // var dim = (this.name == 'xaxis' || this.name == 'x2axis') ? this._plotDimensions.width : this._plotDimensions.height;
572
+ var dim = Math.min(this._plotDimensions.width, this._plotDimensions.height);
573
+
574
+ var minfact = minRatio * minMult/3 * span;
575
+ var maxfact = maxRatio * maxMult/3 * span;
576
+ db.max += maxfact;
577
+ db.min -= minfact;
578
+ };
579
+
580
+ function highlight (plot, sidx, pidx) {
581
+ plot.plugins.bubbleRenderer.highlightLabelCanvas.empty();
582
+ var s = plot.series[sidx];
583
+ var canvas = plot.plugins.bubbleRenderer.highlightCanvas;
584
+ var ctx = canvas._ctx;
585
+ ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
586
+ s._highlightedPoint = pidx;
587
+ plot.plugins.bubbleRenderer.highlightedSeriesIndex = sidx;
588
+
589
+ var color = s.highlightColorGenerator.get(pidx);
590
+ var x = s.gridData[pidx][0],
591
+ y = s.gridData[pidx][1],
592
+ r = s.gridData[pidx][2];
593
+ ctx.save();
594
+ ctx.fillStyle = color;
595
+ ctx.strokeStyle = color;
596
+ ctx.lineWidth = 1;
597
+ ctx.beginPath();
598
+ ctx.arc(x, y, r, 0, 2*Math.PI, 0);
599
+ ctx.closePath();
600
+ ctx.fill();
601
+ ctx.restore();
602
+ // bring label to front
603
+ if (s.labels[pidx]) {
604
+ plot.plugins.bubbleRenderer.highlightLabel = s.labels[pidx].clone();
605
+ plot.plugins.bubbleRenderer.highlightLabel.appendTo(plot.plugins.bubbleRenderer.highlightLabelCanvas);
606
+ plot.plugins.bubbleRenderer.highlightLabel.addClass('jqplot-bubble-label-highlight');
607
+ }
608
+ }
609
+
610
+ function unhighlight (plot) {
611
+ var canvas = plot.plugins.bubbleRenderer.highlightCanvas;
612
+ var sidx = plot.plugins.bubbleRenderer.highlightedSeriesIndex;
613
+ plot.plugins.bubbleRenderer.highlightLabelCanvas.empty();
614
+ canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
615
+ for (var i=0; i<plot.series.length; i++) {
616
+ plot.series[i]._highlightedPoint = null;
617
+ }
618
+ plot.plugins.bubbleRenderer.highlightedSeriesIndex = null;
619
+ plot.target.trigger('jqplotDataUnhighlight');
620
+ }
621
+
622
+
623
+ function handleMove(ev, gridpos, datapos, neighbor, plot) {
624
+ if (neighbor) {
625
+ var si = neighbor.seriesIndex;
626
+ var pi = neighbor.pointIndex;
627
+ var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
628
+ var evt1 = jQuery.Event('jqplotDataMouseOver');
629
+ evt1.pageX = ev.pageX;
630
+ evt1.pageY = ev.pageY;
631
+ plot.target.trigger(evt1, ins);
632
+ if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.bubbleRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
633
+ var evt = jQuery.Event('jqplotDataHighlight');
634
+ evt.pageX = ev.pageX;
635
+ evt.pageY = ev.pageY;
636
+ plot.target.trigger(evt, ins);
637
+ highlight (plot, ins[0], ins[1]);
638
+ }
639
+ }
640
+ else if (neighbor == null) {
641
+ unhighlight (plot);
642
+ }
643
+ }
644
+
645
+ function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
646
+ if (neighbor) {
647
+ var si = neighbor.seriesIndex;
648
+ var pi = neighbor.pointIndex;
649
+ var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
650
+ if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.bubbleRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
651
+ var evt = jQuery.Event('jqplotDataHighlight');
652
+ evt.pageX = ev.pageX;
653
+ evt.pageY = ev.pageY;
654
+ plot.target.trigger(evt, ins);
655
+ highlight (plot, ins[0], ins[1]);
656
+ }
657
+ }
658
+ else if (neighbor == null) {
659
+ unhighlight (plot);
660
+ }
661
+ }
662
+
663
+ function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
664
+ var idx = plot.plugins.bubbleRenderer.highlightedSeriesIndex;
665
+ if (idx != null && plot.series[idx].highlightMouseDown) {
666
+ unhighlight(plot);
667
+ }
668
+ }
669
+
670
+ function handleClick(ev, gridpos, datapos, neighbor, plot) {
671
+ if (neighbor) {
672
+ var si = neighbor.seriesIndex;
673
+ var pi = neighbor.pointIndex;
674
+ var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
675
+ var evt = jQuery.Event('jqplotDataClick');
676
+ evt.pageX = ev.pageX;
677
+ evt.pageY = ev.pageY;
678
+ plot.target.trigger(evt, ins);
679
+ }
680
+ }
681
+
682
+ function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
683
+ if (neighbor) {
684
+ var si = neighbor.seriesIndex;
685
+ var pi = neighbor.pointIndex;
686
+ var ins = [si, pi, neighbor.data, plot.series[si].gridData[pi][2]];
687
+ var idx = plot.plugins.bubbleRenderer.highlightedSeriesIndex;
688
+ if (idx != null && plot.series[idx].highlightMouseDown) {
689
+ unhighlight(plot);
690
+ }
691
+ var evt = jQuery.Event('jqplotDataRightClick');
692
+ evt.pageX = ev.pageX;
693
+ evt.pageY = ev.pageY;
694
+ plot.target.trigger(evt, ins);
695
+ }
696
+ }
697
+
698
+ // called within context of plot
699
+ // create a canvas which we can draw on.
700
+ // insert it before the eventCanvas, so eventCanvas will still capture events.
701
+ function postPlotDraw() {
702
+ // Memory Leaks patch
703
+ if (this.plugins.bubbleRenderer && this.plugins.bubbleRenderer.highlightCanvas) {
704
+ this.plugins.bubbleRenderer.highlightCanvas.resetCanvas();
705
+ this.plugins.bubbleRenderer.highlightCanvas = null;
706
+ }
707
+
708
+ this.plugins.bubbleRenderer = {highlightedSeriesIndex:null};
709
+ this.plugins.bubbleRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
710
+ this.plugins.bubbleRenderer.highlightLabel = null;
711
+ this.plugins.bubbleRenderer.highlightLabelCanvas = $('<div style="position:absolute;"></div>');
712
+ var top = this._gridPadding.top;
713
+ var left = this._gridPadding.left;
714
+ var width = this._plotDimensions.width - this._gridPadding.left - this._gridPadding.right;
715
+ var height = this._plotDimensions.height - this._gridPadding.top - this._gridPadding.bottom;
716
+ this.plugins.bubbleRenderer.highlightLabelCanvas.css({top:top, left:left, width:width+'px', height:height+'px'});
717
+
718
+ this.eventCanvas._elem.before(this.plugins.bubbleRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-bubbleRenderer-highlight-canvas', this._plotDimensions, this));
719
+ this.eventCanvas._elem.before(this.plugins.bubbleRenderer.highlightLabelCanvas);
720
+
721
+ var hctx = this.plugins.bubbleRenderer.highlightCanvas.setContext();
722
+ }
723
+
724
+
725
+ // setup default renderers for axes and legend so user doesn't have to
726
+ // called with scope of plot
727
+ function preInit(target, data, options) {
728
+ options = options || {};
729
+ options.axesDefaults = options.axesDefaults || {};
730
+ options.seriesDefaults = options.seriesDefaults || {};
731
+ // only set these if there is a Bubble series
732
+ var setopts = false;
733
+ if (options.seriesDefaults.renderer == $.jqplot.BubbleRenderer) {
734
+ setopts = true;
735
+ }
736
+ else if (options.series) {
737
+ for (var i=0; i < options.series.length; i++) {
738
+ if (options.series[i].renderer == $.jqplot.BubbleRenderer) {
739
+ setopts = true;
740
+ }
741
+ }
742
+ }
743
+
744
+ if (setopts) {
745
+ options.axesDefaults.renderer = $.jqplot.BubbleAxisRenderer;
746
+ options.sortData = false;
747
+ }
748
+ }
749
+
750
+ $.jqplot.preInitHooks.push(preInit);
751
+
752
+ })(jQuery);
753
+
754
+