Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion src/component/legend/LegendModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export interface LegendOption extends ComponentOption, LegendStyleOption,
*/
tooltip?: CommonTooltipOption<LegendTooltipFormatterParams>

triggerEvent?: boolean
}

class LegendModel<Ops extends LegendOption = LegendOption> extends ComponentModel<Ops> {
Expand Down Expand Up @@ -530,7 +531,9 @@ class LegendModel<Ops extends LegendOption = LegendOption> extends ComponentMode

tooltip: {
show: false
}
},

triggerEvent: false
};
}

Expand Down
30 changes: 28 additions & 2 deletions src/component/legend/LegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {createSymbol, ECSymbol} from '../../util/symbol';
import SeriesModel from '../../model/Series';
import { createOrUpdatePatternFromDecal } from '../../util/decal';
import { getECData } from '../../util/innerStore';
import Element from 'zrender/src/Element';

const curry = zrUtil.curry;
const each = zrUtil.each;
Expand Down Expand Up @@ -177,6 +178,7 @@ class LegendView extends ComponentView {
const contentGroup = this.getContentGroup();
const legendDrawnMap = zrUtil.createHashMap();
const selectMode = legendModel.get('selectedMode');
const triggerEvent = legendModel.get('triggerEvent');

const excludeSeriesId: string[] = [];
ecModel.eachRawSeries(function (seriesModel) {
Expand Down Expand Up @@ -234,6 +236,11 @@ class LegendView extends ComponentView {
ecData.ssrType = 'legend';
});
}
itemGroup.eachChild(child => {
if (triggerEvent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding the if check before the each function to avoid unnecessary invocation if triggerEvent is not enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do this later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plainheart

It's in #20907

Please help me to review.

Thanks.

this.packEventData(child, legendModel, seriesModel, dataIndex, name);
}
});

legendDrawnMap.set(name, true);
}
Expand Down Expand Up @@ -287,7 +294,11 @@ class LegendView extends ComponentView {
ecData.ssrType = 'legend';
});
}

itemGroup.eachChild(child => {
if (triggerEvent) {
this.packEventData(child, legendModel, seriesModel, dataIndex, name);
}
});
legendDrawnMap.set(name, true);
}

Expand All @@ -307,7 +318,22 @@ class LegendView extends ComponentView {
this._createSelector(selector, legendModel, api, orient, selectorPosition);
}
}

private packEventData(
el: Element,
legendModel: LegendModel,
seriesModel: SeriesModel<SeriesOption & SymbolOptionMixin>,
dataIndex: number,
name: string
) {
const eventData = {
componentType: 'legend',
componentIndex: legendModel.componentIndex,
dataIndex,
value: name,
seriesIndex: seriesModel.seriesIndex,
};
getECData(el).eventData = eventData;
};
private _createSelector(
selector: LegendSelectorButtonOption[],
legendModel: LegendModel,
Expand Down
66 changes: 66 additions & 0 deletions test/legend-action.html

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