PolarAxisPointer.js 5.5 KB

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