dataSelectAction.js 4.7 KB

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