API Docs for: 3.17.2
Show:

File: charts/js/TimeAxis.js

  1. /**
  2. * Provides functionality for drawing a time axis for use with a chart.
  3. *
  4. * @module charts
  5. * @submodule axis-time
  6. */
  7. /**
  8. * TimeAxis draws a time-based axis for a chart.
  9. *
  10. * @class TimeAxis
  11. * @constructor
  12. * @extends Axis
  13. * @uses TimeImpl
  14. * @param {Object} config (optional) Configuration parameters.
  15. * @submodule axis-time
  16. */
  17. Y.TimeAxis = Y.Base.create("timeAxis", Y.Axis, [Y.TimeImpl], {
  18. /**
  19. * Calculates and returns a value based on the number of labels and the index of
  20. * the current label.
  21. *
  22. * @method _getLabelByIndex
  23. * @param {Number} i Index of the label.
  24. * @param {Number} l Total number of labels.
  25. * @return String
  26. * @private
  27. */
  28. _getLabelByIndex: function(i, l)
  29. {
  30. var min = this.get("minimum"),
  31. max = this.get("maximum"),
  32. increm,
  33. label;
  34. l -= 1;
  35. increm = ((max - min)/l) * i;
  36. label = min + increm;
  37. return label;
  38. },
  39.  
  40. /**
  41. * Returns an object literal containing and array of label values and an array of points.
  42. *
  43. * @method _getLabelData
  44. * @param {Object} startPoint An object containing x and y values.
  45. * @param {Number} edgeOffset Distance to offset coordinates.
  46. * @param {Number} layoutLength Distance that the axis spans.
  47. * @param {Number} count Number of labels.
  48. * @param {String} direction Indicates whether the axis is horizontal or vertical.
  49. * @param {Array} Array containing values for axis labels.
  50. * @return Array
  51. * @private
  52. */
  53. _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
  54. {
  55. var dataValue,
  56. i,
  57. points = [],
  58. values = [],
  59. point,
  60. offset = edgeOffset;
  61. dataValues = dataValues || this._getDataValuesByCount(count, min, max);
  62. for(i = 0; i < count; i = i + 1)
  63. {
  64. dataValue = this._getNumber(dataValues[i]);
  65. if(dataValue <= max && dataValue >= min)
  66. {
  67. point = {};
  68. point[staticCoord] = constantVal;
  69. point[dynamicCoord] = this._getCoordFromValue(
  70. min,
  71. max,
  72. layoutLength,
  73. dataValue,
  74. offset
  75. );
  76. points.push(point);
  77. values.push(dataValue);
  78. }
  79. }
  80. return {
  81. points: points,
  82. values: values
  83. };
  84. }
  85. });
  86.  
  87.