AngleAxis.js 4.4 KB

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