1717* under the License.
1818*/
1919
20- // @ts -nocheck
20+ import { curry , each , hasOwn } from 'zrender/src/core/util' ;
21+ import { EChartsExtensionInstallRegisters } from '../../extension' ;
22+ import { Payload } from '../../util/types' ;
23+ import type GlobalModel from '../../model/Global' ;
24+ import type LegendModel from './LegendModel' ;
2125
22- import { curry , each } from 'zrender/src/core/util' ;
26+ type LegendSelectMethodNames =
27+ 'select' | 'unSelect' |
28+ 'toggleSelected' | 'toggleSelected' |
29+ 'allSelect' | 'inverseSelect' ;
2330
24- function legendSelectActionHandler ( methodName , payload , ecModel ) {
25- const selectedMap = { } ;
31+ function legendSelectActionHandler ( methodName : LegendSelectMethodNames , payload : Payload , ecModel : GlobalModel ) {
32+ const selectedMap : Record < string , boolean > = { } ;
2633 const isToggleSelect = methodName === 'toggleSelected' ;
27- let isSelected ;
28- // Update all legend components
29- ecModel . eachComponent ( 'legend' , function ( legendModel ) {
34+ let isSelected : boolean ;
35+ const legendModels = ecModel . findComponents ( { mainType : ' legend' , query : payload } ) as LegendModel [ ] ;
36+ each ( legendModels , function ( legendModel : LegendModel ) {
3037 if ( isToggleSelect && isSelected != null ) {
3138 // Force other legend has same selected status
3239 // Or the first is toggled to true and other are toggled to false
@@ -49,7 +56,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
4956 return ;
5057 }
5158 const isItemSelected = legendModel . isSelected ( name ) ;
52- if ( selectedMap . hasOwnProperty ( name ) ) {
59+ if ( hasOwn ( selectedMap , name ) ) {
5360 // Unselected if any legend is unselected
5461 selectedMap [ name ] = selectedMap [ name ] && isItemSelected ;
5562 }
@@ -58,6 +65,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
5865 }
5966 } ) ;
6067 } ) ;
68+
6169 // Return the event explicitly
6270 return ( methodName === 'allSelect' || methodName === 'inverseSelect' )
6371 ? {
@@ -69,7 +77,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
6977 } ;
7078}
7179
72- export function installLegendAction ( registers ) {
80+ export function installLegendAction ( registers : EChartsExtensionInstallRegisters ) {
7381 /**
7482 * @event legendToggleSelect
7583 * @type {Object }
@@ -113,4 +121,4 @@ export function installLegendAction(registers) {
113121 'legendUnSelect' , 'legendunselected' ,
114122 curry ( legendSelectActionHandler , 'unSelect' )
115123 ) ;
116- }
124+ }
0 commit comments