Axis2D.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. var zrUtil = require("zrender/lib/core/util");
  20. var Axis = require("../Axis");
  21. /*
  22. * Licensed to the Apache Software Foundation (ASF) under one
  23. * or more contributor license agreements. See the NOTICE file
  24. * distributed with this work for additional information
  25. * regarding copyright ownership. The ASF licenses this file
  26. * to you under the Apache License, Version 2.0 (the
  27. * "License"); you may not use this file except in compliance
  28. * with the License. You may obtain a copy of the License at
  29. *
  30. * http://www.apache.org/licenses/LICENSE-2.0
  31. *
  32. * Unless required by applicable law or agreed to in writing,
  33. * software distributed under the License is distributed on an
  34. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35. * KIND, either express or implied. See the License for the
  36. * specific language governing permissions and limitations
  37. * under the License.
  38. */
  39. /**
  40. * Extend axis 2d
  41. * @constructor module:echarts/coord/cartesian/Axis2D
  42. * @extends {module:echarts/coord/cartesian/Axis}
  43. * @param {string} dim
  44. * @param {*} scale
  45. * @param {Array.<number>} coordExtent
  46. * @param {string} axisType
  47. * @param {string} position
  48. */
  49. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  50. Axis.call(this, dim, scale, coordExtent);
  51. /**
  52. * Axis type
  53. * - 'category'
  54. * - 'value'
  55. * - 'time'
  56. * - 'log'
  57. * @type {string}
  58. */
  59. this.type = axisType || 'value';
  60. /**
  61. * Axis position
  62. * - 'top'
  63. * - 'bottom'
  64. * - 'left'
  65. * - 'right'
  66. */
  67. this.position = position || 'bottom';
  68. };
  69. Axis2D.prototype = {
  70. constructor: Axis2D,
  71. /**
  72. * Index of axis, can be used as key
  73. */
  74. index: 0,
  75. /**
  76. * Implemented in <module:echarts/coord/cartesian/Grid>.
  77. * @return {Array.<module:echarts/coord/cartesian/Axis2D>}
  78. * If not on zero of other axis, return null/undefined.
  79. * If no axes, return an empty array.
  80. */
  81. getAxesOnZeroOf: null,
  82. /**
  83. * Axis model
  84. * @param {module:echarts/coord/cartesian/AxisModel}
  85. */
  86. model: null,
  87. isHorizontal: function () {
  88. var position = this.position;
  89. return position === 'top' || position === 'bottom';
  90. },
  91. /**
  92. * Each item cooresponds to this.getExtent(), which
  93. * means globalExtent[0] may greater than globalExtent[1],
  94. * unless `asc` is input.
  95. *
  96. * @param {boolean} [asc]
  97. * @return {Array.<number>}
  98. */
  99. getGlobalExtent: function (asc) {
  100. var ret = this.getExtent();
  101. ret[0] = this.toGlobalCoord(ret[0]);
  102. ret[1] = this.toGlobalCoord(ret[1]);
  103. asc && ret[0] > ret[1] && ret.reverse();
  104. return ret;
  105. },
  106. getOtherAxis: function () {
  107. this.grid.getOtherAxis();
  108. },
  109. /**
  110. * @override
  111. */
  112. pointToData: function (point, clamp) {
  113. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  114. },
  115. /**
  116. * Transform global coord to local coord,
  117. * i.e. var localCoord = axis.toLocalCoord(80);
  118. * designate by module:echarts/coord/cartesian/Grid.
  119. * @type {Function}
  120. */
  121. toLocalCoord: null,
  122. /**
  123. * Transform global coord to local coord,
  124. * i.e. var globalCoord = axis.toLocalCoord(40);
  125. * designate by module:echarts/coord/cartesian/Grid.
  126. * @type {Function}
  127. */
  128. toGlobalCoord: null
  129. };
  130. zrUtil.inherits(Axis2D, Axis);
  131. var _default = Axis2D;
  132. module.exports = _default;