[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/jquery/jqplot/plugins/ -> jqplot.dateAxisRenderer.js (source)

   1  /**
   2   * jqPlot
   3   * Pure JavaScript plotting plugin using jQuery
   4   *
   5   * Version: 1.0.2
   6   * Revision: 1108
   7   *
   8   * Copyright (c) 2009-2011 Chris Leonello
   9   * jqPlot is currently available for use in all personal or commercial projects 
  10   * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL 
  11   * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can 
  12   * choose the license that best suits your project and use it accordingly. 
  13   *
  14   * Although not required, the author would appreciate an email letting him 
  15   * know of any substantial use of jqPlot.  You can reach the author at: 
  16   * chris at jqplot dot com or see http://www.jqplot.com/info.php .
  17   *
  18   * If you are feeling kind and generous, consider supporting the project by
  19   * making a donation at: http://www.jqplot.com/donate.php .
  20   *
  21   * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  22   *
  23   *     version 2007.04.27
  24   *     author Ash Searle
  25   *     http://hexmen.com/blog/2007/03/printf-sprintf/
  26   *     http://hexmen.com/js/sprintf.js
  27   *     The author (Ash Searle) has placed this code in the public domain:
  28   *     "This code is unrestricted: you are free to use it however you like."
  29   * 
  30   */
  31  (function($) {  
  32      /**
  33       * Class: $.jqplot.DateAxisRenderer
  34       * A plugin for a jqPlot to render an axis as a series of date values.
  35       * This renderer has no options beyond those supplied by the <Axis> class.
  36       * It supplies it's own tick formatter, so the tickOptions.formatter option
  37       * should not be overridden.
  38       * 
  39       * Thanks to Ken Synder for his enhanced Date instance methods which are
  40       * included with this code <http://kendsnyder.com/sandbox/date/>.
  41       * 
  42       * To use this renderer, include the plugin in your source
  43       * > <script type="text/javascript" language="javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
  44       * 
  45       * and supply the appropriate options to your plot
  46       * 
  47       * > {axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}}
  48       * 
  49       * Dates can be passed into the axis in almost any recognizable value and 
  50       * will be parsed.  They will be rendered on the axis in the format
  51       * specified by tickOptions.formatString.  e.g. tickOptions.formatString = '%Y-%m-%d'.
  52       * 
  53       * Accecptable format codes 
  54       * are:
  55       * 
  56       * > Code    Result                  Description
  57       * >             == Years ==
  58       * > %Y      2008                Four-digit year
  59       * > %y      08                  Two-digit year
  60       * >             == Months ==
  61       * > %m      09                  Two-digit month
  62       * > %#m     9                   One or two-digit month
  63       * > %B      September           Full month name
  64       * > %b      Sep                 Abbreviated month name
  65       * >             == Days ==
  66       * > %d      05                  Two-digit day of month
  67       * > %#d     5                   One or two-digit day of month
  68       * > %e      5                   One or two-digit day of month
  69       * > %A      Sunday              Full name of the day of the week
  70       * > %a      Sun                 Abbreviated name of the day of the week
  71       * > %w      0                   Number of the day of the week (0 = Sunday, 6 = Saturday)
  72       * > %o      th                  The ordinal suffix string following the day of the month
  73       * >             == Hours ==
  74       * > %H      23                  Hours in 24-hour format (two digits)
  75       * > %#H     3                   Hours in 24-hour integer format (one or two digits)
  76       * > %I      11                  Hours in 12-hour format (two digits)
  77       * > %#I     3                   Hours in 12-hour integer format (one or two digits)
  78       * > %p      PM                  AM or PM
  79       * >             == Minutes ==
  80       * > %M      09                  Minutes (two digits)
  81       * > %#M     9                   Minutes (one or two digits)
  82       * >             == Seconds ==
  83       * > %S      02                  Seconds (two digits)
  84       * > %#S     2                   Seconds (one or two digits)
  85       * > %s      1206567625723       Unix timestamp (Seconds past 1970-01-01 00:00:00)
  86       * >             == Milliseconds ==
  87       * > %N      008                 Milliseconds (three digits)
  88       * > %#N     8                   Milliseconds (one to three digits)
  89       * >             == Timezone ==
  90       * > %O      360                 difference in minutes between local time and GMT
  91       * > %Z      Mountain Standard Time  Name of timezone as reported by browser
  92       * > %G      -06:00              Hours and minutes between GMT
  93       * >             == Shortcuts ==
  94       * > %F      2008-03-26          %Y-%m-%d
  95       * > %T      05:06:30            %H:%M:%S
  96       * > %X      05:06:30            %H:%M:%S
  97       * > %x      03/26/08            %m/%d/%y
  98       * > %D      03/26/08            %m/%d/%y
  99       * > %#c     Wed Mar 26 15:31:00 2008  %a %b %e %H:%M:%S %Y
 100       * > %v      3-Sep-2008          %e-%b-%Y
 101       * > %R      15:31               %H:%M
 102       * > %r      3:31:00 PM          %I:%M:%S %p
 103       * >             == Characters ==
 104       * > %n      \n                  Newline
 105       * > %t      \t                  Tab
 106       * > %%      %                   Percent Symbol 
 107       */
 108      $.jqplot.DateAxisRenderer = function() {
 109          $.jqplot.LinearAxisRenderer.call(this);
 110          this.date = new $.jsDate();
 111      };
 112  
 113      var second = 1000;
 114      var minute = 60 * second;
 115      var hour = 60 * minute;
 116      var day = 24 * hour;
 117      var week = 7 * day;
 118  
 119      // these are less definitive
 120      var month = 30.4368499 * day;
 121      var year = 365.242199 * day;
 122  
 123      var daysInMonths = [31,28,31,30,31,30,31,30,31,30,31,30];
 124      // array of consistent nice intervals.  Longer intervals
 125      // will depend on days in month, days in year, etc.
 126      var niceFormatStrings = ['%M:%S.%#N', '%M:%S.%#N', '%M:%S.%#N', '%M:%S', '%M:%S', '%M:%S', '%M:%S', '%H:%M:%S', '%H:%M:%S', '%H:%M', '%H:%M', '%H:%M', '%H:%M', '%H:%M', '%H:%M', '%a %H:%M', '%a %H:%M', '%b %e %H:%M', '%b %e %H:%M', '%b %e %H:%M', '%b %e %H:%M', '%v', '%v', '%v', '%v', '%v', '%v', '%v'];
 127      var niceIntervals = [0.1*second, 0.2*second, 0.5*second, second, 2*second, 5*second, 10*second, 15*second, 30*second, minute, 2*minute, 5*minute, 10*minute, 15*minute, 30*minute, hour, 2*hour, 4*hour, 6*hour, 8*hour, 12*hour, day, 2*day, 3*day, 4*day, 5*day, week, 2*week];
 128  
 129      var niceMonthlyIntervals = [];
 130  
 131      function bestDateInterval(min, max, titarget) {
 132          // iterate through niceIntervals to find one closest to titarget
 133          var badness = Number.MAX_VALUE;
 134          var temp, bestTi, bestfmt;
 135          for (var i=0, l=niceIntervals.length; i < l; i++) {
 136              temp = Math.abs(titarget - niceIntervals[i]);
 137              if (temp < badness) {
 138                  badness = temp;
 139                  bestTi = niceIntervals[i];
 140                  bestfmt = niceFormatStrings[i];
 141              }
 142          }
 143  
 144          return [bestTi, bestfmt];
 145      }
 146      
 147      $.jqplot.DateAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
 148      $.jqplot.DateAxisRenderer.prototype.constructor = $.jqplot.DateAxisRenderer;
 149      
 150      $.jqplot.DateTickFormatter = function(format, val) {
 151          if (!format) {
 152              format = '%Y/%m/%d';
 153          }
 154          return $.jsDate.strftime(val, format);
 155      };
 156      
 157      $.jqplot.DateAxisRenderer.prototype.init = function(options){
 158          // prop: tickRenderer
 159          // A class of a rendering engine for creating the ticks labels displayed on the plot, 
 160          // See <$.jqplot.AxisTickRenderer>.
 161          // this.tickRenderer = $.jqplot.AxisTickRenderer;
 162          // this.labelRenderer = $.jqplot.AxisLabelRenderer;
 163          this.tickOptions.formatter = $.jqplot.DateTickFormatter;
 164          // prop: tickInset
 165          // Controls the amount to inset the first and last ticks from 
 166          // the edges of the grid, in multiples of the tick interval.
 167          // 0 is no inset, 0.5 is one half a tick interval, 1 is a full
 168          // tick interval, etc.
 169          this.tickInset = 0;
 170          // prop: drawBaseline
 171          // True to draw the axis baseline.
 172          this.drawBaseline = true;
 173          // prop: baselineWidth
 174          // width of the baseline in pixels.
 175          this.baselineWidth = null;
 176          // prop: baselineColor
 177          // CSS color spec for the baseline.
 178          this.baselineColor = null;
 179          this.daTickInterval = null;
 180          this._daTickInterval = null;
 181          
 182          $.extend(true, this, options);
 183          
 184          var db = this._dataBounds,
 185              stats, 
 186              sum,
 187              s,
 188              d,
 189              pd,
 190              sd,
 191              intv;
 192          
 193          // Go through all the series attached to this axis and find
 194          // the min/max bounds for this axis.
 195          for (var i=0; i<this._series.length; i++) {
 196              stats = {intervals:[], frequencies:{}, sortedIntervals:[], min:null, max:null, mean:null};
 197              sum = 0;
 198              s = this._series[i];
 199              d = s.data;
 200              pd = s._plotData;
 201              sd = s._stackData;
 202              intv = 0;
 203              
 204              for (var j=0; j<d.length; j++) { 
 205                  if (this.name == 'xaxis' || this.name == 'x2axis') {
 206                      d[j][0] = new $.jsDate(d[j][0]).getTime();
 207                      pd[j][0] = new $.jsDate(d[j][0]).getTime();
 208                      sd[j][0] = new $.jsDate(d[j][0]).getTime();
 209                      if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
 210                          db.min = d[j][0];
 211                      }
 212                      if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
 213                          db.max = d[j][0];
 214                      }
 215                      if (j>0) {
 216                          intv = Math.abs(d[j][0] - d[j-1][0]);
 217                          stats.intervals.push(intv);
 218                          if (stats.frequencies.hasOwnProperty(intv)) {
 219                              stats.frequencies[intv] += 1;
 220                          }
 221                          else {
 222                              stats.frequencies[intv] = 1;
 223                          }
 224                      }
 225                      sum += intv;
 226                      
 227                  }              
 228                  else {
 229                      d[j][1] = new $.jsDate(d[j][1]).getTime();
 230                      pd[j][1] = new $.jsDate(d[j][1]).getTime();
 231                      sd[j][1] = new $.jsDate(d[j][1]).getTime();
 232                      if ((d[j][1] != null && d[j][1] < db.min) || db.min == null) {
 233                          db.min = d[j][1];
 234                      }
 235                      if ((d[j][1] != null && d[j][1] > db.max) || db.max == null) {
 236                          db.max = d[j][1];
 237                      }
 238                      if (j>0) {
 239                          intv = Math.abs(d[j][1] - d[j-1][1]);
 240                          stats.intervals.push(intv);
 241                          if (stats.frequencies.hasOwnProperty(intv)) {
 242                              stats.frequencies[intv] += 1;
 243                          }
 244                          else {
 245                              stats.frequencies[intv] = 1;
 246                          }
 247                      }
 248                  }
 249                  sum += intv;              
 250              }
 251  
 252              if (s.renderer.bands) {
 253                  if (s.renderer.bands.hiData.length) {
 254                      var bd = s.renderer.bands.hiData;
 255                      for (var j=0, l=bd.length; j < l; j++) {
 256                          if (this.name === 'xaxis' || this.name === 'x2axis') {
 257                              bd[j][0] = new $.jsDate(bd[j][0]).getTime();
 258                              if ((bd[j][0] != null && bd[j][0] > db.max) || db.max == null) {
 259                                  db.max = bd[j][0];
 260                              }                        
 261                          }              
 262                          else {
 263                              bd[j][1] = new $.jsDate(bd[j][1]).getTime();
 264                              if ((bd[j][1] != null && bd[j][1] > db.max) || db.max == null) {
 265                                  db.max = bd[j][1];
 266                              }
 267                          }
 268                      }
 269                  }
 270                  if (s.renderer.bands.lowData.length) {
 271                      var bd = s.renderer.bands.lowData;
 272                      for (var j=0, l=bd.length; j < l; j++) {
 273                          if (this.name === 'xaxis' || this.name === 'x2axis') {
 274                              bd[j][0] = new $.jsDate(bd[j][0]).getTime();
 275                              if ((bd[j][0] != null && bd[j][0] < db.min) || db.min == null) {
 276                                  db.min = bd[j][0];
 277                              }                       
 278                          }              
 279                          else {
 280                              bd[j][1] = new $.jsDate(bd[j][1]).getTime();
 281                              if ((bd[j][1] != null && bd[j][1] < db.min) || db.min == null) {
 282                                  db.min = bd[j][1];
 283                              }
 284                          }
 285                      }
 286                  }
 287              }
 288              
 289              var tempf = 0,
 290                  tempn=0;
 291              for (var n in stats.frequencies) {
 292                  stats.sortedIntervals.push({interval:n, frequency:stats.frequencies[n]});
 293              }
 294              stats.sortedIntervals.sort(function(a, b){
 295                  return b.frequency - a.frequency;
 296              });
 297              
 298              stats.min = $.jqplot.arrayMin(stats.intervals);
 299              stats.max = $.jqplot.arrayMax(stats.intervals);
 300              stats.mean = sum/d.length;
 301              this._intervalStats.push(stats);
 302              stats = sum = s = d = pd = sd = null;
 303          }
 304          db = null;
 305          
 306      };
 307      
 308      // called with scope of an axis
 309      $.jqplot.DateAxisRenderer.prototype.reset = function() {
 310          this.min = this._options.min;
 311          this.max = this._options.max;
 312          this.tickInterval = this._options.tickInterval;
 313          this.numberTicks = this._options.numberTicks;
 314          this._autoFormatString = '';
 315          if (this._overrideFormatString && this.tickOptions && this.tickOptions.formatString) {
 316              this.tickOptions.formatString = '';
 317          }
 318          this.daTickInterval = this._daTickInterval;
 319          // this._ticks = this.__ticks;
 320      };
 321      
 322      $.jqplot.DateAxisRenderer.prototype.createTicks = function(plot) {
 323          // we're are operating on an axis here
 324          var ticks = this._ticks;
 325          var userTicks = this.ticks;
 326          var name = this.name;
 327          // databounds were set on axis initialization.
 328          var db = this._dataBounds;
 329          var iv = this._intervalStats;
 330          var dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height;
 331          var interval;
 332          var min, max;
 333          var pos1, pos2;
 334          var tt, i;
 335          var threshold = 30;
 336          var insetMult = 1;
 337  
 338          var tickInterval = this.tickInterval;
 339          
 340          // if we already have ticks, use them.
 341          // ticks must be in order of increasing value.
 342          
 343          min = ((this.min != null) ? new $.jsDate(this.min).getTime() : db.min);
 344          max = ((this.max != null) ? new $.jsDate(this.max).getTime() : db.max);
 345  
 346          // see if we're zooming.  if we are, don't use the min and max we're given,
 347          // but compute some nice ones.  They will be reset later.
 348  
 349          var cursor = plot.plugins.cursor;
 350  
 351          if (cursor && cursor._zoom && cursor._zoom.zooming) {
 352              this.min = null;
 353              this.max = null;
 354          }
 355  
 356          var range = max - min;
 357  
 358          if (this.tickOptions == null || !this.tickOptions.formatString) {
 359              this._overrideFormatString = true;
 360          }
 361          
 362          if (userTicks.length) {
 363              // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
 364              for (i=0; i<userTicks.length; i++){
 365                  var ut = userTicks[i];
 366                  var t = new this.tickRenderer(this.tickOptions);
 367                  if (ut.constructor == Array) {
 368                      t.value = new $.jsDate(ut[0]).getTime();
 369                      t.label = ut[1];
 370                      if (!this.showTicks) {
 371                          t.showLabel = false;
 372                          t.showMark = false;
 373                      }
 374                      else if (!this.showTickMarks) {
 375                          t.showMark = false;
 376                      }
 377                      t.setTick(t.value, this.name);
 378                      this._ticks.push(t);
 379                  }
 380                  
 381                  else {
 382                      t.value = new $.jsDate(ut).getTime();
 383                      if (!this.showTicks) {
 384                          t.showLabel = false;
 385                          t.showMark = false;
 386                      }
 387                      else if (!this.showTickMarks) {
 388                          t.showMark = false;
 389                      }
 390                      t.setTick(t.value, this.name);
 391                      this._ticks.push(t);
 392                  }
 393              }
 394              this.numberTicks = userTicks.length;
 395              this.min = this._ticks[0].value;
 396              this.max = this._ticks[this.numberTicks-1].value;
 397              this.daTickInterval = [(this.max - this.min) / (this.numberTicks - 1)/1000, 'seconds'];
 398          }
 399  
 400          ////////
 401          // We don't have any ticks yet, let's make some!
 402          ////////
 403  
 404          // special case when there is only one point, make three tick marks to center the point
 405          else if (this.min == null && this.max == null && db.min == db.max)
 406          {
 407               var onePointOpts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null});
 408               var delta = 300000;
 409               this.min = db.min - delta;
 410               this.max = db.max + delta;
 411               this.numberTicks = 3;
 412  
 413               for(var i=this.min;i<=this.max;i+= delta)
 414               {
 415                   onePointOpts.value = i;
 416  
 417                   var t = new this.tickRenderer(onePointOpts);
 418  
 419                   if (this._overrideFormatString && this._autoFormatString != '') {
 420                      t.formatString = this._autoFormatString;
 421                   }
 422  
 423                   t.showLabel = false;
 424                   t.showMark = false;
 425  
 426                   this._ticks.push(t);
 427               }
 428  
 429               if(this.showTicks) {
 430                   this._ticks[1].showLabel = true;
 431               }
 432               if(this.showTickMarks) {
 433                   this._ticks[1].showTickMarks = true;
 434               }                   
 435          }
 436          // if user specified min and max are null, we set those to make best ticks.
 437          else if (this.min == null && this.max == null) {
 438  
 439              var opts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null});
 440  
 441              // want to find a nice interval 
 442              var nttarget,
 443                  titarget;
 444  
 445              // if no tickInterval or numberTicks options specified,  make a good guess.
 446              if (!this.tickInterval && !this.numberTicks) {
 447                  var tdim = Math.max(dim, threshold+1);
 448                  // how many ticks to put on the axis?
 449                  // date labels tend to be long.  If ticks not rotated,
 450                  // don't use too many and have a high spacing factor.
 451                  // If we are rotating ticks, use a lower factor.
 452                  var spacingFactor = 115;
 453                  if (this.tickRenderer === $.jqplot.CanvasAxisTickRenderer && this.tickOptions.angle) {
 454                      spacingFactor = 115 - 40 * Math.abs(Math.sin(this.tickOptions.angle/180*Math.PI));
 455                  }
 456  
 457                  nttarget =  Math.ceil((tdim-threshold)/spacingFactor + 1);
 458                  titarget = (max - min) / (nttarget - 1);
 459              }
 460  
 461              // If tickInterval is specified, we'll try to honor it.
 462              // Not gauranteed to get this interval, but we'll get as close as
 463              // we can.
 464              // tickInterval will be used before numberTicks, that is if
 465              // both are specified, numberTicks will be ignored.
 466              else if (this.tickInterval) {
 467                  titarget = this.tickInterval;
 468              }
 469  
 470              // if numberTicks specified, try to honor it.
 471              // Not gauranteed, but will try to get close.
 472              else if (this.numberTicks) {
 473                  nttarget = this.numberTicks;
 474                  titarget = (max - min) / (nttarget - 1);
 475              }
 476  
 477              // If we can use an interval of 2 weeks or less, pick best one
 478              if (titarget <= 19*day) {
 479                  var ret = bestDateInterval(min, max, titarget);
 480                  var tempti = ret[0];
 481                  this._autoFormatString = ret[1];
 482  
 483                  min = Math.floor(min/tempti) * tempti;
 484                  min = new $.jsDate(min);
 485                  min = min.getTime() + min.getUtcOffset();
 486  
 487                  nttarget = Math.ceil((max - min) / tempti) + 1;
 488                  this.min = min;
 489                  this.max = min + (nttarget - 1) * tempti;
 490  
 491                  // if max is less than max, add an interval
 492                  if (this.max < max) {
 493                      this.max += tempti;
 494                      nttarget += 1;
 495                  }
 496                  this.tickInterval = tempti;
 497                  this.numberTicks = nttarget;
 498  
 499                  for (var i=0; i<nttarget; i++) {
 500                      opts.value = this.min + i * tempti;
 501                      t = new this.tickRenderer(opts);
 502                      
 503                      if (this._overrideFormatString && this._autoFormatString != '') {
 504                          t.formatString = this._autoFormatString;
 505                      }
 506                      if (!this.showTicks) {
 507                          t.showLabel = false;
 508                          t.showMark = false;
 509                      }
 510                      else if (!this.showTickMarks) {
 511                          t.showMark = false;
 512                      }
 513                      this._ticks.push(t);
 514                  }
 515  
 516                  insetMult = this.tickInterval;
 517              }
 518  
 519              // should we use a monthly interval?
 520              else if (titarget <= 9 * month) {
 521  
 522                  this._autoFormatString = '%v';
 523  
 524                  // how many months in an interval?
 525                  var intv = Math.round(titarget/month);
 526                  if (intv < 1) {
 527                      intv = 1;
 528                  }
 529                  else if (intv > 6) {
 530                      intv = 6;
 531                  }
 532  
 533                  // figure out the starting month and ending month.
 534                  var mstart = new $.jsDate(min).setDate(1).setHours(0,0,0,0);
 535  
 536                  // See if max ends exactly on a month
 537                  var tempmend = new $.jsDate(max);
 538                  var mend = new $.jsDate(max).setDate(1).setHours(0,0,0,0);
 539  
 540                  if (tempmend.getTime() !== mend.getTime()) {
 541                      mend = mend.add(1, 'month');
 542                  }
 543  
 544                  var nmonths = mend.diff(mstart, 'month');
 545  
 546                  nttarget = Math.ceil(nmonths/intv) + 1;
 547  
 548                  this.min = mstart.getTime();
 549                  this.max = mstart.clone().add((nttarget - 1) * intv, 'month').getTime();
 550                  this.numberTicks = nttarget;
 551  
 552                  for (var i=0; i<nttarget; i++) {
 553                      if (i === 0) {
 554                          opts.value = mstart.getTime();
 555                      }
 556                      else {
 557                          opts.value = mstart.add(intv, 'month').getTime();
 558                      }
 559                      t = new this.tickRenderer(opts);
 560                      
 561                      if (this._overrideFormatString && this._autoFormatString != '') {
 562                          t.formatString = this._autoFormatString;
 563                      }
 564                      if (!this.showTicks) {
 565                          t.showLabel = false;
 566                          t.showMark = false;
 567                      }
 568                      else if (!this.showTickMarks) {
 569                          t.showMark = false;
 570                      }
 571                      this._ticks.push(t);
 572                  }
 573  
 574                  insetMult = intv * month;
 575              }
 576  
 577              // use yearly intervals
 578              else {
 579  
 580                  this._autoFormatString = '%v';
 581  
 582                  // how many years in an interval?
 583                  var intv = Math.round(titarget/year);
 584                  if (intv < 1) {
 585                      intv = 1;
 586                  }
 587  
 588                  // figure out the starting and ending years.
 589                  var mstart = new $.jsDate(min).setMonth(0, 1).setHours(0,0,0,0);
 590                  var mend = new $.jsDate(max).add(1, 'year').setMonth(0, 1).setHours(0,0,0,0);
 591  
 592                  var nyears = mend.diff(mstart, 'year');
 593  
 594                  nttarget = Math.ceil(nyears/intv) + 1;
 595  
 596                  this.min = mstart.getTime();
 597                  this.max = mstart.clone().add((nttarget - 1) * intv, 'year').getTime();
 598                  this.numberTicks = nttarget;
 599  
 600                  for (var i=0; i<nttarget; i++) {
 601                      if (i === 0) {
 602                          opts.value = mstart.getTime();
 603                      }
 604                      else {
 605                          opts.value = mstart.add(intv, 'year').getTime();
 606                      }
 607                      t = new this.tickRenderer(opts);
 608                      
 609                      if (this._overrideFormatString && this._autoFormatString != '') {
 610                          t.formatString = this._autoFormatString;
 611                      }
 612                      if (!this.showTicks) {
 613                          t.showLabel = false;
 614                          t.showMark = false;
 615                      }
 616                      else if (!this.showTickMarks) {
 617                          t.showMark = false;
 618                      }
 619                      this._ticks.push(t);
 620                  }
 621  
 622                  insetMult = intv * year;
 623              }
 624          }
 625  
 626          ////////
 627          // Some option(s) specified, work around that.
 628          ////////
 629          
 630          else {      
 631              if (name == 'xaxis' || name == 'x2axis') {
 632                  dim = this._plotDimensions.width;
 633              }
 634              else {
 635                  dim = this._plotDimensions.height;
 636              }
 637              
 638              // if min, max and number of ticks specified, user can't specify interval.
 639              if (this.min != null && this.max != null && this.numberTicks != null) {
 640                  this.tickInterval = null;
 641              }
 642              
 643              // if user specified a tick interval, convert to usable.
 644              if (this.tickInterval != null)
 645              {
 646                  // if interval is a number or can be converted to one, use it.
 647                  // Assume it is in SECONDS!!!
 648                  if (Number(this.tickInterval)) {
 649                      this.daTickInterval = [Number(this.tickInterval), 'seconds'];
 650                  }
 651                  // else, parse out something we can build from.
 652                  else if (typeof this.tickInterval == "string") {
 653                      var parts = this.tickInterval.split(' ');
 654                      if (parts.length == 1) {
 655                          this.daTickInterval = [1, parts[0]];
 656                      }
 657                      else if (parts.length == 2) {
 658                          this.daTickInterval = [parts[0], parts[1]];
 659                      }
 660                  }
 661              }
 662              
 663              // if min and max are same, space them out a bit
 664              if (min == max) {
 665                  var adj = 24*60*60*500;  // 1/2 day
 666                  min -= adj;
 667                  max += adj;
 668              }
 669  
 670              range = max - min;
 671              
 672              var optNumTicks = 2 + parseInt(Math.max(0, dim-100)/100, 10);
 673              
 674              
 675              var rmin, rmax;
 676              
 677              rmin = (this.min != null) ? new $.jsDate(this.min).getTime() : min - range/2*(this.padMin - 1);
 678              rmax = (this.max != null) ? new $.jsDate(this.max).getTime() : max + range/2*(this.padMax - 1);
 679              this.min = rmin;
 680              this.max = rmax;
 681              range = this.max - this.min;
 682              
 683              if (this.numberTicks == null){
 684                  // if tickInterval is specified by user, we will ignore computed maximum.
 685                  // max will be equal or greater to fit even # of ticks.
 686                  if (this.daTickInterval != null) {
 687                      var nc = new $.jsDate(this.max).diff(this.min, this.daTickInterval[1], true);
 688                      this.numberTicks = Math.ceil(nc/this.daTickInterval[0]) +1;
 689                      // this.max = new $.jsDate(this.min).add(this.numberTicks-1, this.daTickInterval[1]).getTime();
 690                      this.max = new $.jsDate(this.min).add((this.numberTicks-1) * this.daTickInterval[0], this.daTickInterval[1]).getTime();
 691                  }
 692                  else if (dim > 200) {
 693                      this.numberTicks = parseInt(3+(dim-200)/100, 10);
 694                  }
 695                  else {
 696                      this.numberTicks = 2;
 697                  }
 698              }
 699              
 700              insetMult = range / (this.numberTicks-1)/1000;
 701  
 702              if (this.daTickInterval == null) {
 703                  this.daTickInterval = [insetMult, 'seconds'];
 704              }
 705  
 706  
 707              for (var i=0; i<this.numberTicks; i++){
 708                  var min = new $.jsDate(this.min);
 709                  tt = min.add(i*this.daTickInterval[0], this.daTickInterval[1]).getTime();
 710                  var t = new this.tickRenderer(this.tickOptions);
 711                  // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
 712                  if (!this.showTicks) {
 713                      t.showLabel = false;
 714                      t.showMark = false;
 715                  }
 716                  else if (!this.showTickMarks) {
 717                      t.showMark = false;
 718                  }
 719                  t.setTick(tt, this.name);
 720                  this._ticks.push(t);
 721              }
 722          }
 723  
 724          if (this.tickInset) {
 725              this.min = this.min - this.tickInset * insetMult;
 726              this.max = this.max + this.tickInset * insetMult;
 727          }
 728  
 729          if (this._daTickInterval == null) {
 730              this._daTickInterval = this.daTickInterval;    
 731          }
 732  
 733          ticks = null;
 734      };
 735     
 736  })(jQuery);
 737  


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1