dataSelectAction.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 { extend, each, isArray, isString } from 'zrender/lib/core/util.js';
  41. import { deprecateReplaceLog, deprecateLog } from '../util/log.js';
  42. import { queryDataIndex } from '../util/model.js'; // Legacy data selection action.
  43. // Includes: pieSelect, pieUnSelect, pieToggleSelect, mapSelect, mapUnSelect, mapToggleSelect
  44. export function createLegacyDataSelectAction(seriesType, ecRegisterAction) {
  45. function getSeriesIndices(ecModel, payload) {
  46. var seriesIndices = [];
  47. ecModel.eachComponent({
  48. mainType: 'series',
  49. subType: seriesType,
  50. query: payload
  51. }, function (seriesModel) {
  52. seriesIndices.push(seriesModel.seriesIndex);
  53. });
  54. return seriesIndices;
  55. }
  56. each([[seriesType + 'ToggleSelect', 'toggleSelect'], [seriesType + 'Select', 'select'], [seriesType + 'UnSelect', 'unselect']], function (eventsMap) {
  57. ecRegisterAction(eventsMap[0], function (payload, ecModel, api) {
  58. payload = extend({}, payload);
  59. if (process.env.NODE_ENV !== 'production') {
  60. deprecateReplaceLog(payload.type, eventsMap[1]);
  61. }
  62. api.dispatchAction(extend(payload, {
  63. type: eventsMap[1],
  64. seriesIndex: getSeriesIndices(ecModel, payload)
  65. }));
  66. });
  67. });
  68. }
  69. function handleSeriesLegacySelectEvents(type, eventPostfix, ecIns, ecModel, payload) {
  70. var legacyEventName = type + eventPostfix;
  71. if (!ecIns.isSilent(legacyEventName)) {
  72. if (process.env.NODE_ENV !== 'production') {
  73. deprecateLog("event " + legacyEventName + " is deprecated.");
  74. }
  75. ecModel.eachComponent({
  76. mainType: 'series',
  77. subType: 'pie'
  78. }, function (seriesModel) {
  79. var seriesIndex = seriesModel.seriesIndex;
  80. var selectedMap = seriesModel.option.selectedMap;
  81. var selected = payload.selected;
  82. for (var i = 0; i < selected.length; i++) {
  83. if (selected[i].seriesIndex === seriesIndex) {
  84. var data = seriesModel.getData();
  85. var dataIndex = queryDataIndex(data, payload.fromActionPayload);
  86. ecIns.trigger(legacyEventName, {
  87. type: legacyEventName,
  88. seriesId: seriesModel.id,
  89. name: isArray(dataIndex) ? data.getName(dataIndex[0]) : data.getName(dataIndex),
  90. selected: isString(selectedMap) ? selectedMap : extend({}, selectedMap)
  91. });
  92. }
  93. }
  94. });
  95. }
  96. }
  97. export function handleLegacySelectEvents(messageCenter, ecIns, api) {
  98. messageCenter.on('selectchanged', function (params) {
  99. var ecModel = api.getModel();
  100. if (params.isFromClick) {
  101. handleSeriesLegacySelectEvents('map', 'selectchanged', ecIns, ecModel, params);
  102. handleSeriesLegacySelectEvents('pie', 'selectchanged', ecIns, ecModel, params);
  103. } else if (params.fromAction === 'select') {
  104. handleSeriesLegacySelectEvents('map', 'selected', ecIns, ecModel, params);
  105. handleSeriesLegacySelectEvents('pie', 'selected', ecIns, ecModel, params);
  106. } else if (params.fromAction === 'unselect') {
  107. handleSeriesLegacySelectEvents('map', 'unselected', ecIns, ecModel, params);
  108. handleSeriesLegacySelectEvents('pie', 'unselected', ecIns, ecModel, params);
  109. }
  110. });
  111. }