Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/component/legend/LegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ class LegendView extends ComponentView {
},
onclick() {
api.dispatchAction({
type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect'
type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect',
legendId: legendModel.id
});
}
});
Expand Down
26 changes: 16 additions & 10 deletions src/component/legend/legendAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@
* under the License.
*/

// @ts-nocheck
import {curry, each, hasOwn} from 'zrender/src/core/util';
import { EChartsExtensionInstallRegisters } from '../../extension';
import { Payload } from '../../util/types';
import type GlobalModel from '../../model/Global';
import type LegendModel from './LegendModel';

import {curry, each} from 'zrender/src/core/util';
type LegendSelectMethodNames =
'select' | 'unSelect' |
'toggleSelected' | 'toggleSelected' |
'allSelect' | 'inverseSelect';

function legendSelectActionHandler(methodName, payload, ecModel) {
const selectedMap = {};
function legendSelectActionHandler(methodName: LegendSelectMethodNames, payload: Payload, ecModel: GlobalModel) {
const selectedMap: Record<string, boolean> = {};
const isToggleSelect = methodName === 'toggleSelected';
let isSelected;
// Update all legend components
ecModel.eachComponent('legend', function (legendModel) {
let isSelected: boolean;
ecModel.eachComponent({ mainType: 'legend', query: payload }, function (legendModel: LegendModel) {
if (isToggleSelect && isSelected != null) {
// Force other legend has same selected status
// Or the first is toggled to true and other are toggled to false
Expand All @@ -49,7 +55,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
return;
}
const isItemSelected = legendModel.isSelected(name);
if (selectedMap.hasOwnProperty(name)) {
if (hasOwn(selectedMap, name)) {
// Unselected if any legend is unselected
selectedMap[name] = selectedMap[name] && isItemSelected;
}
Expand All @@ -69,7 +75,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
};
}

export function installLegendAction(registers) {
export function installLegendAction(registers: EChartsExtensionInstallRegisters) {
/**
* @event legendToggleSelect
* @type {Object}
Expand Down Expand Up @@ -113,4 +119,4 @@ export function installLegendAction(registers) {
'legendUnSelect', 'legendunselected',
curry(legendSelectActionHandler, 'unSelect')
);
}
}
106 changes: 106 additions & 0 deletions test/legend-action.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/runTest/actions/legend-action.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.