18d569a597e74406551f3f64cd8754f4fb3dde6b500b842f2400dace972f9aedadcfb3bd073bd97dedfce9ad9afabac86806b444567cc5dc41ec733c996adb 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 * as zrUtil from 'zrender/lib/core/util.js';
  41. import env from 'zrender/lib/core/env.js';
  42. import { makeInner } from '../../util/model.js';
  43. var inner = makeInner();
  44. var each = zrUtil.each;
  45. /**
  46. * @param {string} key
  47. * @param {module:echarts/ExtensionAPI} api
  48. * @param {Function} handler
  49. * param: {string} currTrigger
  50. * param: {Array.<number>} point
  51. */
  52. export function register(key, api, handler) {
  53. if (env.node) {
  54. return;
  55. }
  56. var zr = api.getZr();
  57. inner(zr).records || (inner(zr).records = {});
  58. initGlobalListeners(zr, api);
  59. var record = inner(zr).records[key] || (inner(zr).records[key] = {});
  60. record.handler = handler;
  61. }
  62. function initGlobalListeners(zr, api) {
  63. if (inner(zr).initialized) {
  64. return;
  65. }
  66. inner(zr).initialized = true;
  67. useHandler('click', zrUtil.curry(doEnter, 'click'));
  68. useHandler('mousemove', zrUtil.curry(doEnter, 'mousemove')); // useHandler('mouseout', onLeave);
  69. useHandler('globalout', onLeave);
  70. function useHandler(eventType, cb) {
  71. zr.on(eventType, function (e) {
  72. var dis = makeDispatchAction(api);
  73. each(inner(zr).records, function (record) {
  74. record && cb(record, e, dis.dispatchAction);
  75. });
  76. dispatchTooltipFinally(dis.pendings, api);
  77. });
  78. }
  79. }
  80. function dispatchTooltipFinally(pendings, api) {
  81. var showLen = pendings.showTip.length;
  82. var hideLen = pendings.hideTip.length;
  83. var actuallyPayload;
  84. if (showLen) {
  85. actuallyPayload = pendings.showTip[showLen - 1];
  86. } else if (hideLen) {
  87. actuallyPayload = pendings.hideTip[hideLen - 1];
  88. }
  89. if (actuallyPayload) {
  90. actuallyPayload.dispatchAction = null;
  91. api.dispatchAction(actuallyPayload);
  92. }
  93. }
  94. function onLeave(record, e, dispatchAction) {
  95. record.handler('leave', null, dispatchAction);
  96. }
  97. function doEnter(currTrigger, record, e, dispatchAction) {
  98. record.handler(currTrigger, e, dispatchAction);
  99. }
  100. function makeDispatchAction(api) {
  101. var pendings = {
  102. showTip: [],
  103. hideTip: []
  104. }; // FIXME
  105. // better approach?
  106. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  107. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  108. // So we have to add "final stage" to merge those dispatched actions.
  109. var dispatchAction = function (payload) {
  110. var pendingList = pendings[payload.type];
  111. if (pendingList) {
  112. pendingList.push(payload);
  113. } else {
  114. payload.dispatchAction = dispatchAction;
  115. api.dispatchAction(payload);
  116. }
  117. };
  118. return {
  119. dispatchAction: dispatchAction,
  120. pendings: pendings
  121. };
  122. }
  123. export function unregister(key, api) {
  124. if (env.node) {
  125. return;
  126. }
  127. var zr = api.getZr();
  128. var record = (inner(zr).records || {})[key];
  129. if (record) {
  130. inner(zr).records[key] = null;
  131. }
  132. }