axisModelCommonMixin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. // import * as axisHelper from './axisHelper';
  39. var _default = {
  40. /**
  41. * @param {boolean} origin
  42. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  43. */
  44. getMin: function (origin) {
  45. var option = this.option;
  46. var min = !origin && option.rangeStart != null ? option.rangeStart : option.min;
  47. if (this.axis && min != null && min !== 'dataMin' && typeof min !== 'function' && !zrUtil.eqNaN(min)) {
  48. min = this.axis.scale.parse(min);
  49. }
  50. return min;
  51. },
  52. /**
  53. * @param {boolean} origin
  54. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  55. */
  56. getMax: function (origin) {
  57. var option = this.option;
  58. var max = !origin && option.rangeEnd != null ? option.rangeEnd : option.max;
  59. if (this.axis && max != null && max !== 'dataMax' && typeof max !== 'function' && !zrUtil.eqNaN(max)) {
  60. max = this.axis.scale.parse(max);
  61. }
  62. return max;
  63. },
  64. /**
  65. * @return {boolean}
  66. */
  67. getNeedCrossZero: function () {
  68. var option = this.option;
  69. return option.rangeStart != null || option.rangeEnd != null ? false : !option.scale;
  70. },
  71. /**
  72. * Should be implemented by each axis model if necessary.
  73. * @return {module:echarts/model/Component} coordinate system model
  74. */
  75. getCoordSysModel: zrUtil.noop,
  76. /**
  77. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  78. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  79. */
  80. setRange: function (rangeStart, rangeEnd) {
  81. this.option.rangeStart = rangeStart;
  82. this.option.rangeEnd = rangeEnd;
  83. },
  84. /**
  85. * Reset range
  86. */
  87. resetRange: function () {
  88. // rangeStart and rangeEnd is readonly.
  89. this.option.rangeStart = this.option.rangeEnd = null;
  90. }
  91. };
  92. module.exports = _default;