findPointFromSeries.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. var zrUtil = require("zrender/lib/core/util");
  20. var modelUtil = require("../../util/model");
  21. /*
  22. * Licensed to the Apache Software Foundation (ASF) under one
  23. * or more contributor license agreements. See the NOTICE file
  24. * distributed with this work for additional information
  25. * regarding copyright ownership. The ASF licenses this file
  26. * to you under the Apache License, Version 2.0 (the
  27. * "License"); you may not use this file except in compliance
  28. * with the License. You may obtain a copy of the License at
  29. *
  30. * http://www.apache.org/licenses/LICENSE-2.0
  31. *
  32. * Unless required by applicable law or agreed to in writing,
  33. * software distributed under the License is distributed on an
  34. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35. * KIND, either express or implied. See the License for the
  36. * specific language governing permissions and limitations
  37. * under the License.
  38. */
  39. /**
  40. * @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
  41. * @param {module:echarts/model/Global} ecModel
  42. * @return {Object} {point: [x, y], el: ...} point Will not be null.
  43. */
  44. function _default(finder, ecModel) {
  45. var point = [];
  46. var seriesIndex = finder.seriesIndex;
  47. var seriesModel;
  48. if (seriesIndex == null || !(seriesModel = ecModel.getSeriesByIndex(seriesIndex))) {
  49. return {
  50. point: []
  51. };
  52. }
  53. var data = seriesModel.getData();
  54. var dataIndex = modelUtil.queryDataIndex(data, finder);
  55. if (dataIndex == null || dataIndex < 0 || zrUtil.isArray(dataIndex)) {
  56. return {
  57. point: []
  58. };
  59. }
  60. var el = data.getItemGraphicEl(dataIndex);
  61. var coordSys = seriesModel.coordinateSystem;
  62. if (seriesModel.getTooltipPosition) {
  63. point = seriesModel.getTooltipPosition(dataIndex) || [];
  64. } else if (coordSys && coordSys.dataToPoint) {
  65. point = coordSys.dataToPoint(data.getValues(zrUtil.map(coordSys.dimensions, function (dim) {
  66. return data.mapDimension(dim);
  67. }), dataIndex, true)) || [];
  68. } else if (el) {
  69. // Use graphic bounding rect
  70. var rect = el.getBoundingRect().clone();
  71. rect.applyTransform(el.transform);
  72. point = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  73. }
  74. return {
  75. point: point,
  76. el: el
  77. };
  78. }
  79. module.exports = _default;