Scale.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import * as clazzUtil from '../util/clazz.js';
  41. import { ScaleCalculator } from './helper.js';
  42. import { bind } from 'zrender/lib/core/util.js';
  43. import { getScaleBreakHelper } from './break.js';
  44. var Scale = /** @class */function () {
  45. function Scale(setting) {
  46. this._calculator = new ScaleCalculator();
  47. this._setting = setting || {};
  48. this._extent = [Infinity, -Infinity];
  49. var scaleBreakHelper = getScaleBreakHelper();
  50. if (scaleBreakHelper) {
  51. this._brkCtx = scaleBreakHelper.createScaleBreakContext();
  52. this._brkCtx.update(this._extent);
  53. }
  54. }
  55. Scale.prototype.getSetting = function (name) {
  56. return this._setting[name];
  57. };
  58. /**
  59. * [CAVEAT]: It should not be overridden!
  60. */
  61. Scale.prototype._innerUnionExtent = function (other) {
  62. var extent = this._extent;
  63. // Considered that number could be NaN and should not write into the extent.
  64. this._innerSetExtent(other[0] < extent[0] ? other[0] : extent[0], other[1] > extent[1] ? other[1] : extent[1]);
  65. };
  66. /**
  67. * Set extent from data
  68. */
  69. Scale.prototype.unionExtentFromData = function (data, dim) {
  70. this._innerUnionExtent(data.getApproximateExtent(dim));
  71. };
  72. /**
  73. * Get a new slice of extent.
  74. * Extent is always in increase order.
  75. */
  76. Scale.prototype.getExtent = function () {
  77. return this._extent.slice();
  78. };
  79. Scale.prototype.setExtent = function (start, end) {
  80. this._innerSetExtent(start, end);
  81. };
  82. /**
  83. * [CAVEAT]: It should not be overridden!
  84. */
  85. Scale.prototype._innerSetExtent = function (start, end) {
  86. var thisExtent = this._extent;
  87. if (!isNaN(start)) {
  88. thisExtent[0] = start;
  89. }
  90. if (!isNaN(end)) {
  91. thisExtent[1] = end;
  92. }
  93. this._brkCtx && this._brkCtx.update(thisExtent);
  94. };
  95. /**
  96. * Prerequisite: Scale#parse is ready.
  97. */
  98. Scale.prototype.setBreaksFromOption = function (breakOptionList) {
  99. var scaleBreakHelper = getScaleBreakHelper();
  100. if (scaleBreakHelper) {
  101. this._innerSetBreak(scaleBreakHelper.parseAxisBreakOption(breakOptionList, bind(this.parse, this)));
  102. }
  103. };
  104. /**
  105. * [CAVEAT]: It should not be overridden!
  106. */
  107. Scale.prototype._innerSetBreak = function (parsed) {
  108. if (this._brkCtx) {
  109. this._brkCtx.setBreaks(parsed);
  110. this._calculator.updateMethods(this._brkCtx);
  111. this._brkCtx.update(this._extent);
  112. }
  113. };
  114. /**
  115. * [CAVEAT]: It should not be overridden!
  116. */
  117. Scale.prototype._innerGetBreaks = function () {
  118. return this._brkCtx ? this._brkCtx.breaks : [];
  119. };
  120. /**
  121. * Do not expose the internal `_breaks` unless necessary.
  122. */
  123. Scale.prototype.hasBreaks = function () {
  124. return this._brkCtx ? this._brkCtx.hasBreaks() : false;
  125. };
  126. Scale.prototype._getExtentSpanWithBreaks = function () {
  127. return this._brkCtx && this._brkCtx.hasBreaks() ? this._brkCtx.getExtentSpan() : this._extent[1] - this._extent[0];
  128. };
  129. /**
  130. * If value is in extent range
  131. */
  132. Scale.prototype.isInExtentRange = function (value) {
  133. return this._extent[0] <= value && this._extent[1] >= value;
  134. };
  135. /**
  136. * When axis extent depends on data and no data exists,
  137. * axis ticks should not be drawn, which is named 'blank'.
  138. */
  139. Scale.prototype.isBlank = function () {
  140. return this._isBlank;
  141. };
  142. /**
  143. * When axis extent depends on data and no data exists,
  144. * axis ticks should not be drawn, which is named 'blank'.
  145. */
  146. Scale.prototype.setBlank = function (isBlank) {
  147. this._isBlank = isBlank;
  148. };
  149. return Scale;
  150. }();
  151. clazzUtil.enableClassManagement(Scale);
  152. export default Scale;