/** * jqPlot * Pure JavaScript plotting plugin using jQuery * * Version: 1.0.0b2_r792 * * Copyright (c) 2009-2011 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.DateAxisRenderer * A plugin for a jqPlot to render an axis as a series of date values. * This renderer has no options beyond those supplied by the class. * It supplies it's own tick formatter, so the tickOptions.formatter option * should not be overridden. * * Thanks to Ken Synder for his enhanced Date instance methods which are * included with this code . * * To use this renderer, include the plugin in your source * > * * and supply the appropriate options to your plot * * > {axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}} * * Dates can be passed into the axis in almost any recognizable value and * will be parsed. They will be rendered on the axis in the format * specified by tickOptions.formatString. e.g. tickOptions.formatString = '%Y-%m-%d'. * * Accecptable format codes * are: * * > Code Result Description * > == Years == * > %Y 2008 Four-digit year * > %y 08 Two-digit year * > == Months == * > %m 09 Two-digit month * > %#m 9 One or two-digit month * > %B September Full month name * > %b Sep Abbreviated month name * > == Days == * > %d 05 Two-digit day of month * > %#d 5 One or two-digit day of month * > %e 5 One or two-digit day of month * > %A Sunday Full name of the day of the week * > %a Sun Abbreviated name of the day of the week * > %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday) * > %o th The ordinal suffix string following the day of the month * > == Hours == * > %H 23 Hours in 24-hour format (two digits) * > %#H 3 Hours in 24-hour integer format (one or two digits) * > %I 11 Hours in 12-hour format (two digits) * > %#I 3 Hours in 12-hour integer format (one or two digits) * > %p PM AM or PM * > == Minutes == * > %M 09 Minutes (two digits) * > %#M 9 Minutes (one or two digits) * > == Seconds == * > %S 02 Seconds (two digits) * > %#S 2 Seconds (one or two digits) * > %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00) * > == Milliseconds == * > %N 008 Milliseconds (three digits) * > %#N 8 Milliseconds (one to three digits) * > == Timezone == * > %O 360 difference in minutes between local time and GMT * > %Z Mountain Standard Time Name of timezone as reported by browser * > %G -06:00 Hours and minutes between GMT * > == Shortcuts == * > %F 2008-03-26 %Y-%m-%d * > %T 05:06:30 %H:%M:%S * > %X 05:06:30 %H:%M:%S * > %x 03/26/08 %m/%d/%y * > %D 03/26/08 %m/%d/%y * > %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y * > %v 3-Sep-2008 %e-%b-%Y * > %R 15:31 %H:%M * > %r 3:31:00 PM %I:%M:%S %p * > == Characters == * > %n \n Newline * > %t \t Tab * > %% % Percent Symbol */ $.jqplot.DateAxisRenderer = function() { $.jqplot.LinearAxisRenderer.call(this); this.date = new $.jsDate(); }; $.jqplot.DateAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer(); $.jqplot.DateAxisRenderer.prototype.constructor = $.jqplot.DateAxisRenderer; $.jqplot.DateTickFormatter = function(format, val) { if (!format) { format = '%Y/%m/%d'; } return $.jsDate.strftime(val, format); }; $.jqplot.DateAxisRenderer.prototype.init = function(options){ // prop: tickRenderer // A class of a rendering engine for creating the ticks labels displayed on the plot, // See <$.jqplot.AxisTickRenderer>. // this.tickRenderer = $.jqplot.AxisTickRenderer; // this.labelRenderer = $.jqplot.AxisLabelRenderer; this.tickOptions.formatter = $.jqplot.DateTickFormatter; this.daTickInterval = null; this._daTickInterval = null; $.extend(true, this, options); var db = this._dataBounds, stats, sum, s, d, pd, sd, intv; // Go through all the series attached to this axis and find // the min/max bounds for this axis. for (var i=0; i db.max) || db.max == null) { db.max = d[j][0]; } if (j>0) { intv = Math.abs(d[j][0] - d[j-1][0]); stats.intervals.push(intv); if (stats.frequencies.hasOwnProperty(intv)) { stats.frequencies[intv] += 1; } else { stats.frequencies[intv] = 1; } } sum += intv; } else { d[j][1] = new $.jsDate(d[j][1]).getTime(); pd[j][1] = new $.jsDate(d[j][1]).getTime(); sd[j][1] = new $.jsDate(d[j][1]).getTime(); if ((d[j][1] != null && d[j][1] < db.min) || db.min == null) { db.min = d[j][1]; } if ((d[j][1] != null && d[j][1] > db.max) || db.max == null) { db.max = d[j][1]; } if (j>0) { intv = Math.abs(d[j][1] - d[j-1][1]); stats.intervals.push(intv); if (stats.frequencies.hasOwnProperty(intv)) { stats.frequencies[intv] += 1; } else { stats.frequencies[intv] = 1; } } } sum += intv; } var tempf = 0, tempn=0; for (var n in stats.frequencies) { stats.sortedIntervals.push({interval:n, frequency:stats.frequencies[n]}); } stats.sortedIntervals.sort(function(a, b){ return b.frequency - a.frequency; }); stats.min = $.jqplot.arrayMin(stats.intervals); stats.max = $.jqplot.arrayMax(stats.intervals); stats.mean = sum/d.length; this._intervalStats.push(stats); stats = sum = s = d = pd = sd = null; } db = null; }; // called with scope of an axis $.jqplot.DateAxisRenderer.prototype.reset = function() { this.min = this._min; this.max = this._max; this.tickInterval = this._tickInterval; this.numberTicks = this._numberTicks; this.daTickInterval = this._daTickInterval; // this._ticks = this.__ticks; }; $.jqplot.DateAxisRenderer.prototype.createTicks = function() { // we're are operating on an axis here var ticks = this._ticks; var userTicks = this.ticks; var name = this.name; // databounds were set on axis initialization. var db = this._dataBounds; var iv = this._intervalStats; var dim, interval; var min, max; var pos1, pos2; var tt, i; // if we already have ticks, use them. // ticks must be in order of increasing value. min = ((this.min != null) ? new $.jsDate(this.min).getTime() : db.min); max = ((this.max != null) ? new $.jsDate(this.max).getTime() : db.max); var range = max - min; if (userTicks.length) { // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed for (i=0; i= tumax) { tumin = min - range*(this.padMin - 1); tumax = max + range*(this.padMax - 1); ret = $.jqplot.LinearTickGenerator(tumin, tumax); } this.min = ret[0]; this.max = ret[1]; this.numberTicks = ret[2]; this.tickInterval = ret[4]; this.daTickInterval = [this.tickInterval/1000, 'seconds']; for (var i=0; i 200) { this.numberTicks = parseInt(3+(dim-200)/100, 10); } else { this.numberTicks = 2; } } if (this.daTickInterval == null) { this.daTickInterval = [range / (this.numberTicks-1)/1000, 'seconds']; } for (var i=0; i