AngleAxis.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 * as textContain from 'zrender/lib/contain/text.js';
  42. import Axis from '../Axis.js';
  43. import { makeInner } from '../../util/model.js';
  44. var inner = makeInner();
  45. var AngleAxis =
  46. /** @class */
  47. function (_super) {
  48. __extends(AngleAxis, _super);
  49. function AngleAxis(scale, angleExtent) {
  50. return _super.call(this, 'angle', scale, angleExtent || [0, 360]) || this;
  51. }
  52. AngleAxis.prototype.pointToData = function (point, clamp) {
  53. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  54. };
  55. /**
  56. * Only be called in category axis.
  57. * Angle axis uses text height to decide interval
  58. *
  59. * @override
  60. * @return {number} Auto interval for cateogry axis tick and label
  61. */
  62. AngleAxis.prototype.calculateCategoryInterval = function () {
  63. var axis = this;
  64. var labelModel = axis.getLabelModel();
  65. var ordinalScale = axis.scale;
  66. var ordinalExtent = ordinalScale.getExtent(); // Providing this method is for optimization:
  67. // avoid generating a long array by `getTicks`
  68. // in large category data case.
  69. var tickCount = ordinalScale.count();
  70. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  71. return 0;
  72. }
  73. var tickValue = ordinalExtent[0];
  74. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  75. var unitH = Math.abs(unitSpan); // Not precise, just use height as text width
  76. // and each distance from axis line yet.
  77. var rect = textContain.getBoundingRect(tickValue == null ? '' : tickValue + '', labelModel.getFont(), 'center', 'top');
  78. var maxH = Math.max(rect.height, 7);
  79. var dh = maxH / unitH; // 0/0 is NaN, 1/0 is Infinity.
  80. isNaN(dh) && (dh = Infinity);
  81. var interval = Math.max(0, Math.floor(dh));
  82. var cache = inner(axis.model);
  83. var lastAutoInterval = cache.lastAutoInterval;
  84. var lastTickCount = cache.lastTickCount; // Use cache to keep interval stable while moving zoom window,
  85. // otherwise the calculated interval might jitter when the zoom
  86. // window size is close to the interval-changing size.
  87. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1 // Always choose the bigger one, otherwise the critical
  88. // point is not the same when zooming in or zooming out.
  89. && lastAutoInterval > interval) {
  90. interval = lastAutoInterval;
  91. } // Only update cache if cache not used, otherwise the
  92. // changing of interval is too insensitive.
  93. else {
  94. cache.lastTickCount = tickCount;
  95. cache.lastAutoInterval = interval;
  96. }
  97. return interval;
  98. };
  99. return AngleAxis;
  100. }(Axis);
  101. AngleAxis.prototype.dataToAngle = Axis.prototype.dataToCoord;
  102. AngleAxis.prototype.angleToData = Axis.prototype.coordToData;
  103. export default AngleAxis;