1 | /** |
---|
2 | * jqPlot |
---|
3 | * Pure JavaScript plotting plugin using jQuery |
---|
4 | * |
---|
5 | * Version: @VERSION |
---|
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 | // class: $.jqplot.CanvasOverlay |
---|
32 | $.jqplot.CanvasOverlay = function(opts){ |
---|
33 | var options = opts || {}; |
---|
34 | this.options = { |
---|
35 | show: $.jqplot.config.enablePlugins, |
---|
36 | deferDraw: false |
---|
37 | }; |
---|
38 | // prop: objects |
---|
39 | this.objects = []; |
---|
40 | this.objectNames = []; |
---|
41 | this.canvas = null; |
---|
42 | this.markerRenderer = new $.jqplot.MarkerRenderer({style:'line'}); |
---|
43 | this.markerRenderer.init(); |
---|
44 | if (options.objects) { |
---|
45 | var objs = options.objects, |
---|
46 | obj; |
---|
47 | for (var i=0; i<objs.length; i++) { |
---|
48 | obj = objs[i]; |
---|
49 | for (var n in obj) { |
---|
50 | switch (n) { |
---|
51 | case 'line': |
---|
52 | this.addLine(obj[n]); |
---|
53 | break; |
---|
54 | case 'horizontalLine': |
---|
55 | this.addHorizontalLine(obj[n]); |
---|
56 | break; |
---|
57 | case 'dashedHorizontalLine': |
---|
58 | this.addDashedHorizontalLine(obj[n]); |
---|
59 | break; |
---|
60 | case 'verticalLine': |
---|
61 | this.addVerticalLine(obj[n]); |
---|
62 | break; |
---|
63 | case 'dashedVerticalLine': |
---|
64 | this.addDashedVerticalLine(obj[n]); |
---|
65 | break; |
---|
66 | default: |
---|
67 | break; |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | $.extend(true, this.options, options); |
---|
73 | }; |
---|
74 | |
---|
75 | // called with scope of a plot object |
---|
76 | $.jqplot.CanvasOverlay.postPlotInit = function (target, data, opts) { |
---|
77 | var options = opts || {}; |
---|
78 | // add a canvasOverlay attribute to the plot |
---|
79 | this.plugins.canvasOverlay = new $.jqplot.CanvasOverlay(options.canvasOverlay); |
---|
80 | }; |
---|
81 | |
---|
82 | /** |
---|
83 | * Class: Line |
---|
84 | * A straight line. |
---|
85 | */ |
---|
86 | function Line(options) { |
---|
87 | this.type = 'line'; |
---|
88 | this.options = { |
---|
89 | // prop: name |
---|
90 | // Optional name for this overlay object. |
---|
91 | // Can be later used to retrieve the object by name. |
---|
92 | name: null, |
---|
93 | // prop: show |
---|
94 | // true to show (draw), false to not draw. |
---|
95 | show: true, |
---|
96 | // prop: lineWidth |
---|
97 | // Width of the line. |
---|
98 | lineWidth: 2, |
---|
99 | // prop: lineCap |
---|
100 | // Type of ending placed on the line ['round', 'butt', 'square'] |
---|
101 | lineCap: 'round', |
---|
102 | // prop: color |
---|
103 | // color of the line |
---|
104 | color: '#666666', |
---|
105 | // prop: shadow |
---|
106 | // wether or not to draw a shadow on the line |
---|
107 | shadow: true, |
---|
108 | // prop: shadowAngle |
---|
109 | // Shadow angle in degrees |
---|
110 | shadowAngle: 45, |
---|
111 | // prop: shadowOffset |
---|
112 | // Shadow offset from line in pixels |
---|
113 | shadowOffset: 1, |
---|
114 | // prop: shadowDepth |
---|
115 | // Number of times shadow is stroked, each stroke offset shadowOffset from the last. |
---|
116 | shadowDepth: 3, |
---|
117 | // prop: shadowAlpha |
---|
118 | // Alpha channel transparency of shadow. 0 = transparent. |
---|
119 | shadowAlpha: '0.07', |
---|
120 | // prop: xaxis |
---|
121 | // X axis to use for positioning/scaling the line. |
---|
122 | xaxis: 'xaxis', |
---|
123 | // prop: yaxis |
---|
124 | // Y axis to use for positioning/scaling the line. |
---|
125 | yaxis: 'yaxis', |
---|
126 | // prop: start |
---|
127 | // [x, y] coordinates for the start of the line. |
---|
128 | start: [], |
---|
129 | // prop: stop |
---|
130 | // [x, y] coordinates for the end of the line. |
---|
131 | stop: [] |
---|
132 | }; |
---|
133 | $.extend(true, this.options, options); |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * Class: HorizontalLine |
---|
138 | * A straight horizontal line. |
---|
139 | */ |
---|
140 | function HorizontalLine(options) { |
---|
141 | this.type = 'horizontalLine'; |
---|
142 | this.options = { |
---|
143 | // prop: name |
---|
144 | // Optional name for this overlay object. |
---|
145 | // Can be later used to retrieve the object by name. |
---|
146 | name: null, |
---|
147 | // prop: show |
---|
148 | // true to show (draw), false to not draw. |
---|
149 | show: true, |
---|
150 | // prop: lineWidth |
---|
151 | // Width of the line. |
---|
152 | lineWidth: 2, |
---|
153 | // prop: lineCap |
---|
154 | // Type of ending placed on the line ['round', 'butt', 'square'] |
---|
155 | lineCap: 'round', |
---|
156 | // prop: color |
---|
157 | // color of the line |
---|
158 | color: '#666666', |
---|
159 | // prop: shadow |
---|
160 | // wether or not to draw a shadow on the line |
---|
161 | shadow: true, |
---|
162 | // prop: shadowAngle |
---|
163 | // Shadow angle in degrees |
---|
164 | shadowAngle: 45, |
---|
165 | // prop: shadowOffset |
---|
166 | // Shadow offset from line in pixels |
---|
167 | shadowOffset: 1, |
---|
168 | // prop: shadowDepth |
---|
169 | // Number of times shadow is stroked, each stroke offset shadowOffset from the last. |
---|
170 | shadowDepth: 3, |
---|
171 | // prop: shadowAlpha |
---|
172 | // Alpha channel transparency of shadow. 0 = transparent. |
---|
173 | shadowAlpha: '0.07', |
---|
174 | // prop: xaxis |
---|
175 | // X axis to use for positioning/scaling the line. |
---|
176 | xaxis: 'xaxis', |
---|
177 | // prop: yaxis |
---|
178 | // Y axis to use for positioning/scaling the line. |
---|
179 | yaxis: 'yaxis', |
---|
180 | // prop: y |
---|
181 | // y value to position the line |
---|
182 | y: null, |
---|
183 | // prop: xmin |
---|
184 | // x value for the start of the line, null to scale to axis min. |
---|
185 | xmin: null, |
---|
186 | // prop: xmax |
---|
187 | // x value for the end of the line, null to scale to axis max. |
---|
188 | xmax: null, |
---|
189 | // prop xOffset |
---|
190 | // offset ends of the line inside the grid. Number |
---|
191 | xOffset: '6px', // number or string. Number interpreted as units, string as pixels. |
---|
192 | xminOffset: null, |
---|
193 | xmaxOffset: null |
---|
194 | }; |
---|
195 | $.extend(true, this.options, options); |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | /** |
---|
200 | * Class: DashedHorizontalLine |
---|
201 | * A straight dashed horizontal line. |
---|
202 | */ |
---|
203 | function DashedHorizontalLine(options) { |
---|
204 | this.type = 'dashedHorizontalLine'; |
---|
205 | this.options = { |
---|
206 | // prop: name |
---|
207 | // Optional name for this overlay object. |
---|
208 | // Can be later used to retrieve the object by name. |
---|
209 | name: null, |
---|
210 | // prop: show |
---|
211 | // true to show (draw), false to not draw. |
---|
212 | show: true, |
---|
213 | // prop: lineWidth |
---|
214 | // Width of the line. |
---|
215 | lineWidth: 2, |
---|
216 | // prop: lineCap |
---|
217 | // Type of ending placed on the line ['round', 'butt', 'square'] |
---|
218 | lineCap: 'butt', |
---|
219 | // prop: color |
---|
220 | // color of the line |
---|
221 | color: '#666666', |
---|
222 | // prop: shadow |
---|
223 | // wether or not to draw a shadow on the line |
---|
224 | shadow: true, |
---|
225 | // prop: shadowAngle |
---|
226 | // Shadow angle in degrees |
---|
227 | shadowAngle: 45, |
---|
228 | // prop: shadowOffset |
---|
229 | // Shadow offset from line in pixels |
---|
230 | shadowOffset: 1, |
---|
231 | // prop: shadowDepth |
---|
232 | // Number of times shadow is stroked, each stroke offset shadowOffset from the last. |
---|
233 | shadowDepth: 3, |
---|
234 | // prop: shadowAlpha |
---|
235 | // Alpha channel transparency of shadow. 0 = transparent. |
---|
236 | shadowAlpha: '0.07', |
---|
237 | // prop: xaxis |
---|
238 | // X axis to use for positioning/scaling the line. |
---|
239 | xaxis: 'xaxis', |
---|
240 | // prop: yaxis |
---|
241 | // Y axis to use for positioning/scaling the line. |
---|
242 | yaxis: 'yaxis', |
---|
243 | y: null, |
---|
244 | xmin: null, |
---|
245 | xmax: null, |
---|
246 | xOffset: '6px', // number or string. Number interpreted as units, string as pixels. |
---|
247 | xminOffset: null, |
---|
248 | xmaxOffset: null, |
---|
249 | // prop: dashPattern |
---|
250 | // Array of line, space settings in pixels. |
---|
251 | // Default is 8 pixel of line, 8 pixel of space. |
---|
252 | // Note, limit to a 2 element array b/c of bug with higher order arrays. |
---|
253 | dashPattern: [8,8] |
---|
254 | }; |
---|
255 | $.extend(true, this.options, options); |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | /** |
---|
260 | * Class: VerticalLine |
---|
261 | * A straight vertical line. |
---|
262 | */ |
---|
263 | function VerticalLine(options) { |
---|
264 | this.type = 'verticalLine'; |
---|
265 | this.options = { |
---|
266 | // prop: name |
---|
267 | // Optional name for this overlay object. |
---|
268 | // Can be later used to retrieve the object by name. |
---|
269 | name: null, |
---|
270 | // prop: show |
---|
271 | // true to show (draw), false to not draw. |
---|
272 | show: true, |
---|
273 | // prop: lineWidth |
---|
274 | // Width of the line. |
---|
275 | lineWidth: 2, |
---|
276 | // prop: lineCap |
---|
277 | // Type of ending placed on the line ['round', 'butt', 'square'] |
---|
278 | lineCap: 'round', |
---|
279 | // prop: color |
---|
280 | // color of the line |
---|
281 | color: '#666666', |
---|
282 | // prop: shadow |
---|
283 | // wether or not to draw a shadow on the line |
---|
284 | shadow: true, |
---|
285 | // prop: shadowAngle |
---|
286 | // Shadow angle in degrees |
---|
287 | shadowAngle: 45, |
---|
288 | // prop: shadowOffset |
---|
289 | // Shadow offset from line in pixels |
---|
290 | shadowOffset: 1, |
---|
291 | // prop: shadowDepth |
---|
292 | // Number of times shadow is stroked, each stroke offset shadowOffset from the last. |
---|
293 | shadowDepth: 3, |
---|
294 | // prop: shadowAlpha |
---|
295 | // Alpha channel transparency of shadow. 0 = transparent. |
---|
296 | shadowAlpha: '0.07', |
---|
297 | // prop: xaxis |
---|
298 | // X axis to use for positioning/scaling the line. |
---|
299 | xaxis: 'xaxis', |
---|
300 | // prop: yaxis |
---|
301 | // Y axis to use for positioning/scaling the line. |
---|
302 | yaxis: 'yaxis', |
---|
303 | x: null, |
---|
304 | ymin: null, |
---|
305 | ymax: null, |
---|
306 | yOffset: '6px', // number or string. Number interpreted as units, string as pixels. |
---|
307 | yminOffset: null, |
---|
308 | ymaxOffset: null |
---|
309 | }; |
---|
310 | $.extend(true, this.options, options); |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | /** |
---|
315 | * Class: DashedVerticalLine |
---|
316 | * A straight dashed vertical line. |
---|
317 | */ |
---|
318 | function DashedVerticalLine(options) { |
---|
319 | this.type = 'dashedVerticalLine'; |
---|
320 | this.options = { |
---|
321 | // prop: name |
---|
322 | // Optional name for this overlay object. |
---|
323 | // Can be later used to retrieve the object by name. |
---|
324 | name: null, |
---|
325 | // prop: show |
---|
326 | // true to show (draw), false to not draw. |
---|
327 | show: true, |
---|
328 | // prop: lineWidth |
---|
329 | // Width of the line. |
---|
330 | lineWidth: 2, |
---|
331 | // prop: lineCap |
---|
332 | // Type of ending placed on the line ['round', 'butt', 'square'] |
---|
333 | lineCap: 'butt', |
---|
334 | // prop: color |
---|
335 | // color of the line |
---|
336 | color: '#666666', |
---|
337 | // prop: shadow |
---|
338 | // wether or not to draw a shadow on the line |
---|
339 | shadow: true, |
---|
340 | // prop: shadowAngle |
---|
341 | // Shadow angle in degrees |
---|
342 | shadowAngle: 45, |
---|
343 | // prop: shadowOffset |
---|
344 | // Shadow offset from line in pixels |
---|
345 | shadowOffset: 1, |
---|
346 | // prop: shadowDepth |
---|
347 | // Number of times shadow is stroked, each stroke offset shadowOffset from the last. |
---|
348 | shadowDepth: 3, |
---|
349 | // prop: shadowAlpha |
---|
350 | // Alpha channel transparency of shadow. 0 = transparent. |
---|
351 | shadowAlpha: '0.07', |
---|
352 | // prop: xaxis |
---|
353 | // X axis to use for positioning/scaling the line. |
---|
354 | xaxis: 'xaxis', |
---|
355 | // prop: yaxis |
---|
356 | // Y axis to use for positioning/scaling the line. |
---|
357 | yaxis: 'yaxis', |
---|
358 | x: null, |
---|
359 | ymin: null, |
---|
360 | ymax: null, |
---|
361 | yOffset: '6px', // number or string. Number interpreted as units, string as pixels. |
---|
362 | yminOffset: null, |
---|
363 | ymaxOffset: null, |
---|
364 | // prop: dashPattern |
---|
365 | // Array of line, space settings in pixels. |
---|
366 | // Default is 8 pixel of line, 8 pixel of space. |
---|
367 | // Note, limit to a 2 element array b/c of bug with higher order arrays. |
---|
368 | dashPattern: [8,8] |
---|
369 | }; |
---|
370 | $.extend(true, this.options, options); |
---|
371 | } |
---|
372 | |
---|
373 | $.jqplot.CanvasOverlay.prototype.addLine = function(opts) { |
---|
374 | var line = new Line(opts); |
---|
375 | this.objects.push(line); |
---|
376 | this.objectNames.push(line.options.name); |
---|
377 | }; |
---|
378 | |
---|
379 | $.jqplot.CanvasOverlay.prototype.addHorizontalLine = function(opts) { |
---|
380 | var line = new HorizontalLine(opts); |
---|
381 | this.objects.push(line); |
---|
382 | this.objectNames.push(line.options.name); |
---|
383 | }; |
---|
384 | |
---|
385 | $.jqplot.CanvasOverlay.prototype.addDashedHorizontalLine = function(opts) { |
---|
386 | var line = new DashedHorizontalLine(opts); |
---|
387 | this.objects.push(line); |
---|
388 | this.objectNames.push(line.options.name); |
---|
389 | }; |
---|
390 | |
---|
391 | $.jqplot.CanvasOverlay.prototype.addVerticalLine = function(opts) { |
---|
392 | var line = new VerticalLine(opts); |
---|
393 | this.objects.push(line); |
---|
394 | this.objectNames.push(line.options.name); |
---|
395 | }; |
---|
396 | |
---|
397 | $.jqplot.CanvasOverlay.prototype.addDashedVerticalLine = function(opts) { |
---|
398 | var line = new DashedVerticalLine(opts); |
---|
399 | this.objects.push(line); |
---|
400 | this.objectNames.push(line.options.name); |
---|
401 | }; |
---|
402 | |
---|
403 | $.jqplot.CanvasOverlay.prototype.removeObject = function(idx) { |
---|
404 | // check if integer, remove by index |
---|
405 | if ($.type(idx) == 'number') { |
---|
406 | this.objects.splice(idx, 1); |
---|
407 | this.objectNames.splice(idx, 1); |
---|
408 | } |
---|
409 | // if string, remove by name |
---|
410 | else { |
---|
411 | var id = $.inArray(idx, this.objectNames); |
---|
412 | if (id != -1) { |
---|
413 | this.objects.splice(id, 1); |
---|
414 | this.objectNames.splice(id, 1); |
---|
415 | } |
---|
416 | } |
---|
417 | }; |
---|
418 | |
---|
419 | $.jqplot.CanvasOverlay.prototype.getObject = function(idx) { |
---|
420 | // check if integer, remove by index |
---|
421 | if ($.type(idx) == 'number') { |
---|
422 | return this.objects[idx]; |
---|
423 | } |
---|
424 | // if string, remove by name |
---|
425 | else { |
---|
426 | var id = $.inArray(idx, this.objectNames); |
---|
427 | if (id != -1) { |
---|
428 | return this.objects[id]; |
---|
429 | } |
---|
430 | } |
---|
431 | }; |
---|
432 | |
---|
433 | // Set get as alias for getObject. |
---|
434 | $.jqplot.CanvasOverlay.prototype.get = $.jqplot.CanvasOverlay.prototype.getObject; |
---|
435 | |
---|
436 | $.jqplot.CanvasOverlay.prototype.clear = function(plot) { |
---|
437 | this.canvas._ctx.clearRect(0,0,this.canvas.getWidth(), this.canvas.getHeight()); |
---|
438 | }; |
---|
439 | |
---|
440 | $.jqplot.CanvasOverlay.prototype.draw = function(plot) { |
---|
441 | var obj, |
---|
442 | objs = this.objects, |
---|
443 | mr = this.markerRenderer, |
---|
444 | start, |
---|
445 | stop; |
---|
446 | if (this.options.show) { |
---|
447 | this.canvas._ctx.clearRect(0,0,this.canvas.getWidth(), this.canvas.getHeight()); |
---|
448 | for (var k=0; k<objs.length; k++) { |
---|
449 | obj = objs[k]; |
---|
450 | var opts = $.extend(true, {}, obj.options); |
---|
451 | if (obj.options.show) { |
---|
452 | // style and shadow properties should be set before |
---|
453 | // every draw of marker renderer. |
---|
454 | mr.shadow = obj.options.shadow; |
---|
455 | switch (obj.type) { |
---|
456 | case 'line': |
---|
457 | // style and shadow properties should be set before |
---|
458 | // every draw of marker renderer. |
---|
459 | mr.style = 'line'; |
---|
460 | opts.closePath = false; |
---|
461 | start = [plot.axes[obj.options.xaxis].series_u2p(obj.options.start[0]), plot.axes[obj.options.yaxis].series_u2p(obj.options.start[1])]; |
---|
462 | stop = [plot.axes[obj.options.xaxis].series_u2p(obj.options.stop[0]), plot.axes[obj.options.yaxis].series_u2p(obj.options.stop[1])]; |
---|
463 | mr.draw(start, stop, this.canvas._ctx, opts); |
---|
464 | break; |
---|
465 | case 'horizontalLine': |
---|
466 | |
---|
467 | // style and shadow properties should be set before |
---|
468 | // every draw of marker renderer. |
---|
469 | if (obj.options.y != null) { |
---|
470 | mr.style = 'line'; |
---|
471 | opts.closePath = false; |
---|
472 | var xaxis = plot.axes[obj.options.xaxis], |
---|
473 | xstart, |
---|
474 | xstop, |
---|
475 | y = plot.axes[obj.options.yaxis].series_u2p(obj.options.y), |
---|
476 | xminoff = obj.options.xminOffset || obj.options.xOffset, |
---|
477 | xmaxoff = obj.options.xmaxOffset || obj.options.xOffset; |
---|
478 | if (obj.options.xmin != null) { |
---|
479 | xstart = xaxis.series_u2p(obj.options.xmin); |
---|
480 | } |
---|
481 | else if (xminoff != null) { |
---|
482 | if ($.type(xminoff) == "number") { |
---|
483 | xstart = xaxis.series_u2p(xaxis.min + xminoff); |
---|
484 | } |
---|
485 | else if ($.type(xminoff) == "string") { |
---|
486 | xstart = xaxis.series_u2p(xaxis.min) + parseFloat(xminoff); |
---|
487 | } |
---|
488 | } |
---|
489 | if (obj.options.xmax != null) { |
---|
490 | xstop = xaxis.series_u2p(obj.options.xmax); |
---|
491 | } |
---|
492 | else if (xmaxoff != null) { |
---|
493 | if ($.type(xmaxoff) == "number") { |
---|
494 | xstop = xaxis.series_u2p(xaxis.max - xmaxoff); |
---|
495 | } |
---|
496 | else if ($.type(xmaxoff) == "string") { |
---|
497 | xstop = xaxis.series_u2p(xaxis.max) - parseFloat(xmaxoff); |
---|
498 | } |
---|
499 | } |
---|
500 | if (xstop != null && xstart != null) { |
---|
501 | mr.draw([xstart, y], [xstop, y], this.canvas._ctx, opts); |
---|
502 | } |
---|
503 | } |
---|
504 | break; |
---|
505 | |
---|
506 | case 'dashedHorizontalLine': |
---|
507 | |
---|
508 | var dashPat = obj.options.dashPattern; |
---|
509 | var dashPatLen = 0; |
---|
510 | for (var i=0; i<dashPat.length; i++) { |
---|
511 | dashPatLen += dashPat[i]; |
---|
512 | } |
---|
513 | |
---|
514 | // style and shadow properties should be set before |
---|
515 | // every draw of marker renderer. |
---|
516 | if (obj.options.y != null) { |
---|
517 | mr.style = 'line'; |
---|
518 | opts.closePath = false; |
---|
519 | var xaxis = plot.axes[obj.options.xaxis], |
---|
520 | xstart, |
---|
521 | xstop, |
---|
522 | y = plot.axes[obj.options.yaxis].series_u2p(obj.options.y), |
---|
523 | xminoff = obj.options.xminOffset || obj.options.xOffset, |
---|
524 | xmaxoff = obj.options.xmaxOffset || obj.options.xOffset; |
---|
525 | if (obj.options.xmin != null) { |
---|
526 | xstart = xaxis.series_u2p(obj.options.xmin); |
---|
527 | } |
---|
528 | else if (xminoff != null) { |
---|
529 | if ($.type(xminoff) == "number") { |
---|
530 | xstart = xaxis.series_u2p(xaxis.min + xminoff); |
---|
531 | } |
---|
532 | else if ($.type(xminoff) == "string") { |
---|
533 | xstart = xaxis.series_u2p(xaxis.min) + parseFloat(xminoff); |
---|
534 | } |
---|
535 | } |
---|
536 | if (obj.options.xmax != null) { |
---|
537 | xstop = xaxis.series_u2p(obj.options.xmax); |
---|
538 | } |
---|
539 | else if (xmaxoff != null) { |
---|
540 | if ($.type(xmaxoff) == "number") { |
---|
541 | xstop = xaxis.series_u2p(xaxis.max - xmaxoff); |
---|
542 | } |
---|
543 | else if ($.type(xmaxoff) == "string") { |
---|
544 | xstop = xaxis.series_u2p(xaxis.max) - parseFloat(xmaxoff); |
---|
545 | } |
---|
546 | } |
---|
547 | if (xstop != null && xstart != null) { |
---|
548 | var numDash = Math.ceil((xstop - xstart)/dashPatLen); |
---|
549 | var b=xstart, e; |
---|
550 | for (var i=0; i<numDash; i++) { |
---|
551 | for (var j=0; j<dashPat.length; j+=2) { |
---|
552 | e = b+dashPat[j]; |
---|
553 | mr.draw([b, y], [e, y], this.canvas._ctx, opts); |
---|
554 | b += dashPat[j]; |
---|
555 | if (j < dashPat.length-1) { |
---|
556 | b += dashPat[j+1]; |
---|
557 | } |
---|
558 | } |
---|
559 | } |
---|
560 | } |
---|
561 | } |
---|
562 | break; |
---|
563 | |
---|
564 | case 'verticalLine': |
---|
565 | |
---|
566 | // style and shadow properties should be set before |
---|
567 | // every draw of marker renderer. |
---|
568 | if (obj.options.x != null) { |
---|
569 | mr.style = 'line'; |
---|
570 | opts.closePath = false; |
---|
571 | var yaxis = plot.axes[obj.options.yaxis], |
---|
572 | ystart, |
---|
573 | ystop, |
---|
574 | x = plot.axes[obj.options.xaxis].series_u2p(obj.options.x), |
---|
575 | yminoff = obj.options.yminOffset || obj.options.yOffset, |
---|
576 | ymaxoff = obj.options.ymaxOffset || obj.options.yOffset; |
---|
577 | if (obj.options.ymin != null) { |
---|
578 | ystart = yaxis.series_u2p(obj.options.ymin); |
---|
579 | } |
---|
580 | else if (yminoff != null) { |
---|
581 | if ($.type(yminoff) == "number") { |
---|
582 | ystart = yaxis.series_u2p(yaxis.min - yminoff); |
---|
583 | } |
---|
584 | else if ($.type(yminoff) == "string") { |
---|
585 | ystart = yaxis.series_u2p(yaxis.min) - parseFloat(yminoff); |
---|
586 | } |
---|
587 | } |
---|
588 | if (obj.options.ymax != null) { |
---|
589 | ystop = yaxis.series_u2p(obj.options.ymax); |
---|
590 | } |
---|
591 | else if (ymaxoff != null) { |
---|
592 | if ($.type(ymaxoff) == "number") { |
---|
593 | ystop = yaxis.series_u2p(yaxis.max + ymaxoff); |
---|
594 | } |
---|
595 | else if ($.type(ymaxoff) == "string") { |
---|
596 | ystop = yaxis.series_u2p(yaxis.max) + parseFloat(ymaxoff); |
---|
597 | } |
---|
598 | } |
---|
599 | if (ystop != null && ystart != null) { |
---|
600 | mr.draw([x, ystart], [x, ystop], this.canvas._ctx, opts); |
---|
601 | } |
---|
602 | } |
---|
603 | break; |
---|
604 | |
---|
605 | case 'dashedVerticalLine': |
---|
606 | |
---|
607 | var dashPat = obj.options.dashPattern; |
---|
608 | var dashPatLen = 0; |
---|
609 | for (var i=0; i<dashPat.length; i++) { |
---|
610 | dashPatLen += dashPat[i]; |
---|
611 | } |
---|
612 | |
---|
613 | // style and shadow properties should be set before |
---|
614 | // every draw of marker renderer. |
---|
615 | if (obj.options.x != null) { |
---|
616 | mr.style = 'line'; |
---|
617 | opts.closePath = false; |
---|
618 | var yaxis = plot.axes[obj.options.yaxis], |
---|
619 | ystart, |
---|
620 | ystop, |
---|
621 | x = plot.axes[obj.options.xaxis].series_u2p(obj.options.x), |
---|
622 | yminoff = obj.options.yminOffset || obj.options.yOffset, |
---|
623 | ymaxoff = obj.options.ymaxOffset || obj.options.yOffset; |
---|
624 | if (obj.options.ymin != null) { |
---|
625 | ystart = yaxis.series_u2p(obj.options.ymin); |
---|
626 | } |
---|
627 | else if (yminoff != null) { |
---|
628 | if ($.type(yminoff) == "number") { |
---|
629 | ystart = yaxis.series_u2p(yaxis.min - yminoff); |
---|
630 | } |
---|
631 | else if ($.type(yminoff) == "string") { |
---|
632 | ystart = yaxis.series_u2p(yaxis.min) - parseFloat(yminoff); |
---|
633 | } |
---|
634 | } |
---|
635 | if (obj.options.ymax != null) { |
---|
636 | ystop = yaxis.series_u2p(obj.options.ymax); |
---|
637 | } |
---|
638 | else if (ymaxoff != null) { |
---|
639 | if ($.type(ymaxoff) == "number") { |
---|
640 | ystop = yaxis.series_u2p(yaxis.max + ymaxoff); |
---|
641 | } |
---|
642 | else if ($.type(ymaxoff) == "string") { |
---|
643 | ystop = yaxis.series_u2p(yaxis.max) + parseFloat(ymaxoff); |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | |
---|
648 | if (ystop != null && ystart != null) { |
---|
649 | var numDash = Math.ceil((ystart - ystop)/dashPatLen); |
---|
650 | var firstDashAdjust = ((numDash * dashPatLen) - (ystart - ystop))/2.0; |
---|
651 | var b=ystart, e, bs, es; |
---|
652 | for (var i=0; i<numDash; i++) { |
---|
653 | for (var j=0; j<dashPat.length; j+=2) { |
---|
654 | e = b - dashPat[j]; |
---|
655 | if (e < ystop) { |
---|
656 | e = ystop; |
---|
657 | } |
---|
658 | if (b < ystop) { |
---|
659 | b = ystop; |
---|
660 | } |
---|
661 | // es = e; |
---|
662 | // if (i == 0) { |
---|
663 | // es += firstDashAdjust; |
---|
664 | // } |
---|
665 | mr.draw([x, b], [x, e], this.canvas._ctx, opts); |
---|
666 | b -= dashPat[j]; |
---|
667 | if (j < dashPat.length-1) { |
---|
668 | b -= dashPat[j+1]; |
---|
669 | } |
---|
670 | } |
---|
671 | } |
---|
672 | } |
---|
673 | } |
---|
674 | break; |
---|
675 | |
---|
676 | default: |
---|
677 | break; |
---|
678 | } |
---|
679 | } |
---|
680 | } |
---|
681 | } |
---|
682 | }; |
---|
683 | |
---|
684 | // called within context of plot |
---|
685 | // create a canvas which we can draw on. |
---|
686 | // insert it before the eventCanvas, so eventCanvas will still capture events. |
---|
687 | $.jqplot.CanvasOverlay.postPlotDraw = function() { |
---|
688 | // Memory Leaks patch |
---|
689 | if (this.plugins.canvasOverlay && this.plugins.canvasOverlay.highlightCanvas) { |
---|
690 | this.plugins.canvasOverlay.highlightCanvas.resetCanvas(); |
---|
691 | this.plugins.canvasOverlay.highlightCanvas = null; |
---|
692 | } |
---|
693 | this.plugins.canvasOverlay.canvas = new $.jqplot.GenericCanvas(); |
---|
694 | |
---|
695 | this.eventCanvas._elem.before(this.plugins.canvasOverlay.canvas.createElement(this._gridPadding, 'jqplot-overlayCanvas-canvas', this._plotDimensions, this)); |
---|
696 | this.plugins.canvasOverlay.canvas.setContext(); |
---|
697 | if (!this.plugins.canvasOverlay.deferDraw) { |
---|
698 | this.plugins.canvasOverlay.draw(this); |
---|
699 | } |
---|
700 | }; |
---|
701 | |
---|
702 | $.jqplot.postInitHooks.push($.jqplot.CanvasOverlay.postPlotInit); |
---|
703 | $.jqplot.postDrawHooks.push($.jqplot.CanvasOverlay.postPlotDraw); |
---|
704 | |
---|
705 | })(jQuery); |
---|