-
Notifications
You must be signed in to change notification settings - Fork 19.7k
feat(legend): legend supports triggerEvent
option
#18164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your contribution! Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
Waiting for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review. I think this PR is generally good. Please merge from the master to resolve the conflict and I'll have a quick review again. Please also add a test case.
src/component/legend/legendAction.ts
Outdated
@@ -37,6 +37,9 @@ function legendSelectActionHandler(methodName, payload, ecModel) { | |||
else if (methodName === 'allSelect' || methodName === 'inverseSelect') { | |||
legendModel[methodName](); | |||
} | |||
else if (methodName === 'legendMouseover' || methodName === 'legendMouseout') { | |||
isSelected = legendModel.isSelected(payload.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perhaps no longer needed. You make merge the current master code and have a double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should update the LegendSelectMethodNames
after merging from master.
4a0eebc
to
eb975b0
Compare
src/component/legend/LegendView.ts
Outdated
@@ -223,8 +223,16 @@ class LegendView extends ComponentView { | |||
); | |||
|
|||
itemGroup.on('click', curry(dispatchSelectAction, name, null, api, excludeSeriesId)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From users' perspective, if we use this API style, a complete set of events is supposed to be exposed to users ('click', 'mouseover', 'mouseout', 'mousedown', 'mouseup', 'mousemove', ...).
If we only expose mouseover and mouseout for legend, it may not be a good API design.
Whenever users require additional mouse events, we would need to introduce event names like legendmousexxx1
, legendmousexxx2
, legendmousexxx2
. Furthermore, considering other components, the number of events we need to expose would grow significantly due to the orthogonal composition.
At present we already have setting like title.triggerEvent: true
, xAxis.triggerEvent: true
, radar.triggerEvent
, etc. I think this pattern (xxxcomponent.triggerEvent: boolean
) is better to resolve this requirement and could be a standard way.
option = {
title: {
text: "xxxxx",
tiggerEvent: true,
}
}
const chart = echarts.create(...);
chart.on('mouseover', params => {
if (params.componentType === 'title') {
// do something.
}
});
So I think we should implement legend.triggerEvent
like component title
did.
(Incidentally, the implementation is simpler than the current way)
option = {
legend: {
tiggerEvent: true,
// ...
}
}
const chart = echarts.create(...);
chart.on('mouseover', params => {
if (params.componentType === 'legend') {
// do something.
}
});
Some relevant details:
- by default value should be
false
, for backward compatibility. - The event param should follow the convention.
componentType: 'legend'
componentIndex: number
dataIndex: number
can be provided in the event param to representing different legend items. (follow the style of axis label event)value: string
can be provided in the event param to indicate the legend item value. (follow the style of axis label event)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comments and great suggestions.
I didn't consider the triggerEvent
option, and event name need orthogonal composition.
It was my mistake.
I have modified the code, add legend.triggerEvent
. please help me review it again.
eb975b0
to
694eb8f
Compare
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-18164@87561ee |
694eb8f
to
87561ee
Compare
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
@@ -234,6 +236,11 @@ class LegendView extends ComponentView { | |||
ecData.ssrType = 'legend'; | |||
}); | |||
} | |||
itemGroup.eachChild(child => { | |||
if (triggerEvent) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triggerEvent
option
Brief Information
This pull request is in the type of:
What does this PR do?
add legend event
legendmouseover
legendmouseout
Fixed issues
#18144
Details
Before: What was the problem?
Stop data carousel when mouse hover on legend must customizing legend elements with HTML
see demo:
https://codepen.io/plainheart/pen/xxJRdam
After: How does it behave after the fixing?
Stop data carousel with legend event
legendmouseover
legendmouseout
see demo:
https://stackblitz.com/edit/js-q9vzb5?file=index.js
Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
N.A.
Others
Merging options
Other information