CartesianAxisPointer.js 5.6 KB

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