egroupware/phpgwapi/js/jquery/jqplot/plugins/jqplot.dateAxisRenderer.min.js

57 lines
8.6 KiB
JavaScript
Raw Normal View History

2011-08-10 01:10:50 +02:00
/**
* jqPlot
* Pure JavaScript plotting plugin using jQuery
*
* Version: 1.0.0b2_r947
2011-08-10 01:10:50 +02:00
*
* 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."
*
* included jsDate library by Chris Leonello:
*
* Copyright (c) 2010-2011 Chris Leonello
*
* jsDate is currently available for use in all personal or commercial projects
* under both the MIT and GPL version 2.0 licenses. This means that you can
* choose the license that best suits your project and use it accordingly.
*
* jsDate borrows many concepts and ideas from the Date Instance
* Methods by Ken Snyder along with some parts of Ken's actual code.
*
* Ken's origianl Date Instance Methods and copyright notice:
*
* Ken Snyder (ken d snyder at gmail dot com)
* 2008-09-10
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
*
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
* Larry has generously given permission to adapt his code for inclusion
* into jqPlot.
*
* Larry's original code can be found here:
*
* https://github.com/lsiden/export-jqplot-to-png
*
2011-08-10 01:10:50 +02:00
*
*/
(function(a){a.jqplot.DateAxisRenderer=function(){a.jqplot.LinearAxisRenderer.call(this);this.date=new a.jsDate()};a.jqplot.DateAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.DateAxisRenderer.prototype.constructor=a.jqplot.DateAxisRenderer;a.jqplot.DateTickFormatter=function(b,c){if(!b){b="%Y/%m/%d"}return a.jsDate.strftime(c,b)};a.jqplot.DateAxisRenderer.prototype.init=function(w){this.tickOptions.formatter=a.jqplot.DateTickFormatter;this.tickInset=0;this.drawBaseline=true;this.baselineWidth=null;this.baselineColor=null;this.daTickInterval=null;this._daTickInterval=null;a.extend(true,this,w);var u=this._dataBounds,h,o,v,p,r,q,b;for(var g=0;g<this._series.length;g++){h={intervals:[],frequencies:{},sortedIntervals:[],min:null,max:null,mean:null};o=0;v=this._series[g];p=v.data;r=v._plotData;q=v._stackData;b=0;for(var f=0;f<p.length;f++){if(this.name=="xaxis"||this.name=="x2axis"){p[f][0]=new a.jsDate(p[f][0]).getTime();r[f][0]=new a.jsDate(p[f][0]).getTime();q[f][0]=new a.jsDate(p[f][0]).getTime();if((p[f][0]!=null&&p[f][0]<u.min)||u.min==null){u.min=p[f][0]}if((p[f][0]!=null&&p[f][0]>u.max)||u.max==null){u.max=p[f][0]}if(f>0){b=Math.abs(p[f][0]-p[f-1][0]);h.intervals.push(b);if(h.frequencies.hasOwnProperty(b)){h.frequencies[b]+=1}else{h.frequencies[b]=1}}o+=b}else{p[f][1]=new a.jsDate(p[f][1]).getTime();r[f][1]=new a.jsDate(p[f][1]).getTime();q[f][1]=new a.jsDate(p[f][1]).getTime();if((p[f][1]!=null&&p[f][1]<u.min)||u.min==null){u.min=p[f][1]}if((p[f][1]!=null&&p[f][1]>u.max)||u.max==null){u.max=p[f][1]}if(f>0){b=Math.abs(p[f][1]-p[f-1][1]);h.intervals.push(b);if(h.frequencies.hasOwnProperty(b)){h.frequencies[b]+=1}else{h.frequencies[b]=1}}}o+=b}if(v.renderer.bands){if(v.renderer.bands.hiData.length){var m=v.renderer.bands.hiData;for(var f=0,e=m.length;f<e;f++){if(this.name==="xaxis"||this.name==="x2axis"){m[f][0]=new a.jsDate(m[f][0]).getTime();if((m[f][0]!=null&&m[f][0]>u.max)||u.max==null){u.max=m[f][0]}}else{m[f][1]=new a.jsDate(m[f][1]).getTime();if((m[f][1]!=null&&m[f][1]>u.max)||u.max==null){u.max=m[f][1]}}}}if(v.renderer.bands.lowData.length){var m=v.renderer.bands.lowData;for(var f=0,e=m.length;f<e;f++){if(this.name==="xaxis"||this.name==="x2axis"){m[f][0]=new a.jsDate(m[f][0]).getTime();if((m[f][0]!=null&&m[f][0]<u.min)||u.min==null){u.min=m[f][0]}}else{m[f][1]=new a.jsDate(m[f][1]).getTime();if((m[f][1]!=null&&m[f][1]<u.min)||u.min==null){u.min=m[f][1]}}}}}var t=0,k=0;for(var c in h.frequencies){h.sortedIntervals.push({interval:c,frequency:h.frequencies[c]})}h.sortedIntervals.sort(function(i,d){return d.frequency-i.frequency});h.min=a.jqplot.arrayMin(h.intervals);h.max=a.jqplot.arrayMax(h.intervals);h.mean=o/p.length;this._intervalStats.push(h);h=o=v=p=r=q=null}u=null};a.jqplot.DateAxisRenderer.prototype.reset=function(){this.min=this._options.min;this.max=this._options.max;this.tickInterval=this._options.tickInterval;this.numberTicks=this._options.numberTicks;this._autoFormatString="";if(this._overrideFormatString&&this.tickOptions&&this.tickOptions.formatString){this.tickOptions.formatString=""}this.daTickInterval=this._daTickInterval};a.jqplot.DateAxisRenderer.prototype.createTicks=function(){var z=this._ticks;var w=this.ticks;var B=this.name;var y=this._dataBounds;var e=this._intervalStats;var q,x;var o,s;var d,c;var b,u;o=((this.min!=null)?new a.jsDate(this.min).getTime():y.min);s=((this.max!=null)?new a.jsDate(this.max).getTime():y.max);var k=s-o;if(w.length){for(u=0;u<w.length;u++){var g=w[u];var j=new this.tickRenderer(this.tickOptions);if(g.constructor==Array){j.value=new a.jsDate(g[0]).getTime();j.label=g[1];if(!this.showTicks){j.showLabel=false;j.showMark=false}else{if(!this.showTickMarks){j.showMark=false}}j.setTick(j.value,this.name);this._ticks.push(j)}else{j.value=new a.jsDate(g).getTime();if(!this.showTicks){j.showLabel=false;j.showMark=false}else{if(!this.showTickMarks){j.showMark=false}}j.setTick(j.value,this.name);this._ticks.push(j)}}this.numberTicks=w.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value;this.daTickInterval=[(this.max-this.m