CartesianAxisPointer.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 cartesianAxisHelper from '../../coord/cartesian/cartesianAxisHelper.js';
  44. import { mathMax, mathMin } from '../../util/number.js';
  45. var CartesianAxisPointer = /** @class */function (_super) {
  46. __extends(CartesianAxisPointer, _super);
  47. function CartesianAxisPointer() {
  48. return _super !== null && _super.apply(this, arguments) || this;
  49. }
  50. /**
  51. * @override
  52. */
  53. CartesianAxisPointer.prototype.makeElOption = function (elOption, value, axisModel, axisPointerModel, api) {
  54. var axis = axisModel.axis;
  55. var grid = axis.grid;
  56. var axisPointerType = axisPointerModel.get('type');
  57. var thisExtent = axis.getGlobalExtent();
  58. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  59. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  60. if (axisPointerType && axisPointerType !== 'none') {
  61. var elStyle = viewHelper.buildElStyle(axisPointerModel);
  62. var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, thisExtent, otherExtent, axisPointerModel.get('seriesDataIndices'), axisPointerModel.ecModel);
  63. pointerOption.style = elStyle;
  64. elOption.graphicKey = pointerOption.type;
  65. elOption.pointer = pointerOption;
  66. }
  67. var layoutInfo = cartesianAxisHelper.layout(grid.getRect(), axisModel);
  68. viewHelper.buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
  69. };
  70. /**
  71. * @override
  72. */
  73. CartesianAxisPointer.prototype.getHandleTransform = function (value, axisModel, axisPointerModel) {
  74. var layoutInfo = cartesianAxisHelper.layout(axisModel.axis.grid.getRect(), axisModel, {
  75. labelInside: false
  76. });
  77. layoutInfo.labelMargin = axisPointerModel.get(['handle', 'margin']);
  78. var pos = viewHelper.getTransformedPosition(axisModel.axis, value, layoutInfo);
  79. return {
  80. x: pos[0],
  81. y: pos[1],
  82. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  83. };
  84. };
  85. /**
  86. * @override
  87. */
  88. CartesianAxisPointer.prototype.updateHandleTransform = function (transform, delta, axisModel, axisPointerModel) {
  89. var axis = axisModel.axis;
  90. var grid = axis.grid;
  91. var axisExtent = axis.getGlobalExtent(true);
  92. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  93. var dimIndex = axis.dim === 'x' ? 0 : 1;
  94. var currPosition = [transform.x, transform.y];
  95. currPosition[dimIndex] += delta[dimIndex];
  96. currPosition[dimIndex] = mathMin(axisExtent[1], currPosition[dimIndex]);
  97. currPosition[dimIndex] = mathMax(axisExtent[0], currPosition[dimIndex]);
  98. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  99. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  100. cursorPoint[dimIndex] = currPosition[dimIndex];
  101. // Make tooltip do not overlap axisPointer and in the middle of the grid.
  102. var tooltipOptions = [{
  103. verticalAlign: 'middle'
  104. }, {
  105. align: 'center'
  106. }];
  107. return {
  108. x: currPosition[0],
  109. y: currPosition[1],
  110. rotation: transform.rotation,
  111. cursorPoint: cursorPoint,
  112. tooltipOption: tooltipOptions[dimIndex]
  113. };
  114. };
  115. return CartesianAxisPointer;
  116. }(BaseAxisPointer);
  117. function getCartesian(grid, axis) {
  118. var opt = {};
  119. opt[axis.dim + 'AxisIndex'] = axis.index;
  120. return grid.getCartesian(opt);
  121. }
  122. var pointerShapeBuilder = {
  123. line: function (axis, pixelValue, thisExtent, otherExtent) {
  124. var targetShape = viewHelper.makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getAxisDimIndex(axis));
  125. return {
  126. type: 'Line',
  127. subPixelOptimize: true,
  128. shape: targetShape
  129. };
  130. },
  131. shadow: function (axis, pixelValue, thisExtent, otherExtent, seriesDataIndices, ecModel) {
  132. var bandWidth = viewHelper.calcAxisPointerShadowBandWidth(axis, seriesDataIndices, ecModel);
  133. var otherSpan = otherExtent[1] - otherExtent[0];
  134. var _a = viewHelper.calcAxisPointerShadowEnds(pixelValue, thisExtent, bandWidth),
  135. min = _a[0],
  136. max = _a[1];
  137. return {
  138. type: 'Rect',
  139. shape: viewHelper.makeRectShape([min, otherExtent[0]], [max - min, otherSpan], getAxisDimIndex(axis))
  140. };
  141. }
  142. };
  143. function getAxisDimIndex(axis) {
  144. return axis.dim === 'x' ? 0 : 1;
  145. }
  146. export default CartesianAxisPointer;