/** * jqPlot * Pure JavaScript plotting plugin using jQuery * * Version: @VERSION * Revision: @REVISION * * Copyright (c) 2009-2013 Chris Leonello * jqPlot is currently available for use in all personal or commercial projects * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can * choose the license that best suits your project and use it accordingly. * * Although not required, the author would appreciate an email letting him * know of any substantial use of jqPlot. You can reach the author at: * chris at jqplot dot com or see http://www.jqplot.com/info.php . * * If you are feeling kind and generous, consider supporting the project by * making a donation at: http://www.jqplot.com/donate.php . * * sprintf functions contained in jqplot.sprintf.js by Ash Searle: * * version 2007.04.27 * author Ash Searle * http://hexmen.com/blog/2007/03/printf-sprintf/ * http://hexmen.com/js/sprintf.js * The author (Ash Searle) has placed this code in the public domain: * "This code is unrestricted: you are free to use it however you like." * */ (function($) { /** * class: $.jqplot.LogAxisRenderer * A plugin for a jqPlot to render a logarithmic axis. * * To use this renderer, include the plugin in your source * > * * and supply the appropriate options to your plot * * > {axes:{xaxis:{renderer:$.jqplot.LogAxisRenderer}}} **/ $.jqplot.LogAxisRenderer = function() { $.jqplot.LinearAxisRenderer.call(this); // prop: axisDefaults // Default properties which will be applied directly to the series. // // Group: Properties // // Properties // // base - the logarithmic base, commonly 2, 10 or Math.E // tickDistribution - Deprecated. "power" distribution of ticks // always used. Option has no effect. this.axisDefaults = { base : 10, tickDistribution :'power' }; }; $.jqplot.LogAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer(); $.jqplot.LogAxisRenderer.prototype.constructor = $.jqplot.LogAxisRenderer; $.jqplot.LogAxisRenderer.prototype.init = function(options) { // prop: drawBaseline // True to draw the axis baseline. this.drawBaseline = true; // prop: minorTicks // Number of ticks to add between "major" ticks. // Major ticks are ticks supplied by user or auto computed. // Minor ticks cannot be created by user. this.minorTicks = 'auto'; this._scalefact = 1.0; $.extend(true, this, options); this._autoFormatString = '%d'; this._overrideFormatString = false; for (var d in this.renderer.axisDefaults) { if (this[d] == null) { this[d] = this.renderer.axisDefaults[d]; } } this.resetDataBounds(); }; $.jqplot.LogAxisRenderer.prototype.createTicks = function(plot) { // we're are operating on an axis here var ticks = this._ticks; var userTicks = this.ticks; var name = this.name; var db = this._dataBounds; var dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height; var interval; var min, max; var pos1, pos2; var tt, i; var threshold = 30; // For some reason scalefactor is screwing up ticks. this._scalefact = (Math.max(dim, threshold+1) - threshold)/300; // if we already have ticks, use them. // ticks must be in order of increasing value. if (userTicks.length) { // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed for (i=0; i 140) { numberTicks = Math.round(Math.log(this.max/this.min)/Math.log(this.base) + 1); if (numberTicks < 2) { numberTicks = 2; } if (minorTicks === 0) { var temp = dim/(numberTicks - 1); if (temp < 100) { minorTicks = 0; } else if (temp < 190) { minorTicks = 1; } else if (temp < 250) { minorTicks = 3; } else if (temp < 600) { minorTicks = 4; } else { minorTicks = 9; } } } else { numberTicks = 2; if (minorTicks === 0) { minorTicks = 1; } minorTicks = 0; } } else { numberTicks = this.numberTicks; } if (order >= 0 && minorTicks !== 3) { this._autoFormatString = '%d'; } // Adjust format string for case with 3 ticks where we'll have like 1, 2.5, 5, 7.5, 10 else if (order <= 0 && minorTicks === 3) { var temp = -(order - 1); this._autoFormatString = '%.'+ Math.abs(order-1) + 'f'; } // Adjust format string for values less than 1. else if (order < 0) { var temp = -order; this._autoFormatString = '%.'+ Math.abs(order) + 'f'; } else { this._autoFormatString = '%d'; } var to, t, val, tt1, spread, interval; for (var i=0; i=0; j--) { val = tt1-interval*(j+1); t = new this.tickRenderer(this.tickOptions); if (this._overrideFormatString && this._autoFormatString != '') { t.formatString = this._autoFormatString; } if (!this.showTicks) { t.showLabel = false; t.showMark = false; } else if (!this.showTickMarks) { t.showMark = false; } t.setTick(val, this.name); this._ticks.push(t); } } } } // min and max are set as would be the case with zooming else if (this.min != null && this.max != null) { var opts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null}); var nt, ti; // don't have an interval yet, pick one that gives the most // "round" ticks we can get. if (this.numberTicks == null && this.tickInterval == null) { // var threshold = 30; var tdim = Math.max(dim, threshold+1); var nttarget = Math.ceil((tdim-threshold)/35 + 1); var ret = $.jqplot.LinearTickGenerator.bestConstrainedInterval(this.min, this.max, nttarget); this._autoFormatString = ret[3]; nt = ret[2]; ti = ret[4]; for (var i=0; i 0) { shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2; } else { shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2; } break; case 'middle': // if (t.angle > 0) { // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2; // } // else { // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2; // } shim = -t.getHeight()/2; break; default: shim = -t.getHeight()/2; break; } } else { shim = -t.getHeight()/2; } var val = this.u2p(t.value) + shim + 'px'; t._elem.css('top', val); t.pack(); } } if (lshow) { var h = this._label._elem.outerHeight(true); this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px'); if (this.name == 'yaxis') { this._label._elem.css('left', '0px'); } else { this._label._elem.css('right', '0px'); } this._label.pack(); } } } }; })(jQuery);