PolarAxisPointer.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 BaseAxisPointer from './BaseAxisPointer.js';
  42. import * as graphic from '../../util/graphic.js';
  43. import * as viewHelper from './viewHelper.js';
  44. import * as matrix from 'zrender/lib/core/matrix.js';
  45. import AxisBuilder from '../axis/AxisBuilder.js';
  46. var PolarAxisPointer = /** @class */function (_super) {
  47. __extends(PolarAxisPointer, _super);
  48. function PolarAxisPointer() {
  49. return _super !== null && _super.apply(this, arguments) || this;
  50. }
  51. /**
  52. * @override
  53. */
  54. PolarAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  55. var axis = axisModel.axis;
  56. if (axis.dim === 'angle') {
  57. this.animationThreshold = Math.PI / 18;
  58. }
  59. var polar = axis.polar;
  60. var otherAxis = polar.getOtherAxis(axis);
  61. var otherExtent = otherAxis.getExtent();
  62. var coordValue = axis.dataToCoord(value);
  63. var axisPointerType = axisPointerModel.get('type');
  64. if (axisPointerType && axisPointerType !== 'none') {
  65. var elStyle = viewHelper.buildElStyle(axisPointerModel);
  66. var pointerOption = pointerShapeBuilder[axisPointerType](axis, polar, coordValue, otherExtent);
  67. pointerOption.style = elStyle;
  68. elOption.graphicKey = pointerOption.type;
  69. elOption.pointer = pointerOption;
  70. }
  71. var labelMargin = axisPointerModel.get(['label', 'margin']);
  72. var labelPos = getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin);
  73. viewHelper.buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos);
  74. };
  75. return PolarAxisPointer;
  76. }(BaseAxisPointer);
  77. ;
  78. function getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin) {
  79. var axis = axisModel.axis;
  80. var coord = axis.dataToCoord(value);
  81. var axisAngle = polar.getAngleAxis().getExtent()[0];
  82. axisAngle = axisAngle / 180 * Math.PI;
  83. var radiusExtent = polar.getRadiusAxis().getExtent();
  84. var position;
  85. var align;
  86. var verticalAlign;
  87. if (axis.dim === 'radius') {
  88. var transform = matrix.create();
  89. matrix.rotate(transform, transform, axisAngle);
  90. matrix.translate(transform, transform, [polar.cx, polar.cy]);
  91. position = graphic.applyTransform([coord, -labelMargin], transform);
  92. var labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0;
  93. // @ts-ignore
  94. var labelLayout = AxisBuilder.innerTextLayout(axisAngle, labelRotation * Math.PI / 180, -1);
  95. align = labelLayout.textAlign;
  96. verticalAlign = labelLayout.textVerticalAlign;
  97. } else {
  98. // angle axis
  99. var r = radiusExtent[1];
  100. position = polar.coordToPoint([r + labelMargin, coord]);
  101. var cx = polar.cx;
  102. var cy = polar.cy;
  103. align = Math.abs(position[0] - cx) / r < 0.3 ? 'center' : position[0] > cx ? 'left' : 'right';
  104. verticalAlign = Math.abs(position[1] - cy) / r < 0.3 ? 'middle' : position[1] > cy ? 'top' : 'bottom';
  105. }
  106. return {
  107. position: position,
  108. align: align,
  109. verticalAlign: verticalAlign
  110. };
  111. }
  112. var pointerShapeBuilder = {
  113. line: function (axis, polar, coordValue, otherExtent) {
  114. return axis.dim === 'angle' ? {
  115. type: 'Line',
  116. shape: viewHelper.makeLineShape(polar.coordToPoint([otherExtent[0], coordValue]), polar.coordToPoint([otherExtent[1], coordValue]))
  117. } : {
  118. type: 'Circle',
  119. shape: {
  120. cx: polar.cx,
  121. cy: polar.cy,
  122. r: coordValue
  123. }
  124. };
  125. },
  126. shadow: function (axis, polar, coordValue, otherExtent) {
  127. var bandWidth = Math.max(1, axis.getBandWidth());
  128. var radian = Math.PI / 180;
  129. return axis.dim === 'angle' ? {
  130. type: 'Sector',
  131. shape: viewHelper.makeSectorShape(polar.cx, polar.cy, otherExtent[0], otherExtent[1],
  132. // In ECharts y is negative if angle is positive
  133. (-coordValue - bandWidth / 2) * radian, (-coordValue + bandWidth / 2) * radian)
  134. } : {
  135. type: 'Sector',
  136. shape: viewHelper.makeSectorShape(polar.cx, polar.cy, coordValue - bandWidth / 2, coordValue + bandWidth / 2, 0, Math.PI * 2)
  137. };
  138. }
  139. };
  140. export default PolarAxisPointer;