ECEventProcessor.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 { parseClassType } from './clazz.js';
  42. /**
  43. * Usage of query:
  44. * `chart.on('click', query, handler);`
  45. * The `query` can be:
  46. * + The component type query string, only `mainType` or `mainType.subType`,
  47. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  48. * + The component query object, like:
  49. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  50. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  51. * + The data query object, like:
  52. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  53. * + The other query object (cmponent customized query), like:
  54. * `{element: 'some'}` (only available in custom series).
  55. *
  56. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  57. * same as there is no such prop in the `query` object.
  58. */
  59. var ECEventProcessor = /** @class */function () {
  60. function ECEventProcessor() {}
  61. ECEventProcessor.prototype.normalizeQuery = function (query) {
  62. var cptQuery = {};
  63. var dataQuery = {};
  64. var otherQuery = {};
  65. // `query` is `mainType` or `mainType.subType` of component.
  66. if (zrUtil.isString(query)) {
  67. var condCptType = parseClassType(query);
  68. // `.main` and `.sub` may be ''.
  69. cptQuery.mainType = condCptType.main || null;
  70. cptQuery.subType = condCptType.sub || null;
  71. }
  72. // `query` is an object, convert to {mainType, index, name, id}.
  73. else {
  74. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  75. // can not be used in `compomentModel.filterForExposedEvent`.
  76. var suffixes_1 = ['Index', 'Name', 'Id'];
  77. var dataKeys_1 = {
  78. name: 1,
  79. dataIndex: 1,
  80. dataType: 1
  81. };
  82. zrUtil.each(query, function (val, key) {
  83. var reserved = false;
  84. for (var i = 0; i < suffixes_1.length; i++) {
  85. var propSuffix = suffixes_1[i];
  86. var suffixPos = key.lastIndexOf(propSuffix);
  87. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  88. var mainType = key.slice(0, suffixPos);
  89. // Consider `dataIndex`.
  90. if (mainType !== 'data') {
  91. cptQuery.mainType = mainType;
  92. cptQuery[propSuffix.toLowerCase()] = val;
  93. reserved = true;
  94. }
  95. }
  96. }
  97. if (dataKeys_1.hasOwnProperty(key)) {
  98. dataQuery[key] = val;
  99. reserved = true;
  100. }
  101. if (!reserved) {
  102. otherQuery[key] = val;
  103. }
  104. });
  105. }
  106. return {
  107. cptQuery: cptQuery,
  108. dataQuery: dataQuery,
  109. otherQuery: otherQuery
  110. };
  111. };
  112. ECEventProcessor.prototype.filter = function (eventType, query) {
  113. // They should be assigned before each trigger call.
  114. var eventInfo = this.eventInfo;
  115. if (!eventInfo) {
  116. return true;
  117. }
  118. var targetEl = eventInfo.targetEl;
  119. var packedEvent = eventInfo.packedEvent;
  120. var model = eventInfo.model;
  121. var view = eventInfo.view;
  122. // For event like 'globalout'.
  123. if (!model || !view) {
  124. return true;
  125. }
  126. var cptQuery = query.cptQuery;
  127. var dataQuery = query.dataQuery;
  128. return check(cptQuery, model, 'mainType') && check(cptQuery, model, 'subType') && check(cptQuery, model, 'index', 'componentIndex') && check(cptQuery, model, 'name') && check(cptQuery, model, 'id') && check(dataQuery, packedEvent, 'name') && check(dataQuery, packedEvent, 'dataIndex') && check(dataQuery, packedEvent, 'dataType') && (!view.filterForExposedEvent || view.filterForExposedEvent(eventType, query.otherQuery, targetEl, packedEvent));
  129. function check(query, host, prop, propOnHost) {
  130. return query[prop] == null || host[propOnHost || prop] === query[prop];
  131. }
  132. };
  133. ECEventProcessor.prototype.afterTrigger = function () {
  134. // Make sure the eventInfo won't be used in next trigger.
  135. this.eventInfo = null;
  136. };
  137. return ECEventProcessor;
  138. }();
  139. export { ECEventProcessor };
  140. ;