jqplot-rails 0.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/lib/jqplot-rails.rb +6 -4
  2. data/lib/jqplot-rails/railtie.rb +9 -0
  3. data/lib/jqplot-rails/view_helpers.rb +11 -0
  4. data/vendor/assets/javascripts/jqplot/excanvas.js +1438 -0
  5. data/vendor/assets/javascripts/jqplot/index.js +66 -0
  6. data/vendor/assets/javascripts/{jqplot.1.0.0b2_r792.js → jqplot/jquery.jqplot.js} +3458 -793
  7. data/vendor/assets/javascripts/jqplot/plugins/BezierCurveRenderer.js +313 -0
  8. data/vendor/assets/javascripts/jqplot/plugins/barRenderer.js +797 -0
  9. data/vendor/assets/javascripts/jqplot/plugins/blockRenderer.js +235 -0
  10. data/vendor/assets/javascripts/jqplot/plugins/bubbleRenderer.js +759 -0
  11. data/vendor/assets/javascripts/jqplot/plugins/canvasAxisLabelRenderer.js +203 -0
  12. data/vendor/assets/javascripts/jqplot/plugins/canvasAxisTickRenderer.js +243 -0
  13. data/vendor/assets/javascripts/jqplot/plugins/canvasOverlay.js +865 -0
  14. data/vendor/assets/javascripts/jqplot/plugins/canvasTextRenderer.js +449 -0
  15. data/vendor/assets/javascripts/jqplot/plugins/categoryAxisRenderer.js +673 -0
  16. data/vendor/assets/javascripts/jqplot/plugins/ciParser.js +116 -0
  17. data/vendor/assets/javascripts/jqplot/plugins/cursor.js +1108 -0
  18. data/vendor/assets/javascripts/jqplot/plugins/dateAxisRenderer.js +737 -0
  19. data/vendor/assets/javascripts/jqplot/plugins/donutRenderer.js +805 -0
  20. data/vendor/assets/javascripts/jqplot/plugins/dragable.js +225 -0
  21. data/vendor/assets/javascripts/jqplot/plugins/enhancedLegendRenderer.js +305 -0
  22. data/vendor/assets/javascripts/jqplot/plugins/funnelRenderer.js +943 -0
  23. data/vendor/assets/javascripts/jqplot/plugins/highlighter.js +465 -0
  24. data/vendor/assets/javascripts/jqplot/plugins/json2.js +475 -0
  25. data/vendor/assets/javascripts/jqplot/plugins/logAxisRenderer.js +529 -0
  26. data/vendor/assets/javascripts/jqplot/plugins/mekkoAxisRenderer.js +611 -0
  27. data/vendor/assets/javascripts/jqplot/plugins/mekkoRenderer.js +437 -0
  28. data/vendor/assets/javascripts/jqplot/plugins/meterGaugeRenderer.js +1030 -0
  29. data/vendor/assets/javascripts/jqplot/plugins/mobile.js +45 -0
  30. data/vendor/assets/javascripts/jqplot/plugins/ohlcRenderer.js +373 -0
  31. data/vendor/assets/javascripts/jqplot/plugins/pieRenderer.js +904 -0
  32. data/vendor/assets/javascripts/jqplot/plugins/pointLabels.js +379 -0
  33. data/vendor/assets/javascripts/jqplot/plugins/pyramidAxisRenderer.js +728 -0
  34. data/vendor/assets/javascripts/jqplot/plugins/pyramidGridRenderer.js +429 -0
  35. data/vendor/assets/javascripts/jqplot/plugins/pyramidRenderer.js +514 -0
  36. data/vendor/assets/javascripts/jqplot/plugins/trendline.js +223 -0
  37. data/vendor/assets/stylesheets/{jqplot.1.0.0b2_r792.css → jqplot.css} +48 -15
  38. metadata +64 -25
@@ -0,0 +1,429 @@
1
+ /**
2
+ * jqPlot
3
+ * Pure JavaScript plotting plugin using jQuery
4
+ *
5
+ * Version: 1.0.5
6
+ * Revision: 1122+
7
+ *
8
+ * Copyright (c) 2009-2013 Chris Leonello
9
+ * jqPlot is currently available for use in all personal or commercial projects
10
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
11
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
12
+ * choose the license that best suits your project and use it accordingly.
13
+ *
14
+ * Although not required, the author would appreciate an email letting him
15
+ * know of any substantial use of jqPlot. You can reach the author at:
16
+ * chris at jqplot dot com or see http://www.jqplot.com/info.php .
17
+ *
18
+ * If you are feeling kind and generous, consider supporting the project by
19
+ * making a donation at: http://www.jqplot.com/donate.php .
20
+ *
21
+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
22
+ *
23
+ * version 2007.04.27
24
+ * author Ash Searle
25
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
26
+ * http://hexmen.com/js/sprintf.js
27
+ * The author (Ash Searle) has placed this code in the public domain:
28
+ * "This code is unrestricted: you are free to use it however you like."
29
+ *
30
+ */
31
+ (function($) {
32
+ // Class: $.jqplot.CanvasGridRenderer
33
+ // The default jqPlot grid renderer, creating a grid on a canvas element.
34
+ // The renderer has no additional options beyond the <Grid> class.
35
+ $.jqplot.PyramidGridRenderer = function(){
36
+ $.jqplot.CanvasGridRenderer.call(this);
37
+ };
38
+
39
+ $.jqplot.PyramidGridRenderer.prototype = new $.jqplot.CanvasGridRenderer();
40
+ $.jqplot.PyramidGridRenderer.prototype.constructor = $.jqplot.PyramidGridRenderer;
41
+
42
+ // called with context of Grid object
43
+ $.jqplot.CanvasGridRenderer.prototype.init = function(options) {
44
+ this._ctx;
45
+ this.plotBands = {
46
+ show: false,
47
+ color: 'rgb(230, 219, 179)',
48
+ axis: 'y',
49
+ start: null,
50
+ interval: 10
51
+ };
52
+ $.extend(true, this, options);
53
+ // set the shadow renderer options
54
+ var sopts = {lineJoin:'miter', lineCap:'round', fill:false, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.shadowWidth, closePath:false, strokeStyle:this.shadowColor};
55
+ this.renderer.shadowRenderer.init(sopts);
56
+ };
57
+
58
+ $.jqplot.PyramidGridRenderer.prototype.draw = function() {
59
+ this._ctx = this._elem.get(0).getContext("2d");
60
+ var ctx = this._ctx;
61
+ var axes = this._axes;
62
+ var xp = axes.xaxis.u2p;
63
+ var yp = axes.yMidAxis.u2p;
64
+ var xnudge = axes.xaxis.max/1000.0;
65
+ var xp0 = xp(0);
66
+ var xpn = xp(xnudge);
67
+ var ax = ['xaxis', 'yaxis', 'x2axis', 'y2axis','yMidAxis'];
68
+ // Add the grid onto the grid canvas. This is the bottom most layer.
69
+ ctx.save();
70
+ ctx.clearRect(0, 0, this._plotDimensions.width, this._plotDimensions.height);
71
+ ctx.fillStyle = this.backgroundColor || this.background;
72
+
73
+ ctx.fillRect(this._left, this._top, this._width, this._height);
74
+
75
+ if (this.plotBands.show) {
76
+ ctx.save();
77
+ var pb = this.plotBands;
78
+ ctx.fillStyle = pb.color;
79
+ var axis;
80
+ var x, y, w, h;
81
+ // find axis to work with
82
+ if (pb.axis.charAt(0) === 'x') {
83
+ if (axes.xaxis.show) {
84
+ axis = axes.xaxis;
85
+ }
86
+ }
87
+ else if (pb.axis.charAt(0) === 'y') {
88
+ if (axes.yaxis.show) {
89
+ axis = axes.yaxis;
90
+ }
91
+ else if (axes.y2axis.show) {
92
+ axis = axes.y2axis;
93
+ }
94
+ else if (axes.yMidAxis.show) {
95
+ axis = axes.yMidAxis;
96
+ }
97
+ }
98
+
99
+ if (axis !== undefined) {
100
+ // draw some rectangles
101
+ var start = pb.start;
102
+ if (start === null) {
103
+ start = axis.min;
104
+ }
105
+ for (var i = start; i < axis.max; i += 2 * pb.interval) {
106
+ if (axis.name.charAt(0) === 'y') {
107
+ x = this._left;
108
+ if ((i + pb.interval) < axis.max) {
109
+ y = axis.series_u2p(i + pb.interval) + this._top;
110
+ }
111
+ else {
112
+ y = axis.series_u2p(axis.max) + this._top;
113
+ }
114
+ w = this._right - this._left;
115
+ h = axis.series_u2p(start) - axis.series_u2p(start + pb.interval);
116
+ ctx.fillRect(x, y, w, h);
117
+ }
118
+ // else {
119
+ // y = 0;
120
+ // x = axis.series_u2p(i);
121
+ // h = this._height;
122
+ // w = axis.series_u2p(start + pb.interval) - axis.series_u2p(start);
123
+ // }
124
+
125
+ }
126
+ }
127
+ ctx.restore();
128
+ }
129
+
130
+ ctx.save();
131
+ ctx.lineJoin = 'miter';
132
+ ctx.lineCap = 'butt';
133
+ ctx.lineWidth = this.gridLineWidth;
134
+ ctx.strokeStyle = this.gridLineColor;
135
+ var b, e, s, m;
136
+ for (var i=5; i>0; i--) {
137
+ var name = ax[i-1];
138
+ var axis = axes[name];
139
+ var ticks = axis._ticks;
140
+ var numticks = ticks.length;
141
+ if (axis.show) {
142
+ if (axis.drawBaseline) {
143
+ var bopts = {};
144
+ if (axis.baselineWidth !== null) {
145
+ bopts.lineWidth = axis.baselineWidth;
146
+ }
147
+ if (axis.baselineColor !== null) {
148
+ bopts.strokeStyle = axis.baselineColor;
149
+ }
150
+ switch (name) {
151
+ case 'xaxis':
152
+ if (axes.yMidAxis.show) {
153
+ drawLine (this._left, this._bottom, xp0, this._bottom, bopts);
154
+ drawLine (xpn, this._bottom, this._right, this._bottom, bopts);
155
+ }
156
+ else {
157
+ drawLine (this._left, this._bottom, this._right, this._bottom, bopts);
158
+ }
159
+ break;
160
+ case 'yaxis':
161
+ drawLine (this._left, this._bottom, this._left, this._top, bopts);
162
+ break;
163
+ case 'yMidAxis':
164
+ drawLine(xp0, this._bottom, xp0, this._top, bopts);
165
+ drawLine(xpn, this._bottom, xpn, this._top, bopts);
166
+ break;
167
+ case 'x2axis':
168
+ if (axes.yMidAxis.show) {
169
+ drawLine (this._left, this._top, xp0, this._top, bopts);
170
+ drawLine (xpn, this._top, this._right, this._top, bopts);
171
+ }
172
+ else {
173
+ drawLine (this._left, this._bottom, this._right, this._bottom, bopts);
174
+ }
175
+ break;
176
+ case 'y2axis':
177
+ drawLine (this._right, this._bottom, this._right, this._top, bopts);
178
+ break;
179
+
180
+ }
181
+ }
182
+ for (var j=numticks; j>0; j--) {
183
+ var t = ticks[j-1];
184
+ if (t.show) {
185
+ var pos = Math.round(axis.u2p(t.value)) + 0.5;
186
+ switch (name) {
187
+ case 'xaxis':
188
+ // draw the grid line if we should
189
+ if (t.showGridline && this.drawGridlines && (!t.isMinorTick || axis.showMinorTicks)) {
190
+ drawLine(pos, this._top, pos, this._bottom);
191
+ }
192
+
193
+ // draw the mark
194
+ if (t.showMark && t.mark && (!t.isMinorTick || axis.showMinorTicks)) {
195
+ s = t.markSize;
196
+ m = t.mark;
197
+ var pos = Math.round(axis.u2p(t.value)) + 0.5;
198
+ switch (m) {
199
+ case 'outside':
200
+ b = this._bottom;
201
+ e = this._bottom+s;
202
+ break;
203
+ case 'inside':
204
+ b = this._bottom-s;
205
+ e = this._bottom;
206
+ break;
207
+ case 'cross':
208
+ b = this._bottom-s;
209
+ e = this._bottom+s;
210
+ break;
211
+ default:
212
+ b = this._bottom;
213
+ e = this._bottom+s;
214
+ break;
215
+ }
216
+ // draw the shadow
217
+ if (this.shadow) {
218
+ this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
219
+ }
220
+ // draw the line
221
+ drawLine(pos, b, pos, e);
222
+ }
223
+ break;
224
+ case 'yaxis':
225
+ // draw the grid line
226
+ if (t.showGridline && this.drawGridlines && (!t.isMinorTick || axis.showMinorTicks)) {
227
+ drawLine(this._right, pos, this._left, pos);
228
+ }
229
+
230
+ // draw the mark
231
+ if (t.showMark && t.mark && (!t.isMinorTick || axis.showMinorTicks)) {
232
+ s = t.markSize;
233
+ m = t.mark;
234
+ var pos = Math.round(axis.u2p(t.value)) + 0.5;
235
+ switch (m) {
236
+ case 'outside':
237
+ b = this._left-s;
238
+ e = this._left;
239
+ break;
240
+ case 'inside':
241
+ b = this._left;
242
+ e = this._left+s;
243
+ break;
244
+ case 'cross':
245
+ b = this._left-s;
246
+ e = this._left+s;
247
+ break;
248
+ default:
249
+ b = this._left-s;
250
+ e = this._left;
251
+ break;
252
+ }
253
+ // draw the shadow
254
+ if (this.shadow) {
255
+ this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
256
+ }
257
+ drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
258
+ }
259
+ break;
260
+ case 'yMidAxis':
261
+ // draw the grid line
262
+ if (t.showGridline && this.drawGridlines && (!t.isMinorTick || axis.showMinorTicks)) {
263
+ drawLine(this._left, pos, xp0, pos);
264
+ drawLine(xpn, pos, this._right, pos);
265
+ }
266
+ // draw the mark
267
+ if (t.showMark && t.mark && (!t.isMinorTick || axis.showMinorTicks)) {
268
+ s = t.markSize;
269
+ m = t.mark;
270
+ var pos = Math.round(axis.u2p(t.value)) + 0.5;
271
+
272
+ b = xp0;
273
+ e = xp0 + s;
274
+ // draw the shadow
275
+ if (this.shadow) {
276
+ this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
277
+ }
278
+ drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
279
+
280
+ b = xpn - s;
281
+ e = xpn;
282
+ // draw the shadow
283
+ if (this.shadow) {
284
+ this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
285
+ }
286
+ drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
287
+ }
288
+ break;
289
+ case 'x2axis':
290
+ // draw the grid line
291
+ if (t.showGridline && this.drawGridlines && (!t.isMinorTick || axis.showMinorTicks)) {
292
+ drawLine(pos, this._bottom, pos, this._top);
293
+ }
294
+
295
+ // draw the mark
296
+ if (t.showMark && t.mark && (!t.isMinorTick || axis.showMinorTicks)) {
297
+ s = t.markSize;
298
+ m = t.mark;
299
+ var pos = Math.round(axis.u2p(t.value)) + 0.5;
300
+ switch (m) {
301
+ case 'outside':
302
+ b = this._top-s;
303
+ e = this._top;
304
+ break;
305
+ case 'inside':
306
+ b = this._top;
307
+ e = this._top+s;
308
+ break;
309
+ case 'cross':
310
+ b = this._top-s;
311
+ e = this._top+s;
312
+ break;
313
+ default:
314
+ b = this._top-s;
315
+ e = this._top;
316
+ break;
317
+ }
318
+ // draw the shadow
319
+ if (this.shadow) {
320
+ this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
321
+ }
322
+ drawLine(pos, b, pos, e);
323
+ }
324
+ break;
325
+ case 'y2axis':
326
+ // draw the grid line
327
+ if (t.showGridline && this.drawGridlines && (!t.isMinorTick || axis.showMinorTicks)) {
328
+ drawLine(this._left, pos, this._right, pos);
329
+ }
330
+
331
+ // draw the mark
332
+ if (t.showMark && t.mark && (!t.isMinorTick || axis.showMinorTicks)) {
333
+ s = t.markSize;
334
+ m = t.mark;
335
+ var pos = Math.round(axis.u2p(t.value)) + 0.5;
336
+ switch (m) {
337
+ case 'outside':
338
+ b = this._right;
339
+ e = this._right+s;
340
+ break;
341
+ case 'inside':
342
+ b = this._right-s;
343
+ e = this._right;
344
+ break;
345
+ case 'cross':
346
+ b = this._right-s;
347
+ e = this._right+s;
348
+ break;
349
+ default:
350
+ b = this._right;
351
+ e = this._right+s;
352
+ break;
353
+ }
354
+ // draw the shadow
355
+ if (this.shadow) {
356
+ this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
357
+ }
358
+ drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
359
+ }
360
+ break;
361
+ default:
362
+ break;
363
+ }
364
+ }
365
+ }
366
+ t = null;
367
+ }
368
+ axis = null;
369
+ ticks = null;
370
+ }
371
+
372
+ ctx.restore();
373
+
374
+ function drawLine(bx, by, ex, ey, opts) {
375
+ ctx.save();
376
+ opts = opts || {};
377
+ if (opts.lineWidth == null || opts.lineWidth != 0){
378
+ $.extend(true, ctx, opts);
379
+ ctx.beginPath();
380
+ ctx.moveTo(bx, by);
381
+ ctx.lineTo(ex, ey);
382
+ ctx.stroke();
383
+ }
384
+ ctx.restore();
385
+ }
386
+
387
+ if (this.shadow) {
388
+ if (axes.yMidAxis.show) {
389
+ var points = [[this._left, this._bottom], [xp0, this._bottom]];
390
+ this.renderer.shadowRenderer.draw(ctx, points);
391
+ var points = [[xpn, this._bottom], [this._right, this._bottom], [this._right, this._top]];
392
+ this.renderer.shadowRenderer.draw(ctx, points);
393
+ var points = [[xp0, this._bottom], [xp0, this._top]];
394
+ this.renderer.shadowRenderer.draw(ctx, points);
395
+ }
396
+ else {
397
+ var points = [[this._left, this._bottom], [this._right, this._bottom], [this._right, this._top]];
398
+ this.renderer.shadowRenderer.draw(ctx, points);
399
+ }
400
+ }
401
+ // Now draw border around grid. Use axis border definitions. start at
402
+ // upper left and go clockwise.
403
+ if (this.borderWidth != 0 && this.drawBorder) {
404
+ if (axes.yMidAxis.show) {
405
+ drawLine (this._left, this._top, xp0, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth});
406
+ drawLine (xpn, this._top, this._right, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth});
407
+ drawLine (this._right, this._top, this._right, this._bottom, {lineCap:'round', strokeStyle:axes.y2axis.borderColor, lineWidth:axes.y2axis.borderWidth});
408
+ drawLine (this._right, this._bottom, xpn, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth});
409
+ drawLine (xp0, this._bottom, this._left, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth});
410
+ drawLine (this._left, this._bottom, this._left, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
411
+ drawLine (xp0, this._bottom, xp0, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
412
+ drawLine (xpn, this._bottom, xpn, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
413
+ }
414
+ else {
415
+ drawLine (this._left, this._top, this._right, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth});
416
+ drawLine (this._right, this._top, this._right, this._bottom, {lineCap:'round', strokeStyle:axes.y2axis.borderColor, lineWidth:axes.y2axis.borderWidth});
417
+ drawLine (this._right, this._bottom, this._left, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth});
418
+ drawLine (this._left, this._bottom, this._left, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
419
+ }
420
+ }
421
+ // ctx.lineWidth = this.borderWidth;
422
+ // ctx.strokeStyle = this.borderColor;
423
+ // ctx.strokeRect(this._left, this._top, this._width, this._height);
424
+
425
+ ctx.restore();
426
+ ctx = null;
427
+ axes = null;
428
+ };
429
+ })(jQuery);
@@ -0,0 +1,514 @@
1
+ /**
2
+ * jqPlot
3
+ * Pure JavaScript plotting plugin using jQuery
4
+ *
5
+ * Version: 1.0.5
6
+ * Revision: 1122+
7
+ *
8
+ * Copyright (c) 2009-2013 Chris Leonello
9
+ * jqPlot is currently available for use in all personal or commercial projects
10
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
11
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
12
+ * choose the license that best suits your project and use it accordingly.
13
+ *
14
+ * Although not required, the author would appreciate an email letting him
15
+ * know of any substantial use of jqPlot. You can reach the author at:
16
+ * chris at jqplot dot com or see http://www.jqplot.com/info.php .
17
+ *
18
+ * If you are feeling kind and generous, consider supporting the project by
19
+ * making a donation at: http://www.jqplot.com/donate.php .
20
+ *
21
+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
22
+ *
23
+ * version 2007.04.27
24
+ * author Ash Searle
25
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
26
+ * http://hexmen.com/js/sprintf.js
27
+ * The author (Ash Searle) has placed this code in the public domain:
28
+ * "This code is unrestricted: you are free to use it however you like."
29
+ *
30
+ */
31
+ (function($) {
32
+
33
+ // Need to ensure pyramid axis and grid renderers are loaded.
34
+ // You should load these with script tags in the html head, that is more efficient
35
+ // as the browser will cache the request.
36
+ // Note, have to block with synchronous request in order to execute bar renderer code.
37
+ if ($.jqplot.PyramidAxisRenderer === undefined) {
38
+ $.ajax({
39
+ url: $.jqplot.pluginLocation + 'jqplot.pyramidAxisRenderer.js',
40
+ dataType: "script",
41
+ async: false
42
+ });
43
+ }
44
+
45
+ if ($.jqplot.PyramidGridRenderer === undefined) {
46
+ $.ajax({
47
+ url: $.jqplot.pluginLocation + 'jqplot.pyramidGridRenderer.js',
48
+ dataType: "script",
49
+ async: false
50
+ });
51
+ }
52
+
53
+ $.jqplot.PyramidRenderer = function(){
54
+ $.jqplot.LineRenderer.call(this);
55
+ };
56
+
57
+ $.jqplot.PyramidRenderer.prototype = new $.jqplot.LineRenderer();
58
+ $.jqplot.PyramidRenderer.prototype.constructor = $.jqplot.PyramidRenderer;
59
+
60
+ // called with scope of a series
61
+ $.jqplot.PyramidRenderer.prototype.init = function(options, plot) {
62
+ options = options || {};
63
+ this._type = 'pyramid';
64
+ // Group: Properties
65
+ //
66
+ // prop: barPadding
67
+ this.barPadding = 10;
68
+ this.barWidth = null;
69
+ // prop: fill
70
+ // True to fill the bars.
71
+ this.fill = true;
72
+ // prop: highlightMouseOver
73
+ // True to highlight slice when moused over.
74
+ // This must be false to enable highlightMouseDown to highlight when clicking on a slice.
75
+ this.highlightMouseOver = true;
76
+ // prop: highlightMouseDown
77
+ // True to highlight when a mouse button is pressed over a slice.
78
+ // This will be disabled if highlightMouseOver is true.
79
+ this.highlightMouseDown = false;
80
+ // prop: highlightColors
81
+ // an array of colors to use when highlighting a slice.
82
+ this.highlightColors = [];
83
+ // prop highlightThreshold
84
+ // Expand the highlightable region in the x direction.
85
+ // E.g. a value of 3 will highlight a bar when the mouse is
86
+ // within 3 pixels of the bar in the x direction.
87
+ this.highlightThreshold = 2;
88
+ // prop: synchronizeHighlight
89
+ // Index of another series to highlight when this series is highlighted.
90
+ // null or false to not synchronize.
91
+ this.synchronizeHighlight = false;
92
+ // prop: offsetBars
93
+ // False will center bars on their y value.
94
+ // True will push bars up by 1/2 bar width to fill between their y values.
95
+ // If true, there needs to be 1 more tick than there are bars.
96
+ this.offsetBars = false;
97
+
98
+ // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
99
+ if (options.highlightMouseDown && options.highlightMouseOver == null) {
100
+ options.highlightMouseOver = false;
101
+ }
102
+
103
+ this.side = 'right';
104
+
105
+ $.extend(true, this, options);
106
+
107
+ // if (this.fill === false) {
108
+ // this.shadow = false;
109
+ // }
110
+
111
+ if (this.side === 'left') {
112
+ this._highlightThreshold = [[-this.highlightThreshold, 0], [-this.highlightThreshold, 0], [0,0], [0,0]];
113
+ }
114
+
115
+ else {
116
+ this._highlightThreshold = [[0,0], [0,0], [this.highlightThreshold, 0], [this.highlightThreshold, 0]];
117
+ }
118
+
119
+ this.renderer.options = options;
120
+ // index of the currenty highlighted point, if any
121
+ this._highlightedPoint = null;
122
+ // Array of actual data colors used for each data point.
123
+ this._dataColors = [];
124
+ this._barPoints = [];
125
+ this.fillAxis = 'y';
126
+ this._primaryAxis = '_yaxis';
127
+ this._xnudge = 0;
128
+
129
+ // set the shape renderer options
130
+ var opts = {lineJoin:'miter', lineCap:'butt', fill:this.fill, fillRect:this.fill, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill, lineWidth: this.lineWidth};
131
+ this.renderer.shapeRenderer.init(opts);
132
+ // set the shadow renderer options
133
+ var shadow_offset = options.shadowOffset;
134
+ // set the shadow renderer options
135
+ if (shadow_offset == null) {
136
+ // scale the shadowOffset to the width of the line.
137
+ if (this.lineWidth > 2.5) {
138
+ shadow_offset = 1.25 * (1 + (Math.atan((this.lineWidth/2.5))/0.785398163 - 1)*0.6);
139
+ // var shadow_offset = this.shadowOffset;
140
+ }
141
+ // for skinny lines, don't make such a big shadow.
142
+ else {
143
+ shadow_offset = 1.25 * Math.atan((this.lineWidth/2.5))/0.785398163;
144
+ }
145
+ }
146
+ var sopts = {lineJoin:'miter', lineCap:'butt', fill:this.fill, fillRect:this.fill, isarc:false, angle:this.shadowAngle, offset:shadow_offset, alpha:this.shadowAlpha, depth:this.shadowDepth, closePath:this.fill, lineWidth: this.lineWidth};
147
+ this.renderer.shadowRenderer.init(sopts);
148
+
149
+ plot.postDrawHooks.addOnce(postPlotDraw);
150
+ plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
151
+
152
+ // if this is the left side of pyramid, set y values to negative.
153
+ if (this.side === 'left') {
154
+ for (var i=0, l=this.data.length; i<l; i++) {
155
+ this.data[i][1] = -Math.abs(this.data[i][1]);
156
+ }
157
+ }
158
+ };
159
+
160
+ // setGridData
161
+ // converts the user data values to grid coordinates and stores them
162
+ // in the gridData array.
163
+ // Called with scope of a series.
164
+ $.jqplot.PyramidRenderer.prototype.setGridData = function(plot) {
165
+ // recalculate the grid data
166
+ var xp = this._xaxis.series_u2p;
167
+ var yp = this._yaxis.series_u2p;
168
+ var data = this._plotData;
169
+ var pdata = this._prevPlotData;
170
+ this.gridData = [];
171
+ this._prevGridData = [];
172
+ var l = data.length;
173
+ var adjust = false;
174
+ var i;
175
+
176
+ // if any data values are < 0, consider this a negative series
177
+ for (i = 0; i < l; i++) {
178
+ if (data[i][1] < 0) {
179
+ this.side = 'left';
180
+ }
181
+ }
182
+
183
+ if (this._yaxis.name === 'yMidAxis' && this.side === 'right') {
184
+ this._xnudge = this._xaxis.max/2000.0;
185
+ adjust = true;
186
+ }
187
+
188
+ for (i = 0; i < l; i++) {
189
+ // if not a line series or if no nulls in data, push the converted point onto the array.
190
+ if (data[i][0] != null && data[i][1] != null) {
191
+ this.gridData.push([xp(data[i][1]), yp(data[i][0])]);
192
+ }
193
+ // else if there is a null, preserve it.
194
+ else if (data[i][0] == null) {
195
+ this.gridData.push([xp(data[i][1]), null]);
196
+ }
197
+ else if (data[i][1] == null) {
198
+ this.gridData.push(null, [yp(data[i][0])]);
199
+ }
200
+ // finally, adjust x grid data if have to
201
+ if (data[i][1] === 0 && adjust) {
202
+ this.gridData[i][0] = xp(this._xnudge);
203
+ }
204
+ }
205
+ };
206
+
207
+ // makeGridData
208
+ // converts any arbitrary data values to grid coordinates and
209
+ // returns them. This method exists so that plugins can use a series'
210
+ // linerenderer to generate grid data points without overwriting the
211
+ // grid data associated with that series.
212
+ // Called with scope of a series.
213
+ $.jqplot.PyramidRenderer.prototype.makeGridData = function(data, plot) {
214
+ // recalculate the grid data
215
+ var xp = this._xaxis.series_u2p;
216
+ var yp = this._yaxis.series_u2p;
217
+ var gd = [];
218
+ var l = data.length;
219
+ var adjust = false;
220
+ var i;
221
+
222
+ // if any data values are < 0, consider this a negative series
223
+ for (i = 0; i < l; i++) {
224
+ if (data[i][1] < 0) {
225
+ this.side = 'left';
226
+ }
227
+ }
228
+
229
+ if (this._yaxis.name === 'yMidAxis' && this.side === 'right') {
230
+ this._xnudge = this._xaxis.max/2000.0;
231
+ adjust = true;
232
+ }
233
+
234
+ for (i = 0; i < l; i++) {
235
+ // if not a line series or if no nulls in data, push the converted point onto the array.
236
+ if (data[i][0] != null && data[i][1] != null) {
237
+ gd.push([xp(data[i][1]), yp(data[i][0])]);
238
+ }
239
+ // else if there is a null, preserve it.
240
+ else if (data[i][0] == null) {
241
+ gd.push([xp(data[i][1]), null]);
242
+ }
243
+ else if (data[i][1] == null) {
244
+ gd.push([null, yp(data[i][0])]);
245
+ }
246
+ // finally, adjust x grid data if have to
247
+ if (data[i][1] === 0 && adjust) {
248
+ gd[i][0] = xp(this._xnudge);
249
+ }
250
+ }
251
+
252
+ return gd;
253
+ };
254
+
255
+ $.jqplot.PyramidRenderer.prototype.setBarWidth = function() {
256
+ // need to know how many data values we have on the approprate axis and figure it out.
257
+ var i;
258
+ var nvals = 0;
259
+ var nseries = 0;
260
+ var paxis = this[this._primaryAxis];
261
+ var s, series, pos;
262
+ nvals = paxis.max - paxis.min;
263
+ var nticks = paxis.numberTicks;
264
+ var nbins = (nticks-1)/2;
265
+ // so, now we have total number of axis values.
266
+ var temp = (this.barPadding === 0) ? 1.0 : 0;
267
+ if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
268
+ this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding + temp;
269
+ }
270
+ else {
271
+ if (this.fill) {
272
+ this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding + temp;
273
+ }
274
+ else {
275
+ this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals;
276
+ }
277
+ }
278
+ };
279
+
280
+ $.jqplot.PyramidRenderer.prototype.draw = function(ctx, gridData, options) {
281
+ var i;
282
+ // Ughhh, have to make a copy of options b/c it may be modified later.
283
+ var opts = $.extend({}, options);
284
+ var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
285
+ var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
286
+ var fill = (opts.fill != undefined) ? opts.fill : this.fill;
287
+ var xp = this._xaxis.series_u2p;
288
+ var yp = this._yaxis.series_u2p;
289
+ var pointx, pointy;
290
+ // clear out data colors.
291
+ this._dataColors = [];
292
+ this._barPoints = [];
293
+
294
+ if (this.renderer.options.barWidth == null) {
295
+ this.renderer.setBarWidth.call(this);
296
+ }
297
+
298
+ // var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
299
+ // var nvals = temp[0];
300
+ // var nseries = temp[1];
301
+ // var pos = temp[2];
302
+ var points = [],
303
+ w,
304
+ h;
305
+
306
+ // this._barNudge = 0;
307
+
308
+ if (showLine) {
309
+ var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
310
+ var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors);
311
+ var negativeColor = negativeColors.get(this.index);
312
+ if (! this.useNegativeColors) {
313
+ negativeColor = opts.fillStyle;
314
+ }
315
+ var positiveColor = opts.fillStyle;
316
+ var base;
317
+ var xstart = this._xaxis.series_u2p(this._xnudge);
318
+ var ystart = this._yaxis.series_u2p(this._yaxis.min);
319
+ var yend = this._yaxis.series_u2p(this._yaxis.max);
320
+ var bw = this.barWidth;
321
+ var bw2 = bw/2.0;
322
+ var points = [];
323
+ var yadj = this.offsetBars ? bw2 : 0;
324
+
325
+ for (var i=0, l=gridData.length; i<l; i++) {
326
+ if (this.data[i][0] == null) {
327
+ continue;
328
+ }
329
+ base = gridData[i][1];
330
+ // not stacked and first series in stack
331
+
332
+ if (this._plotData[i][1] < 0) {
333
+ if (this.varyBarColor && !this._stack) {
334
+ if (this.useNegativeColors) {
335
+ opts.fillStyle = negativeColors.next();
336
+ }
337
+ else {
338
+ opts.fillStyle = positiveColors.next();
339
+ }
340
+ }
341
+ }
342
+ else {
343
+ if (this.varyBarColor && !this._stack) {
344
+ opts.fillStyle = positiveColors.next();
345
+ }
346
+ else {
347
+ opts.fillStyle = positiveColor;
348
+ }
349
+ }
350
+
351
+ if (this.fill) {
352
+
353
+ if (this._plotData[i][1] >= 0) {
354
+ // xstart = this._xaxis.series_u2p(this._xnudge);
355
+ w = gridData[i][0] - xstart;
356
+ h = this.barWidth;
357
+ points = [xstart, base - bw2 - yadj, w, h];
358
+ }
359
+ else {
360
+ // xstart = this._xaxis.series_u2p(0);
361
+ w = xstart - gridData[i][0];
362
+ h = this.barWidth;
363
+ points = [gridData[i][0], base - bw2 - yadj, w, h];
364
+ }
365
+
366
+ this._barPoints.push([[points[0], points[1] + h], [points[0], points[1]], [points[0] + w, points[1]], [points[0] + w, points[1] + h]]);
367
+
368
+ if (shadow) {
369
+ this.renderer.shadowRenderer.draw(ctx, points);
370
+ }
371
+ var clr = opts.fillStyle || this.color;
372
+ this._dataColors.push(clr);
373
+ this.renderer.shapeRenderer.draw(ctx, points, opts);
374
+ }
375
+
376
+ else {
377
+ if (i === 0) {
378
+ points =[[xstart, ystart], [gridData[i][0], ystart], [gridData[i][0], gridData[i][1] - bw2 - yadj]];
379
+ }
380
+
381
+ else if (i < l-1) {
382
+ points = points.concat([[gridData[i-1][0], gridData[i-1][1] - bw2 - yadj], [gridData[i][0], gridData[i][1] + bw2 - yadj], [gridData[i][0], gridData[i][1] - bw2 - yadj]]);
383
+ }
384
+
385
+ // finally, draw the line
386
+ else {
387
+ points = points.concat([[gridData[i-1][0], gridData[i-1][1] - bw2 - yadj], [gridData[i][0], gridData[i][1] + bw2 - yadj], [gridData[i][0], yend], [xstart, yend]]);
388
+
389
+ if (shadow) {
390
+ this.renderer.shadowRenderer.draw(ctx, points);
391
+ }
392
+ var clr = opts.fillStyle || this.color;
393
+ this._dataColors.push(clr);
394
+ this.renderer.shapeRenderer.draw(ctx, points, opts);
395
+ }
396
+ }
397
+ }
398
+ }
399
+
400
+ if (this.highlightColors.length == 0) {
401
+ this.highlightColors = $.jqplot.computeHighlightColors(this._dataColors);
402
+ }
403
+
404
+ else if (typeof(this.highlightColors) == 'string') {
405
+ this.highlightColors = [];
406
+ for (var i=0; i<this._dataColors.length; i++) {
407
+ this.highlightColors.push(this.highlightColors);
408
+ }
409
+ }
410
+
411
+ };
412
+
413
+
414
+ // setup default renderers for axes and legend so user doesn't have to
415
+ // called with scope of plot
416
+ function preInit(target, data, options) {
417
+ options = options || {};
418
+ options.axesDefaults = options.axesDefaults || {};
419
+ options.grid = options.grid || {};
420
+ options.legend = options.legend || {};
421
+ options.seriesDefaults = options.seriesDefaults || {};
422
+ // only set these if there is a pie series
423
+ var setopts = false;
424
+ if (options.seriesDefaults.renderer === $.jqplot.PyramidRenderer) {
425
+ setopts = true;
426
+ }
427
+ else if (options.series) {
428
+ for (var i=0; i < options.series.length; i++) {
429
+ if (options.series[i].renderer === $.jqplot.PyramidRenderer) {
430
+ setopts = true;
431
+ }
432
+ }
433
+ }
434
+
435
+ if (setopts) {
436
+ options.axesDefaults.renderer = $.jqplot.PyramidAxisRenderer;
437
+ options.grid.renderer = $.jqplot.PyramidGridRenderer;
438
+ options.seriesDefaults.pointLabels = {show: false};
439
+ }
440
+ }
441
+
442
+ // called within context of plot
443
+ // create a canvas which we can draw on.
444
+ // insert it before the eventCanvas, so eventCanvas will still capture events.
445
+ function postPlotDraw() {
446
+ // Memory Leaks patch
447
+ if (this.plugins.pyramidRenderer && this.plugins.pyramidRenderer.highlightCanvas) {
448
+
449
+ this.plugins.pyramidRenderer.highlightCanvas.resetCanvas();
450
+ this.plugins.pyramidRenderer.highlightCanvas = null;
451
+ }
452
+
453
+ this.plugins.pyramidRenderer = {highlightedSeriesIndex:null};
454
+ this.plugins.pyramidRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
455
+
456
+ this.eventCanvas._elem.before(this.plugins.pyramidRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-pyramidRenderer-highlight-canvas', this._plotDimensions, this));
457
+ this.plugins.pyramidRenderer.highlightCanvas.setContext();
458
+ this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
459
+ }
460
+
461
+ function highlight (plot, sidx, pidx, points) {
462
+ var s = plot.series[sidx];
463
+ var canvas = plot.plugins.pyramidRenderer.highlightCanvas;
464
+ canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
465
+ s._highlightedPoint = pidx;
466
+ plot.plugins.pyramidRenderer.highlightedSeriesIndex = sidx;
467
+ var opts = {fillStyle: s.highlightColors[pidx], fillRect: false};
468
+ s.renderer.shapeRenderer.draw(canvas._ctx, points, opts);
469
+ if (s.synchronizeHighlight !== false && plot.series.length >= s.synchronizeHighlight && s.synchronizeHighlight !== sidx) {
470
+ s = plot.series[s.synchronizeHighlight];
471
+ opts = {fillStyle: s.highlightColors[pidx], fillRect: false};
472
+ s.renderer.shapeRenderer.draw(canvas._ctx, s._barPoints[pidx], opts);
473
+ }
474
+ canvas = null;
475
+ }
476
+
477
+ function unhighlight (plot) {
478
+ var canvas = plot.plugins.pyramidRenderer.highlightCanvas;
479
+ canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
480
+ for (var i=0; i<plot.series.length; i++) {
481
+ plot.series[i]._highlightedPoint = null;
482
+ }
483
+ plot.plugins.pyramidRenderer.highlightedSeriesIndex = null;
484
+ plot.target.trigger('jqplotDataUnhighlight');
485
+ canvas = null;
486
+ }
487
+
488
+
489
+ function handleMove(ev, gridpos, datapos, neighbor, plot) {
490
+ if (neighbor) {
491
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
492
+ var evt1 = jQuery.Event('jqplotDataMouseOver');
493
+ evt1.pageX = ev.pageX;
494
+ evt1.pageY = ev.pageY;
495
+ plot.target.trigger(evt1, ins);
496
+ if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.pyramidRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
497
+ var evt = jQuery.Event('jqplotDataHighlight');
498
+ evt.which = ev.which;
499
+ evt.pageX = ev.pageX;
500
+ evt.pageY = ev.pageY;
501
+ plot.target.trigger(evt, ins);
502
+ highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
503
+ }
504
+ }
505
+ else if (neighbor == null) {
506
+ unhighlight (plot);
507
+ }
508
+ }
509
+
510
+ // Have to add hook here, becuase it needs called before series is inited.
511
+ $.jqplot.preInitHooks.push(preInit);
512
+
513
+
514
+ })(jQuery);