Axis2D.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. var zrUtil = require("zrender/lib/core/util");
  2. var Axis = require("../Axis");
  3. /**
  4. * Extend axis 2d
  5. * @constructor module:echarts/coord/cartesian/Axis2D
  6. * @extends {module:echarts/coord/cartesian/Axis}
  7. * @param {string} dim
  8. * @param {*} scale
  9. * @param {Array.<number>} coordExtent
  10. * @param {string} axisType
  11. * @param {string} position
  12. */
  13. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  14. Axis.call(this, dim, scale, coordExtent);
  15. /**
  16. * Axis type
  17. * - 'category'
  18. * - 'value'
  19. * - 'time'
  20. * - 'log'
  21. * @type {string}
  22. */
  23. this.type = axisType || 'value';
  24. /**
  25. * Axis position
  26. * - 'top'
  27. * - 'bottom'
  28. * - 'left'
  29. * - 'right'
  30. */
  31. this.position = position || 'bottom';
  32. };
  33. Axis2D.prototype = {
  34. constructor: Axis2D,
  35. /**
  36. * Index of axis, can be used as key
  37. */
  38. index: 0,
  39. /**
  40. * If axis is on the zero position of the other axis
  41. * @type {boolean}
  42. */
  43. onZero: false,
  44. /**
  45. * Axis model
  46. * @param {module:echarts/coord/cartesian/AxisModel}
  47. */
  48. model: null,
  49. isHorizontal: function () {
  50. var position = this.position;
  51. return position === 'top' || position === 'bottom';
  52. },
  53. /**
  54. * Each item cooresponds to this.getExtent(), which
  55. * means globalExtent[0] may greater than globalExtent[1],
  56. * unless `asc` is input.
  57. *
  58. * @param {boolean} [asc]
  59. * @return {Array.<number>}
  60. */
  61. getGlobalExtent: function (asc) {
  62. var ret = this.getExtent();
  63. ret[0] = this.toGlobalCoord(ret[0]);
  64. ret[1] = this.toGlobalCoord(ret[1]);
  65. asc && ret[0] > ret[1] && ret.reverse();
  66. return ret;
  67. },
  68. getOtherAxis: function () {
  69. this.grid.getOtherAxis();
  70. },
  71. /**
  72. * If label is ignored.
  73. * Automatically used when axis is category and label can not be all shown
  74. * @param {number} idx
  75. * @return {boolean}
  76. */
  77. isLabelIgnored: function (idx) {
  78. if (this.type === 'category') {
  79. var labelInterval = this.getLabelInterval();
  80. return typeof labelInterval === 'function' && !labelInterval(idx, this.scale.getLabel(idx)) || idx % (labelInterval + 1);
  81. }
  82. },
  83. /**
  84. * @override
  85. */
  86. pointToData: function (point, clamp) {
  87. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  88. },
  89. /**
  90. * Transform global coord to local coord,
  91. * i.e. var localCoord = axis.toLocalCoord(80);
  92. * designate by module:echarts/coord/cartesian/Grid.
  93. * @type {Function}
  94. */
  95. toLocalCoord: null,
  96. /**
  97. * Transform global coord to local coord,
  98. * i.e. var globalCoord = axis.toLocalCoord(40);
  99. * designate by module:echarts/coord/cartesian/Grid.
  100. * @type {Function}
  101. */
  102. toGlobalCoord: null
  103. };
  104. zrUtil.inherits(Axis2D, Axis);
  105. var _default = Axis2D;
  106. module.exports = _default;