Log.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 { __extends } from "tslib";
  41. import Scale from './Scale.js';
  42. import IntervalScale from './Interval.js';
  43. import { logScalePowTick, logScaleLogTick } from './helper.js';
  44. import { getBreaksUnsafe, getScaleBreakHelper } from './break.js';
  45. import { getMinorTicks } from './minorTicks.js';
  46. import { decorateScaleMapper, enableScaleMapperFreeze, SCALE_EXTENT_KIND_EFFECTIVE, SCALE_MAPPER_DEPTH_OUT_OF_BREAK } from './scaleMapper.js';
  47. import { map } from 'zrender/lib/core/util.js';
  48. import { isValidBoundsForExtent } from '../util/model.js';
  49. import { isNullableNumberFinite } from '../util/number.js';
  50. var LOOKUP_IDX_EXTENT_START = 0;
  51. var LOOKUP_IDX_EXTENT_END = 1;
  52. var LOOKUP_IDX_BREAK_START = 2;
  53. /**
  54. * @final NEVER inherit me!
  55. */
  56. var LogScale = /** @class */function (_super) {
  57. __extends(LogScale, _super);
  58. function LogScale(setting) {
  59. var _this = _super.call(this) || this;
  60. _this.type = 'log';
  61. _this.parse = IntervalScale.parse;
  62. _this.base = setting.logBase || 10;
  63. var lookupFrom = [];
  64. var lookupTo = [];
  65. var lookup = _this._lookup = {
  66. from: lookupFrom,
  67. to: lookupTo
  68. };
  69. lookupFrom[LOOKUP_IDX_EXTENT_START] = lookupFrom[LOOKUP_IDX_EXTENT_END] = lookupTo[LOOKUP_IDX_EXTENT_START] = lookupTo[LOOKUP_IDX_EXTENT_END] = NaN;
  70. decorateScaleMapper(_this, LogScale.mapperMethods);
  71. var scaleBreakHelper = getScaleBreakHelper();
  72. var breakOption = setting.breakOption;
  73. var out = {
  74. lookup: lookup
  75. };
  76. if (scaleBreakHelper) {
  77. scaleBreakHelper.parseAxisBreakOptionInwardTransform(breakOption, _this, {
  78. noNegative: true
  79. }, LOOKUP_IDX_BREAK_START, out);
  80. }
  81. _this.powStub = new IntervalScale({
  82. breakParsed: out.original
  83. });
  84. _this.intervalStub = new IntervalScale({
  85. breakParsed: out.transformed
  86. });
  87. enableScaleMapperFreeze(_this, _this.intervalStub);
  88. return _this;
  89. }
  90. LogScale.prototype.getTicks = function (opt) {
  91. var base = this.base;
  92. var powStub = this.powStub;
  93. var scaleBreakHelper = getScaleBreakHelper();
  94. var intervalStub = this.intervalStub;
  95. var intervalExtent = intervalStub.getExtent();
  96. var powExtent = powStub.getExtent();
  97. var powOpt = {
  98. lookup: {
  99. from: intervalExtent,
  100. to: powExtent
  101. }
  102. };
  103. return map(intervalStub.getTicks(opt || {}), function (tick) {
  104. var val = tick.value;
  105. var powVal = logScalePowTick(val, base, powOpt);
  106. var vBreak;
  107. if (scaleBreakHelper) {
  108. var brkPowResult = scaleBreakHelper.getTicksBreakOutwardTransform(this, tick, getBreaksUnsafe(powStub), this._lookup);
  109. if (brkPowResult) {
  110. vBreak = brkPowResult.vBreak;
  111. powVal = brkPowResult.tickVal;
  112. }
  113. }
  114. return {
  115. value: powVal,
  116. "break": vBreak
  117. };
  118. }, this);
  119. };
  120. LogScale.prototype.getMinorTicks = function (splitNumber) {
  121. return getMinorTicks(this, splitNumber, getBreaksUnsafe(this.powStub),
  122. // NOTE: minor ticks are in the log scale value to visually hint users "logarithm".
  123. this.intervalStub.getConfig().interval);
  124. };
  125. LogScale.prototype.getLabel = function (data, opt) {
  126. return this.intervalStub.getLabel(data, opt);
  127. };
  128. LogScale.type = 'log';
  129. LogScale.mapperMethods = {
  130. needTransform: function () {
  131. return true;
  132. },
  133. normalize: function (val) {
  134. return this.intervalStub.normalize(logScaleLogTick(val, this.base));
  135. },
  136. scale: function (val) {
  137. // PENDING: Input `intervalStub.getExtent()` and `powStub.getExtent()` may
  138. // break monotonicity. Do not do it until real problems found.
  139. return logScalePowTick(this.intervalStub.scale(val), this.base, null);
  140. },
  141. transformIn: function (val, opt) {
  142. val = logScaleLogTick(val, this.base);
  143. return opt && opt.depth === SCALE_MAPPER_DEPTH_OUT_OF_BREAK ? val : this.intervalStub.transformIn(val, opt);
  144. },
  145. transformOut: function (val, opt) {
  146. var depth = opt ? opt.depth : null;
  147. tmpTransformOutOpt1.depth = depth;
  148. tmpTransformOutOpt2.lookup = this._lookup;
  149. return logScalePowTick(depth === SCALE_MAPPER_DEPTH_OUT_OF_BREAK ? val : this.intervalStub.transformOut(val, tmpTransformOutOpt1), this.base, tmpTransformOutOpt2);
  150. },
  151. contain: function (val) {
  152. return this.powStub.contain(val);
  153. },
  154. /**
  155. * NOTICE: The caller should ensure `start` and `end` are both non-negative.
  156. */
  157. setExtent: function (start, end) {
  158. this.setExtent2(SCALE_EXTENT_KIND_EFFECTIVE, start, end);
  159. },
  160. setExtent2: function (kind, start, end) {
  161. if (!isValidBoundsForExtent(start, end) || start <= 0 || end <= 0) {
  162. return;
  163. }
  164. var lookupTo = tmpNotUsedArr;
  165. var lookupFrom = tmpNotUsedArr;
  166. if (kind === SCALE_EXTENT_KIND_EFFECTIVE) {
  167. var lookup = this._lookup;
  168. lookupTo = lookup.to;
  169. lookupFrom = lookup.from;
  170. }
  171. this.powStub.setExtent2(kind, lookupTo[LOOKUP_IDX_EXTENT_START] = start, lookupTo[LOOKUP_IDX_EXTENT_END] = end);
  172. var base = this.base;
  173. this.intervalStub.setExtent2(kind, lookupFrom[LOOKUP_IDX_EXTENT_START] = logScaleLogTick(start, base), lookupFrom[LOOKUP_IDX_EXTENT_END] = logScaleLogTick(end, base));
  174. },
  175. getFilter: function () {
  176. return {
  177. g: 0
  178. };
  179. },
  180. sanitize: function (value, dataExtent) {
  181. // Conservative - if dataExtent is invalid, do not sanitize.
  182. if (isValidBoundsForExtent(dataExtent[0], dataExtent[1]) && isNullableNumberFinite(value) && value <= 0) {
  183. // `DataStore` has ensured that `dataExtent` is valid for LogScale.
  184. value = dataExtent[0];
  185. }
  186. return value;
  187. },
  188. getDefaultStartValue: function () {
  189. return 1;
  190. },
  191. getExtent: function () {
  192. return this.powStub.getExtent();
  193. },
  194. getExtentUnsafe: function (kind, depth) {
  195. return depth === null ? this.powStub.getExtentUnsafe(kind, null) : this.intervalStub.getExtentUnsafe(kind, depth);
  196. }
  197. };
  198. return LogScale;
  199. }(Scale);
  200. Scale.registerClass(LogScale);
  201. var tmpTransformOutOpt1 = {};
  202. var tmpTransformOutOpt2 = {};
  203. var tmpNotUsedArr = [];
  204. export default LogScale;