You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2024/07/08 10:43:37 UTC
(echarts) branch fix/legend-action-isolation created (now 5c84ce2b8)
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a change to branch fix/legend-action-isolation
in repository https://gitbox.apache.org/repos/asf/echarts.git
at 5c84ce2b8 fix(legend): fix legend action is not isolated from other legend components (resolves #20128)
This branch includes the following new commits:
new 5c84ce2b8 fix(legend): fix legend action is not isolated from other legend components (resolves #20128)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
(echarts) 01/01: fix(legend): fix legend action is not isolated from other legend components (resolves #20128)
Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a commit to branch fix/legend-action-isolation
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 5c84ce2b8d77615dfb9519bb7ed6a80adfe58456
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Mon Jul 8 18:40:53 2024 +0800
fix(legend): fix legend action is not isolated from other legend components (resolves #20128)
---
src/component/legend/LegendView.ts | 3 ++-
src/component/legend/legendAction.ts | 28 ++++++++++++++++++----------
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts
index 35b0779f2..901646824 100644
--- a/src/component/legend/LegendView.ts
+++ b/src/component/legend/LegendView.ts
@@ -329,7 +329,8 @@ class LegendView extends ComponentView {
},
onclick() {
api.dispatchAction({
- type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect'
+ type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect',
+ legendId: legendModel.id
});
}
});
diff --git a/src/component/legend/legendAction.ts b/src/component/legend/legendAction.ts
index 04ed3723a..225a18d34 100644
--- a/src/component/legend/legendAction.ts
+++ b/src/component/legend/legendAction.ts
@@ -17,16 +17,23 @@
* 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;
+ const legendModels = ecModel.findComponents({ mainType: 'legend', query: payload }) as LegendModel[];
+ each(legendModels, 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
@@ -49,7 +56,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;
}
@@ -58,6 +65,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
}
});
});
+
// Return the event explicitly
return (methodName === 'allSelect' || methodName === 'inverseSelect')
? {
@@ -69,7 +77,7 @@ function legendSelectActionHandler(methodName, payload, ecModel) {
};
}
-export function installLegendAction(registers) {
+export function installLegendAction(registers: EChartsExtensionInstallRegisters) {
/**
* @event legendToggleSelect
* @type {Object}
@@ -113,4 +121,4 @@ export function installLegendAction(registers) {
'legendUnSelect', 'legendunselected',
curry(legendSelectActionHandler, 'unSelect')
);
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org