API Docs for: 3.18.1
Show:

File: charts/js/CategoryAxis.js

  1. /**
  2. * Provides functionality for drawing a category axis for use with a chart.
  3. *
  4. * @module charts
  5. * @submodule axis-category
  6. */
  7. var Y_Lang = Y.Lang;
  8. /**
  9. * CategoryAxis draws a category axis for a chart.
  10. *
  11. * @class CategoryAxis
  12. * @constructor
  13. * @extends Axis
  14. * @uses CategoryImpl
  15. * @param {Object} config (optional) Configuration parameters.
  16. * @submodule axis-category
  17. */
  18. Y.CategoryAxis = Y.Base.create("categoryAxis", Y.Axis, [Y.CategoryImpl], {
  19. /**
  20. * Returns a string corresponding to the first label on an
  21. * axis.
  22. *
  23. * @method getMinimumValue
  24. * @return String
  25. */
  26. getMinimumValue: function()
  27. {
  28. var data = this.get("data"),
  29. label = data[0];
  30. return label;
  31. },
  32.  
  33. /**
  34. * Returns a string corresponding to the last label on an
  35. * axis.
  36. *
  37. * @method getMaximumValue
  38. * @return String
  39. */
  40. getMaximumValue: function()
  41. {
  42. var data = this.get("data"),
  43. len = data.length - 1,
  44. label = data[len];
  45. return label;
  46. },
  47.  
  48. /**
  49. * Calculates and returns a value based on the number of labels and the index of
  50. * the current label.
  51. *
  52. * @method _getLabelByIndex
  53. * @param {Number} i Index of the label.
  54. * @return String
  55. * @private
  56. */
  57. _getLabelByIndex: function(i)
  58. {
  59. var label,
  60. data = this.get("data");
  61. label = data[i];
  62. return label;
  63. },
  64.  
  65. /**
  66. * Returns an object literal containing and array of label values and an array of points.
  67. *
  68. * @method _getLabelData
  69. * @param {Object} startPoint An object containing x and y values.
  70. * @param {Number} edgeOffset Distance to offset coordinates.
  71. * @param {Number} layoutLength Distance that the axis spans.
  72. * @param {Number} count Number of labels.
  73. * @param {String} direction Indicates whether the axis is horizontal or vertical.
  74. * @param {Array} Array containing values for axis labels.
  75. * @return Array
  76. * @private
  77. */
  78. _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
  79. {
  80. var labelValue,
  81. i,
  82. points = [],
  83. values = [],
  84. point,
  85. labelIndex,
  86. data = this.get("data"),
  87. offset = edgeOffset;
  88. dataValues = dataValues || data;
  89. for(i = 0; i < count; i = i + 1)
  90. {
  91. labelValue = dataValues[i];
  92. labelIndex = Y.Array.indexOf(data, labelValue);
  93. if(Y_Lang.isNumber(labelIndex) && labelIndex > -1)
  94. {
  95. point = {};
  96. point[staticCoord] = constantVal;
  97. point[dynamicCoord] = this._getCoordFromValue(
  98. min,
  99. max,
  100. layoutLength,
  101. labelIndex,
  102. offset
  103. );
  104. points.push(point);
  105. values.push(labelValue);
  106. }
  107. }
  108. return {
  109. points: points,
  110. values: values
  111. };
  112. }
  113. });
  114.  
  115.