SingleAxisPointer.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 viewHelper from './viewHelper.js';
  43. import * as singleAxisHelper from '../../coord/single/singleAxisHelper.js';
  44. var XY = ['x', 'y'];
  45. var WH = ['width', 'height'];
  46. var SingleAxisPointer = /** @class */function (_super) {
  47. __extends(SingleAxisPointer, _super);
  48. function SingleAxisPointer() {
  49. return _super !== null && _super.apply(this, arguments) || this;
  50. }
  51. /**
  52. * @override
  53. */
  54. SingleAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  55. var axis = axisModel.axis;
  56. var coordSys = axis.coordinateSystem;
  57. var pointDimIndex = getPointDimIndex(axis);
  58. var thisExtent = getGlobalExtent(coordSys, pointDimIndex);
  59. var otherExtent = getGlobalExtent(coordSys, 1 - pointDimIndex);
  60. var pixelValue = coordSys.dataToPoint(value)[0];
  61. var axisPointerType = axisPointerModel.get('type');
  62. if (axisPointerType && axisPointerType !== 'none') {
  63. var elStyle = viewHelper.buildElStyle(axisPointerModel);
  64. var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, thisExtent, otherExtent, axisPointerModel.get('seriesDataIndices'), axisPointerModel.ecModel);
  65. pointerOption.style = elStyle;
  66. elOption.graphicKey = pointerOption.type;
  67. elOption.pointer = pointerOption;
  68. }
  69. var layoutInfo = singleAxisHelper.layout(axisModel);
  70. viewHelper.buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
  71. };
  72. /**
  73. * @override
  74. */
  75. SingleAxisPointer.prototype.getHandleTransform = function (value, axisModel, axisPointerModel) {
  76. var layoutInfo = singleAxisHelper.layout(axisModel, {
  77. labelInside: false
  78. });
  79. layoutInfo.labelMargin = axisPointerModel.get(['handle', 'margin']);
  80. var position = viewHelper.getTransformedPosition(axisModel.axis, value, layoutInfo);
  81. return {
  82. x: position[0],
  83. y: position[1],
  84. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  85. };
  86. };
  87. /**
  88. * @override
  89. */
  90. SingleAxisPointer.prototype.updateHandleTransform = function (transform, delta, axisModel, axisPointerModel) {
  91. var axis = axisModel.axis;
  92. var coordSys = axis.coordinateSystem;
  93. var dimIndex = getPointDimIndex(axis);
  94. var axisExtent = getGlobalExtent(coordSys, dimIndex);
  95. var currPosition = [transform.x, transform.y];
  96. currPosition[dimIndex] += delta[dimIndex];
  97. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  98. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  99. var otherExtent = getGlobalExtent(coordSys, 1 - dimIndex);
  100. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  101. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  102. cursorPoint[dimIndex] = currPosition[dimIndex];
  103. return {
  104. x: currPosition[0],
  105. y: currPosition[1],
  106. rotation: transform.rotation,
  107. cursorPoint: cursorPoint,
  108. tooltipOption: {
  109. verticalAlign: 'middle'
  110. }
  111. };
  112. };
  113. return SingleAxisPointer;
  114. }(BaseAxisPointer);
  115. var pointerShapeBuilder = {
  116. line: function (axis, pixelValue, thisExtent, otherExtent) {
  117. var targetShape = viewHelper.makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getPointDimIndex(axis));
  118. return {
  119. type: 'Line',
  120. subPixelOptimize: true,
  121. shape: targetShape
  122. };
  123. },
  124. shadow: function (axis, pixelValue, thisExtent, otherExtent, seriesDataIndices, ecModel) {
  125. var bandWidth = viewHelper.calcAxisPointerShadowBandWidth(axis, seriesDataIndices, ecModel);
  126. var span = otherExtent[1] - otherExtent[0];
  127. var _a = viewHelper.calcAxisPointerShadowEnds(pixelValue, thisExtent, bandWidth),
  128. min = _a[0],
  129. max = _a[1];
  130. return {
  131. type: 'Rect',
  132. shape: viewHelper.makeRectShape([min, otherExtent[0]], [max - min, span], getPointDimIndex(axis))
  133. };
  134. }
  135. };
  136. function getPointDimIndex(axis) {
  137. return axis.isHorizontal() ? 0 : 1;
  138. }
  139. function getGlobalExtent(coordSys, dimIndex) {
  140. var rect = coordSys.getRect();
  141. return [rect[XY[dimIndex]], rect[XY[dimIndex]] + rect[WH[dimIndex]]];
  142. }
  143. export default SingleAxisPointer;