legendAction.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // @ts-nocheck
  41. import { curry, each } from 'zrender/lib/core/util.js';
  42. function legendSelectActionHandler(methodName, payload, ecModel) {
  43. var selectedMap = {};
  44. var isToggleSelect = methodName === 'toggleSelected';
  45. var isSelected; // Update all legend components
  46. ecModel.eachComponent('legend', function (legendModel) {
  47. if (isToggleSelect && isSelected != null) {
  48. // Force other legend has same selected status
  49. // Or the first is toggled to true and other are toggled to false
  50. // In the case one legend has some item unSelected in option. And if other legend
  51. // doesn't has the item, they will assume it is selected.
  52. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  53. } else if (methodName === 'allSelect' || methodName === 'inverseSelect') {
  54. legendModel[methodName]();
  55. } else {
  56. legendModel[methodName](payload.name);
  57. isSelected = legendModel.isSelected(payload.name);
  58. }
  59. var legendData = legendModel.getData();
  60. each(legendData, function (model) {
  61. var name = model.get('name'); // Wrap element
  62. if (name === '\n' || name === '') {
  63. return;
  64. }
  65. var isItemSelected = legendModel.isSelected(name);
  66. if (selectedMap.hasOwnProperty(name)) {
  67. // Unselected if any legend is unselected
  68. selectedMap[name] = selectedMap[name] && isItemSelected;
  69. } else {
  70. selectedMap[name] = isItemSelected;
  71. }
  72. });
  73. }); // Return the event explicitly
  74. return methodName === 'allSelect' || methodName === 'inverseSelect' ? {
  75. selected: selectedMap
  76. } : {
  77. name: payload.name,
  78. selected: selectedMap
  79. };
  80. }
  81. export function installLegendAction(registers) {
  82. /**
  83. * @event legendToggleSelect
  84. * @type {Object}
  85. * @property {string} type 'legendToggleSelect'
  86. * @property {string} [from]
  87. * @property {string} name Series name or data item name
  88. */
  89. registers.registerAction('legendToggleSelect', 'legendselectchanged', curry(legendSelectActionHandler, 'toggleSelected'));
  90. registers.registerAction('legendAllSelect', 'legendselectall', curry(legendSelectActionHandler, 'allSelect'));
  91. registers.registerAction('legendInverseSelect', 'legendinverseselect', curry(legendSelectActionHandler, 'inverseSelect'));
  92. /**
  93. * @event legendSelect
  94. * @type {Object}
  95. * @property {string} type 'legendSelect'
  96. * @property {string} name Series name or data item name
  97. */
  98. registers.registerAction('legendSelect', 'legendselected', curry(legendSelectActionHandler, 'select'));
  99. /**
  100. * @event legendUnSelect
  101. * @type {Object}
  102. * @property {string} type 'legendUnSelect'
  103. * @property {string} name Series name or data item name
  104. */
  105. registers.registerAction('legendUnSelect', 'legendunselected', curry(legendSelectActionHandler, 'unSelect'));
  106. }