API Docs for: 3.18.1
Show:

File: charts/js/NumericAxis.js

  1. /**
  2. * Provides functionality for drawing a numeric axis for use with a chart.
  3. *
  4. * @module charts
  5. * @submodule axis-numeric
  6. */
  7. var Y_Lang = Y.Lang;
  8. /**
  9. * NumericAxis draws a numeric axis.
  10. *
  11. * @class NumericAxis
  12. * @constructor
  13. * @extends Axis
  14. * @uses NumericImpl
  15. * @param {Object} config (optional) Configuration parameters.
  16. * @submodule axis-numeric
  17. */
  18. Y.NumericAxis = Y.Base.create("numericAxis", Y.Axis, [Y.NumericImpl], {
  19. /**
  20. * Calculates and returns a value based on the number of labels and the index of
  21. * the current label.
  22. *
  23. * @method getLabelByIndex
  24. * @param {Number} i Index of the label.
  25. * @param {Number} l Total number of labels.
  26. * @return String
  27. * @private
  28. */
  29. _getLabelByIndex: function(i, l)
  30. {
  31. var min = this.get("minimum"),
  32. max = this.get("maximum"),
  33. increm = (max - min)/(l-1),
  34. label,
  35. roundingMethod = this.get("roundingMethod");
  36. l -= 1;
  37. //respect the min and max. calculate all other labels.
  38. if(i === 0)
  39. {
  40. label = min;
  41. }
  42. else if(i === l)
  43. {
  44. label = max;
  45. }
  46. else
  47. {
  48. label = (i * increm);
  49. if(roundingMethod === "niceNumber")
  50. {
  51. label = this._roundToNearest(label, increm);
  52. }
  53. label += min;
  54. }
  55. return parseFloat(label);
  56. },
  57.  
  58. /**
  59. * Returns an object literal containing and array of label values and an array of points.
  60. *
  61. * @method _getLabelData
  62. * @param {Object} startPoint An object containing x and y values.
  63. * @param {Number} edgeOffset Distance to offset coordinates.
  64. * @param {Number} layoutLength Distance that the axis spans.
  65. * @param {Number} count Number of labels.
  66. * @param {String} direction Indicates whether the axis is horizontal or vertical.
  67. * @param {Array} Array containing values for axis labels.
  68. * @return Array
  69. * @private
  70. */
  71. _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
  72. {
  73. var dataValue,
  74. i,
  75. points = [],
  76. values = [],
  77. point,
  78. isVertical = staticCoord === "x",
  79. offset = isVertical ? layoutLength + edgeOffset : edgeOffset;
  80. dataValues = dataValues || this._getDataValuesByCount(count, min, max);
  81. for(i = 0; i < count; i = i + 1)
  82. {
  83. dataValue = parseFloat(dataValues[i]);
  84. if(dataValue <= max && dataValue >= min)
  85. {
  86. point = {};
  87. point[staticCoord] = constantVal;
  88. point[dynamicCoord] = this._getCoordFromValue(
  89. min,
  90. max,
  91. layoutLength,
  92. dataValue,
  93. offset,
  94. isVertical
  95. );
  96. points.push(point);
  97. values.push(dataValue);
  98. }
  99. }
  100. return {
  101. points: points,
  102. values: values
  103. };
  104. },
  105.  
  106. /**
  107. * Checks to see if data extends beyond the range of the axis. If so,
  108. * that data will need to be hidden. This method is internal, temporary and subject
  109. * to removal in the future.
  110. *
  111. * @method _hasDataOverflow
  112. * @protected
  113. * @return Boolean
  114. */
  115. _hasDataOverflow: function()
  116. {
  117. var roundingMethod,
  118. min,
  119. max;
  120. if(this.get("setMin") || this.get("setMax"))
  121. {
  122. return true;
  123. }
  124. roundingMethod = this.get("roundingMethod");
  125. min = this._actualMinimum;
  126. max = this._actualMaximum;
  127. if(Y_Lang.isNumber(roundingMethod) &&
  128. ((Y_Lang.isNumber(max) && max > this._dataMaximum) || (Y_Lang.isNumber(min) && min < this._dataMinimum)))
  129. {
  130. return true;
  131. }
  132. return false;
  133. }
  134. });
  135.  
  136.