ECEventProcessor.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 =
  60. /** @class */
  61. function () {
  62. function ECEventProcessor() {}
  63. ECEventProcessor.prototype.normalizeQuery = function (query) {
  64. var cptQuery = {};
  65. var dataQuery = {};
  66. var otherQuery = {}; // `query` is `mainType` or `mainType.subType` of component.
  67. if (zrUtil.isString(query)) {
  68. var condCptType = parseClassType(query); // `.main` and `.sub` may be ''.
  69. cptQuery.mainType = condCptType.main || null;
  70. cptQuery.subType = condCptType.sub || null;
  71. } // `query` is an object, convert to {mainType, index, name, id}.
  72. else {
  73. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  74. // can not be used in `compomentModel.filterForExposedEvent`.
  75. var suffixes_1 = ['Index', 'Name', 'Id'];
  76. var dataKeys_1 = {
  77. name: 1,
  78. dataIndex: 1,
  79. dataType: 1
  80. };
  81. zrUtil.each(query, function (val, key) {
  82. var reserved = false;
  83. for (var i = 0; i < suffixes_1.length; i++) {
  84. var propSuffix = suffixes_1[i];
  85. var suffixPos = key.lastIndexOf(propSuffix);
  86. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  87. var mainType = key.slice(0, suffixPos); // Consider `dataIndex`.
  88. if (mainType !== 'data') {
  89. cptQuery.mainType = mainType;
  90. cptQuery[propSuffix.toLowerCase()] = val;
  91. reserved = true;
  92. }
  93. }
  94. }
  95. if (dataKeys_1.hasOwnProperty(key)) {
  96. dataQuery[key] = val;
  97. reserved = true;
  98. }
  99. if (!reserved) {
  100. otherQuery[key] = val;
  101. }
  102. });
  103. }
  104. return {
  105. cptQuery: cptQuery,
  106. dataQuery: dataQuery,
  107. otherQuery: otherQuery
  108. };
  109. };
  110. ECEventProcessor.prototype.filter = function (eventType, query) {
  111. // They should be assigned before each trigger call.
  112. var eventInfo = this.eventInfo;
  113. if (!eventInfo) {
  114. return true;
  115. }
  116. var targetEl = eventInfo.targetEl;
  117. var packedEvent = eventInfo.packedEvent;
  118. var model = eventInfo.model;
  119. var view = eventInfo.view; // For event like 'globalout'.
  120. if (!model || !view) {
  121. return true;
  122. }
  123. var cptQuery = query.cptQuery;
  124. var dataQuery = query.dataQuery;
  125. 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));
  126. function check(query, host, prop, propOnHost) {
  127. return query[prop] == null || host[propOnHost || prop] === query[prop];
  128. }
  129. };
  130. ECEventProcessor.prototype.afterTrigger = function () {
  131. // Make sure the eventInfo won't be used in next trigger.
  132. this.eventInfo = null;
  133. };
  134. return ECEventProcessor;
  135. }();
  136. export { ECEventProcessor };
  137. ;