Version 3.18.1
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. * Returns an object literal containing and array of label values and an array of points.
  41. *
  42. * @method _getLabelData
  43. * @param {Object} startPoint An object containing x and y values.
  44. * @param {Number} edgeOffset Distance to offset coordinates.
  45. * @param {Number} layoutLength Distance that the axis spans.
  46. * @param {Number} count Number of labels.
  47. * @param {String} direction Indicates whether the axis is horizontal or vertical.
  48. * @param {Array} Array containing values for axis labels.
  49. * @return Array
  50. * @private
  51. */
  52. _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
  53. {
  54. var dataValue,
  55. i,
  56. points = [],
  57. values = [],
  58. point,
  59. offset = edgeOffset;
  60. dataValues = dataValues || this._getDataValuesByCount(count, min, max);
  61. for(i = 0; i < count; i = i + 1)
  62. {
  63. dataValue = this._getNumber(dataValues[i]);
  64. if(dataValue <= max && dataValue >= min)
  65. {
  66. point = {};
  67. point[staticCoord] = constantVal;
  68. point[dynamicCoord] = this._getCoordFromValue(
  69. min,
  70. max,
  71. layoutLength,
  72. dataValue,
  73. offset
  74. );
  75. points.push(point);
  76. values.push(dataValue);
  77. }
  78. }
  79. return {
  80. points: points,
  81. values: values
  82. };
  83. }
  84. });