(function($) { /** * Class: $.jqplot.BoxplotRenderer * jqPlot Plugin to draw box plots . * * To use this plugin, include the renderer js file in * your source: * * > * * Then you set the renderer in the series options on your plot: * * > series: [{renderer:$.jqplot.BoxplotRenderer}] * * Data should be specified like so: * * > dat = [[sample_id, min, q1, median, q3, max], ...] * */ $.jqplot.BoxplotRenderer = function(){ // subclass line renderer to make use of some of its methods. $.jqplot.LineRenderer.call(this); // prop: boxWidth // Default will auto calculate based on plot width and number // of boxes displayed. this.boxWidth = 'auto'; this._boxMaxWidth = 100; // if 'auto', cap at this max // prop: lineWidth // The thickness of all lines drawn. Default is 1.5 pixels. this.lineWidth = 1.5; }; $.jqplot.BoxplotRenderer.prototype = new $.jqplot.LineRenderer(); $.jqplot.BoxplotRenderer.prototype.constructor = $.jqplot.BoxplotRenderer; // called with scope of series. $.jqplot.BoxplotRenderer.prototype.init = function(options) { this.lineWidth = options.lineWidth || this.renderer.lineWidth; $.jqplot.LineRenderer.prototype.init.call(this, options); // set the yaxis data bounds here to account for high and low values var db = this._yaxis._dataBounds; var d = this._plotData; for (var j=0, dj=d[j]; j db.max || db.max == null) db.max = dj[5]; } }; // called within scope of series. $.jqplot.BoxplotRenderer.prototype.draw = function(ctx, gd, options) { var d = this.data; var r = this.renderer; var xp = this._xaxis.series_u2p; var yp = this._yaxis.series_u2p; if (!options) options = {}; if (!('lineWidth' in options)) $.extend(true, options, {lineWidth: this.lineWidth}); var boxopts = $.extend(true, {}, options, {strokeRect: true}); var boxW = options.boxWidth || r.boxWidth; if (boxW == 'auto') boxW = Math.min(r._boxMaxWidth, 0.6 * ctx.canvas.width/d.length); var endW = boxW / 2; // min and max ticks are half the box width boxW -= this.lineWidth*2; ctx.save(); if (this.show) { for (var i=0, di=d[i]; i' + 'min:%s' + 'q1:%s' + 'med:%s' + 'q3:%s' + 'max:%s' + '' }; if (!options.highlighter) options.highlighter = {show: true}; if (options.highlighter.show) { for (opt in hldefaults) { if (!(opt in options.highlighter)) { options.highlighter[opt] = hldefaults[opt]; } } } }; $.jqplot.preInitHooks.push($.jqplot.BoxplotRenderer.checkOptions); })(jQuery);