legendAction.js 4.3 KB

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