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,313 @@
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.BezierCurveRenderer.js
33
+ // Renderer which draws lines as stacked bezier curves.
34
+ // Data for the line will not be specified as an array of
35
+ // [x, y] data point values, but as a an array of [start piont, bezier curve]
36
+ // So, the line is specified as: [[xstart, ystart], [cp1x, cp1y, cp2x, cp2y, xend, yend]].
37
+ $.jqplot.BezierCurveRenderer = function(){
38
+ $.jqplot.LineRenderer.call(this);
39
+ };
40
+
41
+ $.jqplot.BezierCurveRenderer.prototype = new $.jqplot.LineRenderer();
42
+ $.jqplot.BezierCurveRenderer.prototype.constructor = $.jqplot.BezierCurveRenderer;
43
+
44
+
45
+ // Method: setGridData
46
+ // converts the user data values to grid coordinates and stores them
47
+ // in the gridData array.
48
+ // Called with scope of a series.
49
+ $.jqplot.BezierCurveRenderer.prototype.setGridData = function(plot) {
50
+ // recalculate the grid data
51
+ var xp = this._xaxis.series_u2p;
52
+ var yp = this._yaxis.series_u2p;
53
+ // this._plotData should be same as this.data
54
+ var data = this.data;
55
+ this.gridData = [];
56
+ this._prevGridData = [];
57
+ // if seriesIndex = 0, fill to x axis.
58
+ // if seriesIndex > 0, fill to previous series data.
59
+ var idx = this.index;
60
+ if (data.length == 2) {
61
+ if (idx == 0) {
62
+ this.gridData = [
63
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
64
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
65
+ xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
66
+ xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
67
+ [xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, this._yaxis.min)],
68
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
69
+ ];
70
+ }
71
+ else {
72
+ var psd = plot.series[idx-1].data;
73
+ this.gridData = [
74
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
75
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
76
+ xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
77
+ xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
78
+ [xp.call(this._xaxis, psd[1][4]), yp.call(this._yaxis, psd[1][5])],
79
+ [xp.call(this._xaxis, psd[1][2]), yp.call(this._yaxis, psd[1][3]),
80
+ xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
81
+ xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
82
+ ];
83
+ }
84
+ }
85
+ else {
86
+ if (idx == 0) {
87
+ this.gridData = [
88
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
89
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
90
+ xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
91
+ xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
92
+ [xp.call(this._xaxis, data[3][1]), yp.call(this._yaxis, this._yaxis.min)],
93
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
94
+ ];
95
+ }
96
+ else {
97
+ var psd = plot.series[idx-1].data;
98
+ this.gridData = [
99
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
100
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
101
+ xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
102
+ xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
103
+ [xp.call(this._xaxis, psd[3][0]), yp.call(this._yaxis, psd[3][1])],
104
+ [xp.call(this._xaxis, psd[2][0]), yp.call(this._yaxis, psd[2][1]),
105
+ xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
106
+ xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
107
+ ];
108
+ }
109
+ }
110
+ };
111
+
112
+ // Method: makeGridData
113
+ // converts any arbitrary data values to grid coordinates and
114
+ // returns them. This method exists so that plugins can use a series'
115
+ // linerenderer to generate grid data points without overwriting the
116
+ // grid data associated with that series.
117
+ // Called with scope of a series.
118
+ $.jqplot.BezierCurveRenderer.prototype.makeGridData = function(data, plot) {
119
+ // recalculate the grid data
120
+ var xp = this._xaxis.series_u2p;
121
+ var yp = this._yaxis.series_u2p;
122
+ var gd = [];
123
+ var pgd = [];
124
+ // if seriesIndex = 0, fill to x axis.
125
+ // if seriesIndex > 0, fill to previous series data.
126
+ var idx = this.index;
127
+ if (data.length == 2) {
128
+ if (idx == 0) {
129
+ gd = [
130
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
131
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
132
+ xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
133
+ xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
134
+ [xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, this._yaxis.min)],
135
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
136
+ ];
137
+ }
138
+ else {
139
+ var psd = plot.series[idx-1].data;
140
+ gd = [
141
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
142
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
143
+ xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
144
+ xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
145
+ [xp.call(this._xaxis, psd[1][4]), yp.call(this._yaxis, psd[1][5])],
146
+ [xp.call(this._xaxis, psd[1][2]), yp.call(this._yaxis, psd[1][3]),
147
+ xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
148
+ xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
149
+ ];
150
+ }
151
+ }
152
+ else {
153
+ if (idx == 0) {
154
+ gd = [
155
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
156
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
157
+ xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
158
+ xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
159
+ [xp.call(this._xaxis, data[3][1]), yp.call(this._yaxis, this._yaxis.min)],
160
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
161
+ ];
162
+ }
163
+ else {
164
+ var psd = plot.series[idx-1].data;
165
+ gd = [
166
+ [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
167
+ [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
168
+ xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
169
+ xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
170
+ [xp.call(this._xaxis, psd[3][0]), yp.call(this._yaxis, psd[3][1])],
171
+ [xp.call(this._xaxis, psd[2][0]), yp.call(this._yaxis, psd[2][1]),
172
+ xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
173
+ xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
174
+ ];
175
+ }
176
+ }
177
+ return gd;
178
+ };
179
+
180
+
181
+ // called within scope of series.
182
+ $.jqplot.BezierCurveRenderer.prototype.draw = function(ctx, gd, options) {
183
+ var i;
184
+ ctx.save();
185
+ if (gd.length) {
186
+ if (this.showLine) {
187
+ ctx.save();
188
+ var opts = (options != null) ? options : {};
189
+ ctx.fillStyle = opts.fillStyle || this.color;
190
+ ctx.beginPath();
191
+ ctx.moveTo(gd[0][0], gd[0][1]);
192
+ ctx.bezierCurveTo(gd[1][0], gd[1][1], gd[1][2], gd[1][3], gd[1][4], gd[1][5]);
193
+ ctx.lineTo(gd[2][0], gd[2][1]);
194
+ if (gd[3].length == 2) {
195
+ ctx.lineTo(gd[3][0], gd[3][1]);
196
+ }
197
+ else {
198
+ ctx.bezierCurveTo(gd[3][0], gd[3][1], gd[3][2], gd[3][3], gd[3][4], gd[3][5]);
199
+ }
200
+ ctx.closePath();
201
+ ctx.fill();
202
+ ctx.restore();
203
+ }
204
+ }
205
+
206
+ ctx.restore();
207
+ };
208
+
209
+ $.jqplot.BezierCurveRenderer.prototype.drawShadow = function(ctx, gd, options) {
210
+ // This is a no-op, shadows drawn with lines.
211
+ };
212
+
213
+ $.jqplot.BezierAxisRenderer = function() {
214
+ $.jqplot.LinearAxisRenderer.call(this);
215
+ };
216
+
217
+ $.jqplot.BezierAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
218
+ $.jqplot.BezierAxisRenderer.prototype.constructor = $.jqplot.BezierAxisRenderer;
219
+
220
+
221
+ // Axes on a plot with Bezier Curves
222
+ $.jqplot.BezierAxisRenderer.prototype.init = function(options){
223
+ $.extend(true, this, options);
224
+ var db = this._dataBounds;
225
+ // Go through all the series attached to this axis and find
226
+ // the min/max bounds for this axis.
227
+ for (var i=0; i<this._series.length; i++) {
228
+ var s = this._series[i];
229
+ var d = s.data;
230
+ if (d.length == 4) {
231
+ for (var j=0; j<d.length; j++) {
232
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
233
+ if (d[j][0] < db.min || db.min == null) {
234
+ db.min = d[j][0];
235
+ }
236
+ if (d[j][0] > db.max || db.max == null) {
237
+ db.max = d[j][0];
238
+ }
239
+ }
240
+ else {
241
+ if (d[j][1] < db.min || db.min == null) {
242
+ db.min = d[j][1];
243
+ }
244
+ if (d[j][1] > db.max || db.max == null) {
245
+ db.max = d[j][1];
246
+ }
247
+ }
248
+ }
249
+ }
250
+ else {
251
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
252
+ if (d[0][0] < db.min || db.min == null) {
253
+ db.min = d[0][0];
254
+ }
255
+ if (d[0][0] > db.max || db.max == null) {
256
+ db.max = d[0][0];
257
+ }
258
+ for (var j=0; j<5; j+=2) {
259
+ if (d[1][j] < db.min || db.min == null) {
260
+ db.min = d[1][j];
261
+ }
262
+ if (d[1][j] > db.max || db.max == null) {
263
+ db.max = d[1][j];
264
+ }
265
+ }
266
+ }
267
+ else {
268
+ if (d[0][1] < db.min || db.min == null) {
269
+ db.min = d[0][1];
270
+ }
271
+ if (d[0][1] > db.max || db.max == null) {
272
+ db.max = d[0][1];
273
+ }
274
+ for (var j=1; j<6; j+=2) {
275
+ if (d[1][j] < db.min || db.min == null) {
276
+ db.min = d[1][j];
277
+ }
278
+ if (d[1][j] > db.max || db.max == null) {
279
+ db.max = d[1][j];
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ };
286
+
287
+ // setup default renderers for axes and legend so user doesn't have to
288
+ // called with scope of plot
289
+ function preInit(target, data, options) {
290
+ options = options || {};
291
+ options.axesDefaults = $.extend(true, {pad:0}, options.axesDefaults);
292
+ options.legend = $.extend(true, {placement:'outside'}, options.legend);
293
+ // only set these if there is a pie series
294
+ var setopts = false;
295
+ if (options.seriesDefaults.renderer == $.jqplot.BezierCurveRenderer) {
296
+ setopts = true;
297
+ }
298
+ else if (options.series) {
299
+ for (var i=0; i < options.series.length; i++) {
300
+ if (options.series[i].renderer == $.jqplot.BezierCurveRenderer) {
301
+ setopts = true;
302
+ }
303
+ }
304
+ }
305
+
306
+ if (setopts) {
307
+ options.axesDefaults.renderer = $.jqplot.BezierAxisRenderer;
308
+ }
309
+ }
310
+
311
+ $.jqplot.preInitHooks.push(preInit);
312
+
313
+ })(jQuery);
@@ -0,0 +1,797 @@
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
+ // Class: $.jqplot.BarRenderer
34
+ // A plugin renderer for jqPlot to draw a bar plot.
35
+ // Draws series as a line.
36
+
37
+ $.jqplot.BarRenderer = function(){
38
+ $.jqplot.LineRenderer.call(this);
39
+ };
40
+
41
+ $.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();
42
+ $.jqplot.BarRenderer.prototype.constructor = $.jqplot.BarRenderer;
43
+
44
+ // called with scope of series.
45
+ $.jqplot.BarRenderer.prototype.init = function(options, plot) {
46
+ // Group: Properties
47
+ //
48
+ // prop: barPadding
49
+ // Number of pixels between adjacent bars at the same axis value.
50
+ this.barPadding = 8;
51
+ // prop: barMargin
52
+ // Number of pixels between groups of bars at adjacent axis values.
53
+ this.barMargin = 10;
54
+ // prop: barDirection
55
+ // 'vertical' = up and down bars, 'horizontal' = side to side bars
56
+ this.barDirection = 'vertical';
57
+ // prop: barWidth
58
+ // Width of the bar in pixels (auto by devaul). null = calculated automatically.
59
+ this.barWidth = null;
60
+ // prop: shadowOffset
61
+ // offset of the shadow from the slice and offset of
62
+ // each succesive stroke of the shadow from the last.
63
+ this.shadowOffset = 2;
64
+ // prop: shadowDepth
65
+ // number of strokes to apply to the shadow,
66
+ // each stroke offset shadowOffset from the last.
67
+ this.shadowDepth = 5;
68
+ // prop: shadowAlpha
69
+ // transparency of the shadow (0 = transparent, 1 = opaque)
70
+ this.shadowAlpha = 0.08;
71
+ // prop: waterfall
72
+ // true to enable waterfall plot.
73
+ this.waterfall = false;
74
+ // prop: groups
75
+ // group bars into this many groups
76
+ this.groups = 1;
77
+ // prop: varyBarColor
78
+ // true to color each bar of a series separately rather than
79
+ // have every bar of a given series the same color.
80
+ // If used for non-stacked multiple series bar plots, user should
81
+ // specify a separate 'seriesColors' array for each series.
82
+ // Otherwise, each series will set their bars to the same color array.
83
+ // This option has no Effect for stacked bar charts and is disabled.
84
+ this.varyBarColor = false;
85
+ // prop: highlightMouseOver
86
+ // True to highlight slice when moused over.
87
+ // This must be false to enable highlightMouseDown to highlight when clicking on a slice.
88
+ this.highlightMouseOver = true;
89
+ // prop: highlightMouseDown
90
+ // True to highlight when a mouse button is pressed over a slice.
91
+ // This will be disabled if highlightMouseOver is true.
92
+ this.highlightMouseDown = false;
93
+ // prop: highlightColors
94
+ // an array of colors to use when highlighting a bar.
95
+ this.highlightColors = [];
96
+ // prop: transposedData
97
+ // NOT IMPLEMENTED YET. True if this is a horizontal bar plot and
98
+ // x and y values are "transposed". Tranposed, or "swapped", data is
99
+ // required prior to rev. 894 builds of jqPlot with horizontal bars.
100
+ // Allows backward compatability of bar renderer horizontal bars with
101
+ // old style data sets.
102
+ this.transposedData = true;
103
+ this.renderer.animation = {
104
+ show: false,
105
+ direction: 'down',
106
+ speed: 3000,
107
+ _supported: true
108
+ };
109
+ this._type = 'bar';
110
+
111
+ // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
112
+ if (options.highlightMouseDown && options.highlightMouseOver == null) {
113
+ options.highlightMouseOver = false;
114
+ }
115
+
116
+ //////
117
+ // This is probably wrong here.
118
+ // After going back and forth on wether renderer should be the thing
119
+ // or extend the thing, it seems that it it best if it is a property
120
+ // on the thing. This should be something that is commonized
121
+ // among series renderers in the future.
122
+ //////
123
+ $.extend(true, this, options);
124
+
125
+ // really should probably do this
126
+ $.extend(true, this.renderer, options);
127
+ // fill is still needed to properly draw the legend.
128
+ // bars have to be filled.
129
+ this.fill = true;
130
+
131
+ // if horizontal bar and animating, reset the default direction
132
+ if (this.barDirection === 'horizontal' && this.rendererOptions.animation && this.rendererOptions.animation.direction == null) {
133
+ this.renderer.animation.direction = 'left';
134
+ }
135
+
136
+ if (this.waterfall) {
137
+ this.fillToZero = false;
138
+ this.disableStack = true;
139
+ }
140
+
141
+ if (this.barDirection == 'vertical' ) {
142
+ this._primaryAxis = '_xaxis';
143
+ this._stackAxis = 'y';
144
+ this.fillAxis = 'y';
145
+ }
146
+ else {
147
+ this._primaryAxis = '_yaxis';
148
+ this._stackAxis = 'x';
149
+ this.fillAxis = 'x';
150
+ }
151
+ // index of the currenty highlighted point, if any
152
+ this._highlightedPoint = null;
153
+ // total number of values for all bar series, total number of bar series, and position of this series
154
+ this._plotSeriesInfo = null;
155
+ // Array of actual data colors used for each data point.
156
+ this._dataColors = [];
157
+ this._barPoints = [];
158
+
159
+ // set the shape renderer options
160
+ var opts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill};
161
+ this.renderer.shapeRenderer.init(opts);
162
+ // set the shadow renderer options
163
+ var sopts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, closePath:this.fill};
164
+ this.renderer.shadowRenderer.init(sopts);
165
+
166
+ plot.postInitHooks.addOnce(postInit);
167
+ plot.postDrawHooks.addOnce(postPlotDraw);
168
+ plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
169
+ plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
170
+ plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
171
+ plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
172
+ plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
173
+ };
174
+
175
+ // called with scope of series
176
+ function barPreInit(target, data, seriesDefaults, options) {
177
+ if (this.rendererOptions.barDirection == 'horizontal') {
178
+ this._stackAxis = 'x';
179
+ this._primaryAxis = '_yaxis';
180
+ }
181
+ if (this.rendererOptions.waterfall == true) {
182
+ this._data = $.extend(true, [], this.data);
183
+ var sum = 0;
184
+ var pos = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection === 'vertical' || this.transposedData === false) ? 1 : 0;
185
+ for(var i=0; i<this.data.length; i++) {
186
+ sum += this.data[i][pos];
187
+ if (i>0) {
188
+ this.data[i][pos] += this.data[i-1][pos];
189
+ }
190
+ }
191
+ this.data[this.data.length] = (pos == 1) ? [this.data.length+1, sum] : [sum, this.data.length+1];
192
+ this._data[this._data.length] = (pos == 1) ? [this._data.length+1, sum] : [sum, this._data.length+1];
193
+ }
194
+ if (this.rendererOptions.groups > 1) {
195
+ this.breakOnNull = true;
196
+ var l = this.data.length;
197
+ var skip = parseInt(l/this.rendererOptions.groups, 10);
198
+ var count = 0;
199
+ for (var i=skip; i<l; i+=skip) {
200
+ this.data.splice(i+count, 0, [null, null]);
201
+ this._plotData.splice(i+count, 0, [null, null]);
202
+ this._stackData.splice(i+count, 0, [null, null]);
203
+ count++;
204
+ }
205
+ for (i=0; i<this.data.length; i++) {
206
+ if (this._primaryAxis == '_xaxis') {
207
+ this.data[i][0] = i+1;
208
+ this._plotData[i][0] = i+1;
209
+ this._stackData[i][0] = i+1;
210
+ }
211
+ else {
212
+ this.data[i][1] = i+1;
213
+ this._plotData[i][1] = i+1;
214
+ this._stackData[i][1] = i+1;
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ $.jqplot.preSeriesInitHooks.push(barPreInit);
221
+
222
+ // needs to be called with scope of series, not renderer.
223
+ $.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() {
224
+ var nvals = 0;
225
+ var nseries = 0;
226
+ var paxis = this[this._primaryAxis];
227
+ var s, series, pos;
228
+ // loop through all series on this axis
229
+ for (var i=0; i < paxis._series.length; i++) {
230
+ series = paxis._series[i];
231
+ if (series === this) {
232
+ pos = i;
233
+ }
234
+ // is the series rendered as a bar?
235
+ if (series.renderer.constructor == $.jqplot.BarRenderer) {
236
+ // gridData may not be computed yet, use data length insted
237
+ nvals += series.data.length;
238
+ nseries += 1;
239
+ }
240
+ }
241
+ // return total number of values for all bar series, total number of bar series, and position of this series
242
+ return [nvals, nseries, pos];
243
+ };
244
+
245
+ $.jqplot.BarRenderer.prototype.setBarWidth = function() {
246
+ // need to know how many data values we have on the approprate axis and figure it out.
247
+ var i;
248
+ var nvals = 0;
249
+ var nseries = 0;
250
+ var paxis = this[this._primaryAxis];
251
+ var s, series, pos;
252
+ var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
253
+ nvals = temp[0];
254
+ nseries = temp[1];
255
+ var nticks = paxis.numberTicks;
256
+ var nbins = (nticks-1)/2;
257
+ // so, now we have total number of axis values.
258
+ if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
259
+ if (this._stack) {
260
+ this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals * nseries - this.barMargin;
261
+ }
262
+ else {
263
+ this.barWidth = ((paxis._offsets.max - paxis._offsets.min)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
264
+ // this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding - this.barMargin/nseries;
265
+ }
266
+ }
267
+ else {
268
+ if (this._stack) {
269
+ this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals * nseries - this.barMargin;
270
+ }
271
+ else {
272
+ this.barWidth = ((paxis._offsets.min - paxis._offsets.max)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
273
+ // this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding - this.barMargin/nseries;
274
+ }
275
+ }
276
+ return [nvals, nseries];
277
+ };
278
+
279
+ function computeHighlightColors (colors) {
280
+ var ret = [];
281
+ for (var i=0; i<colors.length; i++){
282
+ var rgba = $.jqplot.getColorComponents(colors[i]);
283
+ var newrgb = [rgba[0], rgba[1], rgba[2]];
284
+ var sum = newrgb[0] + newrgb[1] + newrgb[2];
285
+ for (var j=0; j<3; j++) {
286
+ // when darkening, lowest color component can be is 60.
287
+ newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
288
+ newrgb[j] = parseInt(newrgb[j], 10);
289
+ }
290
+ ret.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
291
+ }
292
+ return ret;
293
+ }
294
+
295
+ function getStart(sidx, didx, comp, plot, axis) {
296
+ // check if sign change
297
+ var seriesIndex = sidx,
298
+ prevSeriesIndex = sidx - 1,
299
+ start,
300
+ prevVal,
301
+ aidx = (axis === 'x') ? 0 : 1;
302
+
303
+ // is this not the first series?
304
+ if (seriesIndex > 0) {
305
+ prevVal = plot.series[prevSeriesIndex]._plotData[didx][aidx];
306
+
307
+ // is there a sign change
308
+ if ((comp * prevVal) < 0) {
309
+ start = getStart(prevSeriesIndex, didx, comp, plot, axis);
310
+ }
311
+
312
+ // no sign change.
313
+ else {
314
+ start = plot.series[prevSeriesIndex].gridData[didx][aidx];
315
+ }
316
+
317
+ }
318
+
319
+ // if first series, return value at 0
320
+ else {
321
+
322
+ start = (aidx === 0) ? plot.series[seriesIndex]._xaxis.series_u2p(0) : plot.series[seriesIndex]._yaxis.series_u2p(0);
323
+ }
324
+
325
+ return start;
326
+ }
327
+
328
+
329
+ $.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options, plot) {
330
+ var i;
331
+ // Ughhh, have to make a copy of options b/c it may be modified later.
332
+ var opts = $.extend({}, options);
333
+ var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
334
+ var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
335
+ var fill = (opts.fill != undefined) ? opts.fill : this.fill;
336
+ var xaxis = this.xaxis;
337
+ var yaxis = this.yaxis;
338
+ var xp = this._xaxis.series_u2p;
339
+ var yp = this._yaxis.series_u2p;
340
+ var pointx, pointy;
341
+ // clear out data colors.
342
+ this._dataColors = [];
343
+ this._barPoints = [];
344
+
345
+ if (this.barWidth == null) {
346
+ this.renderer.setBarWidth.call(this);
347
+ }
348
+
349
+ var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
350
+ var nvals = temp[0];
351
+ var nseries = temp[1];
352
+ var pos = temp[2];
353
+ var points = [];
354
+
355
+ if (this._stack) {
356
+ this._barNudge = 0;
357
+ }
358
+ else {
359
+ this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
360
+ }
361
+ if (showLine) {
362
+ var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
363
+ var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors);
364
+ var negativeColor = negativeColors.get(this.index);
365
+ if (! this.useNegativeColors) {
366
+ negativeColor = opts.fillStyle;
367
+ }
368
+ var positiveColor = opts.fillStyle;
369
+ var base;
370
+ var xstart;
371
+ var ystart;
372
+
373
+ if (this.barDirection == 'vertical') {
374
+ for (var i=0; i<gridData.length; i++) {
375
+ if (!this._stack && this.data[i][1] == null) {
376
+ continue;
377
+ }
378
+ points = [];
379
+ base = gridData[i][0] + this._barNudge;
380
+
381
+ // stacked
382
+ if (this._stack && this._prevGridData.length) {
383
+ ystart = getStart(this.index, i, this._plotData[i][1], plot, 'y');
384
+ }
385
+
386
+ // not stacked
387
+ else {
388
+ if (this.fillToZero) {
389
+ ystart = this._yaxis.series_u2p(0);
390
+ }
391
+ else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
392
+ ystart = this.gridData[i-1][1];
393
+ }
394
+ else if (this.waterfall && i == 0 && i < this.gridData.length-1) {
395
+ if (this._yaxis.min <= 0 && this._yaxis.max >= 0) {
396
+ ystart = this._yaxis.series_u2p(0);
397
+ }
398
+ else if (this._yaxis.min > 0) {
399
+ ystart = ctx.canvas.height;
400
+ }
401
+ else {
402
+ ystart = 0;
403
+ }
404
+ }
405
+ else if (this.waterfall && i == this.gridData.length - 1) {
406
+ if (this._yaxis.min <= 0 && this._yaxis.max >= 0) {
407
+ ystart = this._yaxis.series_u2p(0);
408
+ }
409
+ else if (this._yaxis.min > 0) {
410
+ ystart = ctx.canvas.height;
411
+ }
412
+ else {
413
+ ystart = 0;
414
+ }
415
+ }
416
+ else {
417
+ ystart = ctx.canvas.height;
418
+ }
419
+ }
420
+ if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
421
+ if (this.varyBarColor && !this._stack) {
422
+ if (this.useNegativeColors) {
423
+ opts.fillStyle = negativeColors.next();
424
+ }
425
+ else {
426
+ opts.fillStyle = positiveColors.next();
427
+ }
428
+ }
429
+ else {
430
+ opts.fillStyle = negativeColor;
431
+ }
432
+ }
433
+ else {
434
+ if (this.varyBarColor && !this._stack) {
435
+ opts.fillStyle = positiveColors.next();
436
+ }
437
+ else {
438
+ opts.fillStyle = positiveColor;
439
+ }
440
+ }
441
+
442
+ if (!this.fillToZero || this._plotData[i][1] >= 0) {
443
+ points.push([base-this.barWidth/2, ystart]);
444
+ points.push([base-this.barWidth/2, gridData[i][1]]);
445
+ points.push([base+this.barWidth/2, gridData[i][1]]);
446
+ points.push([base+this.barWidth/2, ystart]);
447
+ }
448
+ // for negative bars make sure points are always ordered clockwise
449
+ else {
450
+ points.push([base-this.barWidth/2, gridData[i][1]]);
451
+ points.push([base-this.barWidth/2, ystart]);
452
+ points.push([base+this.barWidth/2, ystart]);
453
+ points.push([base+this.barWidth/2, gridData[i][1]]);
454
+ }
455
+ this._barPoints.push(points);
456
+ // now draw the shadows if not stacked.
457
+ // for stacked plots, they are predrawn by drawShadow
458
+ if (shadow && !this._stack) {
459
+ var sopts = $.extend(true, {}, opts);
460
+ // need to get rid of fillStyle on shadow.
461
+ delete sopts.fillStyle;
462
+ this.renderer.shadowRenderer.draw(ctx, points, sopts);
463
+ }
464
+ var clr = opts.fillStyle || this.color;
465
+ this._dataColors.push(clr);
466
+ this.renderer.shapeRenderer.draw(ctx, points, opts);
467
+ }
468
+ }
469
+
470
+ else if (this.barDirection == 'horizontal'){
471
+ for (var i=0; i<gridData.length; i++) {
472
+ if (!this._stack && this.data[i][0] == null) {
473
+ continue;
474
+ }
475
+ points = [];
476
+ base = gridData[i][1] - this._barNudge;
477
+ xstart;
478
+
479
+ if (this._stack && this._prevGridData.length) {
480
+ xstart = getStart(this.index, i, this._plotData[i][0], plot, 'x');
481
+ }
482
+ // not stacked
483
+ else {
484
+ if (this.fillToZero) {
485
+ xstart = this._xaxis.series_u2p(0);
486
+ }
487
+ else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
488
+ xstart = this.gridData[i-1][0];
489
+ }
490
+ else if (this.waterfall && i == 0 && i < this.gridData.length-1) {
491
+ if (this._xaxis.min <= 0 && this._xaxis.max >= 0) {
492
+ xstart = this._xaxis.series_u2p(0);
493
+ }
494
+ else if (this._xaxis.min > 0) {
495
+ xstart = 0;
496
+ }
497
+ else {
498
+ xstart = 0;
499
+ }
500
+ }
501
+ else if (this.waterfall && i == this.gridData.length - 1) {
502
+ if (this._xaxis.min <= 0 && this._xaxis.max >= 0) {
503
+ xstart = this._xaxis.series_u2p(0);
504
+ }
505
+ else if (this._xaxis.min > 0) {
506
+ xstart = 0;
507
+ }
508
+ else {
509
+ xstart = ctx.canvas.width;
510
+ }
511
+ }
512
+ else {
513
+ xstart = 0;
514
+ }
515
+ }
516
+ if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
517
+ if (this.varyBarColor && !this._stack) {
518
+ if (this.useNegativeColors) {
519
+ opts.fillStyle = negativeColors.next();
520
+ }
521
+ else {
522
+ opts.fillStyle = positiveColors.next();
523
+ }
524
+ }
525
+ }
526
+ else {
527
+ if (this.varyBarColor && !this._stack) {
528
+ opts.fillStyle = positiveColors.next();
529
+ }
530
+ else {
531
+ opts.fillStyle = positiveColor;
532
+ }
533
+ }
534
+
535
+
536
+ if (!this.fillToZero || this._plotData[i][0] >= 0) {
537
+ points.push([xstart, base + this.barWidth / 2]);
538
+ points.push([xstart, base - this.barWidth / 2]);
539
+ points.push([gridData[i][0], base - this.barWidth / 2]);
540
+ points.push([gridData[i][0], base + this.barWidth / 2]);
541
+ }
542
+ else {
543
+ points.push([gridData[i][0], base + this.barWidth / 2]);
544
+ points.push([gridData[i][0], base - this.barWidth / 2]);
545
+ points.push([xstart, base - this.barWidth / 2]);
546
+ points.push([xstart, base + this.barWidth / 2]);
547
+ }
548
+
549
+ this._barPoints.push(points);
550
+ // now draw the shadows if not stacked.
551
+ // for stacked plots, they are predrawn by drawShadow
552
+ if (shadow && !this._stack) {
553
+ var sopts = $.extend(true, {}, opts);
554
+ delete sopts.fillStyle;
555
+ this.renderer.shadowRenderer.draw(ctx, points, sopts);
556
+ }
557
+ var clr = opts.fillStyle || this.color;
558
+ this._dataColors.push(clr);
559
+ this.renderer.shapeRenderer.draw(ctx, points, opts);
560
+ }
561
+ }
562
+ }
563
+
564
+ if (this.highlightColors.length == 0) {
565
+ this.highlightColors = $.jqplot.computeHighlightColors(this._dataColors);
566
+ }
567
+
568
+ else if (typeof(this.highlightColors) == 'string') {
569
+ var temp = this.highlightColors;
570
+ this.highlightColors = [];
571
+ for (var i=0; i<this._dataColors.length; i++) {
572
+ this.highlightColors.push(temp);
573
+ }
574
+ }
575
+
576
+ };
577
+
578
+
579
+ // for stacked plots, shadows will be pre drawn by drawShadow.
580
+ $.jqplot.BarRenderer.prototype.drawShadow = function(ctx, gridData, options, plot) {
581
+ var i;
582
+ var opts = (options != undefined) ? options : {};
583
+ var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
584
+ var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
585
+ var fill = (opts.fill != undefined) ? opts.fill : this.fill;
586
+ var xaxis = this.xaxis;
587
+ var yaxis = this.yaxis;
588
+ var xp = this._xaxis.series_u2p;
589
+ var yp = this._yaxis.series_u2p;
590
+ var pointx, points, pointy, nvals, nseries, pos;
591
+
592
+ if (this._stack && this.shadow) {
593
+ if (this.barWidth == null) {
594
+ this.renderer.setBarWidth.call(this);
595
+ }
596
+
597
+ var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
598
+ nvals = temp[0];
599
+ nseries = temp[1];
600
+ pos = temp[2];
601
+
602
+ if (this._stack) {
603
+ this._barNudge = 0;
604
+ }
605
+ else {
606
+ this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
607
+ }
608
+ if (showLine) {
609
+
610
+ if (this.barDirection == 'vertical') {
611
+ for (var i=0; i<gridData.length; i++) {
612
+ if (this.data[i][1] == null) {
613
+ continue;
614
+ }
615
+ points = [];
616
+ var base = gridData[i][0] + this._barNudge;
617
+ var ystart;
618
+
619
+ if (this._stack && this._prevGridData.length) {
620
+ ystart = getStart(this.index, i, this._plotData[i][1], plot, 'y');
621
+ }
622
+ else {
623
+ if (this.fillToZero) {
624
+ ystart = this._yaxis.series_u2p(0);
625
+ }
626
+ else {
627
+ ystart = ctx.canvas.height;
628
+ }
629
+ }
630
+
631
+ points.push([base-this.barWidth/2, ystart]);
632
+ points.push([base-this.barWidth/2, gridData[i][1]]);
633
+ points.push([base+this.barWidth/2, gridData[i][1]]);
634
+ points.push([base+this.barWidth/2, ystart]);
635
+ this.renderer.shadowRenderer.draw(ctx, points, opts);
636
+ }
637
+ }
638
+
639
+ else if (this.barDirection == 'horizontal'){
640
+ for (var i=0; i<gridData.length; i++) {
641
+ if (this.data[i][0] == null) {
642
+ continue;
643
+ }
644
+ points = [];
645
+ var base = gridData[i][1] - this._barNudge;
646
+ var xstart;
647
+
648
+ if (this._stack && this._prevGridData.length) {
649
+ xstart = getStart(this.index, i, this._plotData[i][0], plot, 'x');
650
+ }
651
+ else {
652
+ if (this.fillToZero) {
653
+ xstart = this._xaxis.series_u2p(0);
654
+ }
655
+ else {
656
+ xstart = 0;
657
+ }
658
+ }
659
+
660
+ points.push([xstart, base+this.barWidth/2]);
661
+ points.push([gridData[i][0], base+this.barWidth/2]);
662
+ points.push([gridData[i][0], base-this.barWidth/2]);
663
+ points.push([xstart, base-this.barWidth/2]);
664
+ this.renderer.shadowRenderer.draw(ctx, points, opts);
665
+ }
666
+ }
667
+ }
668
+
669
+ }
670
+ };
671
+
672
+ function postInit(target, data, options) {
673
+ for (var i=0; i<this.series.length; i++) {
674
+ if (this.series[i].renderer.constructor == $.jqplot.BarRenderer) {
675
+ // don't allow mouseover and mousedown at same time.
676
+ if (this.series[i].highlightMouseOver) {
677
+ this.series[i].highlightMouseDown = false;
678
+ }
679
+ }
680
+ }
681
+ }
682
+
683
+ // called within context of plot
684
+ // create a canvas which we can draw on.
685
+ // insert it before the eventCanvas, so eventCanvas will still capture events.
686
+ function postPlotDraw() {
687
+ // Memory Leaks patch
688
+ if (this.plugins.barRenderer && this.plugins.barRenderer.highlightCanvas) {
689
+
690
+ this.plugins.barRenderer.highlightCanvas.resetCanvas();
691
+ this.plugins.barRenderer.highlightCanvas = null;
692
+ }
693
+
694
+ this.plugins.barRenderer = {highlightedSeriesIndex:null};
695
+ this.plugins.barRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
696
+
697
+ this.eventCanvas._elem.before(this.plugins.barRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-barRenderer-highlight-canvas', this._plotDimensions, this));
698
+ this.plugins.barRenderer.highlightCanvas.setContext();
699
+ this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
700
+ }
701
+
702
+ function highlight (plot, sidx, pidx, points) {
703
+ var s = plot.series[sidx];
704
+ var canvas = plot.plugins.barRenderer.highlightCanvas;
705
+ canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
706
+ s._highlightedPoint = pidx;
707
+ plot.plugins.barRenderer.highlightedSeriesIndex = sidx;
708
+ var opts = {fillStyle: s.highlightColors[pidx]};
709
+ s.renderer.shapeRenderer.draw(canvas._ctx, points, opts);
710
+ canvas = null;
711
+ }
712
+
713
+ function unhighlight (plot) {
714
+ var canvas = plot.plugins.barRenderer.highlightCanvas;
715
+ canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
716
+ for (var i=0; i<plot.series.length; i++) {
717
+ plot.series[i]._highlightedPoint = null;
718
+ }
719
+ plot.plugins.barRenderer.highlightedSeriesIndex = null;
720
+ plot.target.trigger('jqplotDataUnhighlight');
721
+ canvas = null;
722
+ }
723
+
724
+
725
+ function handleMove(ev, gridpos, datapos, neighbor, plot) {
726
+ if (neighbor) {
727
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
728
+ var evt1 = jQuery.Event('jqplotDataMouseOver');
729
+ evt1.pageX = ev.pageX;
730
+ evt1.pageY = ev.pageY;
731
+ plot.target.trigger(evt1, ins);
732
+ if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
733
+ var evt = jQuery.Event('jqplotDataHighlight');
734
+ evt.which = ev.which;
735
+ evt.pageX = ev.pageX;
736
+ evt.pageY = ev.pageY;
737
+ plot.target.trigger(evt, ins);
738
+ highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
739
+ }
740
+ }
741
+ else if (neighbor == null) {
742
+ unhighlight (plot);
743
+ }
744
+ }
745
+
746
+ function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
747
+ if (neighbor) {
748
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
749
+ if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
750
+ var evt = jQuery.Event('jqplotDataHighlight');
751
+ evt.which = ev.which;
752
+ evt.pageX = ev.pageX;
753
+ evt.pageY = ev.pageY;
754
+ plot.target.trigger(evt, ins);
755
+ highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
756
+ }
757
+ }
758
+ else if (neighbor == null) {
759
+ unhighlight (plot);
760
+ }
761
+ }
762
+
763
+ function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
764
+ var idx = plot.plugins.barRenderer.highlightedSeriesIndex;
765
+ if (idx != null && plot.series[idx].highlightMouseDown) {
766
+ unhighlight(plot);
767
+ }
768
+ }
769
+
770
+ function handleClick(ev, gridpos, datapos, neighbor, plot) {
771
+ if (neighbor) {
772
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
773
+ var evt = jQuery.Event('jqplotDataClick');
774
+ evt.which = ev.which;
775
+ evt.pageX = ev.pageX;
776
+ evt.pageY = ev.pageY;
777
+ plot.target.trigger(evt, ins);
778
+ }
779
+ }
780
+
781
+ function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
782
+ if (neighbor) {
783
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
784
+ var idx = plot.plugins.barRenderer.highlightedSeriesIndex;
785
+ if (idx != null && plot.series[idx].highlightMouseDown) {
786
+ unhighlight(plot);
787
+ }
788
+ var evt = jQuery.Event('jqplotDataRightClick');
789
+ evt.which = ev.which;
790
+ evt.pageX = ev.pageX;
791
+ evt.pageY = ev.pageY;
792
+ plot.target.trigger(evt, ins);
793
+ }
794
+ }
795
+
796
+
797
+ })(jQuery);