Skip to content
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

fix: hightlight multiple series not work as expected #15207

Merged
merged 7 commits into from
Jul 2, 2021

Conversation

ssthouse
Copy link
Contributor

@ssthouse ssthouse commented Jun 22, 2021

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Fixed issues

Close #15204

Details

Before: What was the problem?

Dispatch hightlight action with the following code only highlight the lastest series; The expected result is all three series are highlighted;

dispatchAction({
    type: 'highlight',
    seriesIndex: [0, 1, 2],
});

image

After: How is it fixed in this PR?

Fix the logic of running blur unHighlighted series multiple times;

Jun-22-2021 13-10-57

Misc

  • The API has been changed (apache/echarts-doc#xxx).
  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

NA.

Others

Merging options

  • Please squash the commits into a single one when merge.

Other information

@echarts-bot
Copy link

echarts-bot bot commented Jun 22, 2021

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

@pissang pissang added this to the 5.2 milestone Jun 22, 2021
@pissang pissang requested review from pissang and 100pah June 22, 2021 07:51
@pissang
Copy link
Contributor

pissang commented Jun 22, 2021

The fix looks neat! One suggestion: this test case can be put in hoverFocus2.html. It has similar cases

@ssthouse
Copy link
Contributor Author

The fix looks neat! One suggestion: this test case can be put in hoverFocus2.html. It has similar cases

fixed~

if (!excludeSeriesIdMap || excludeSeriesIdMap.get(model.id) == null) {
if (isHighDownPayload(payload)) {
if (model instanceof SeriesModel) {
if (payload.type === HIGHLIGHT_ACTION_TYPE && !payload.notBlur) {
// only blur once
const isFirstTimeBlur = modelIndex === 0;
Copy link
Contributor

@pissang pissang Jun 22, 2021

Choose a reason for hiding this comment

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

In some cases modelndex may not be 0. It’s the index in the option. For example: if we change the test code to:

chart.dispatchAction({
  type: 'highlight',
  seriesIndex: [1],
 });

The modelIndex of the first iteration will be 1. And no series will be blurred, which is not expected.

I think a better solution is using a flag to check if any series triggers blur.

There is another situation I think we need to consider:
If we set blurScope to series. Only other data in the same series will be blurred. Should we still use the "only one series will trigger blur" policy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another unrelated suggestion:

I think the old case you are using can be added to hoverFocus.html. It's more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pissang Hi~

In some cases modelndex may not be 0. It’s the index in the option.

I have changed to flag implementation now~
(I was thinking that the second params index always starts with zero like Array.forEach. )

There is another situation I think we need to consider:
If we set blurScope to series. Only other data in the same series will be blurred. Should we still use the "only one series will trigger blur" policy?

I think when blurScope === 'series', we can stick to the original blur all logic.

I think the old case you are using can be added to hoverFocus.html. It's more clear.

👌 I have moved the old testcase into the hoverFocus.html.

When blurScope="series"
Jun-23-2021 17-26-08

When blurScope!="series"
Jun-23-2021 17-24-51

Copy link
Contributor

@pissang pissang Jun 23, 2021

Choose a reason for hiding this comment

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

(I was thinking that the second params index always starts with zero like Array.forEach. )

Yeah, this API design may be misleading.

I think when blurScope === 'series', we can stick to the original blur all logic.

There is another option blurScope: 'coordinateSystem' may have a similar issue. I'm thinking if we can support multiple series in

export function blurSeriesFromHighlightPayload(
and
export function blurSeries(

Perhaps it's a better place to do this complex logic.

BTW: this comment can be removed to avoid confusion.

// TODO blurScope: coordinate system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pissang I moved the logic into echarts/src/util/states.ts;
(ps: the code modification in src/core/echarts.ts now is to improve code readability)

And for blurScope: 'coordinateSystem', a new testcase is added in hoverFocus.html

coordinate

@ssthouse ssthouse force-pushed the fix/multiple-series-highlight branch from bc3399e to e193f6a Compare June 24, 2021 05:27
@@ -437,7 +438,10 @@ export function blurSeries(

const blurredSeries: SeriesModel[] = [];

ecModel.eachSeries(function (seriesModel) {
ecModel.eachSeries(function (seriesModel, seriesIndex) {
if (excludedSeriesIndexes && excludedSeriesIndexes.includes(seriesIndex)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

includes is not supported in IE 9+, which we still supported currently. We can use zrUtil.indexOf(excludedSeriesIndexes, seriesIndex) >= 0 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -529,11 +532,12 @@ export function blurSeriesFromHighlightPayload(
el = data.getItemGraphicEl(current++);
}
}
const excludedSeriesIndexes = payload.seriesIndex || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

seriesIndex is one of the possible queries. Developers can also use payload.seriesId to query target series. Perhaps we need to query the highlight seriesModel list in echarts.ts and pass it to this function.

Also, I'm not sure if there is a logic issue:

If we have focus: 'self' in one series and dispatch a highlight action on this series. This series will also be in this excludedSeriesIndexes and not perform the focus: 'self' strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I'm not sure if there is a logic issue:

If we have focus: 'self' in one series and dispatch a highlight action on this series. This series will also be in this excludedSeriesIndexes and not perform the focus: 'self' strategy.

Yes, There is a logic issue. I add another testcase for this.
Please take a look if this is the expected result~

Jun-26-2021 20-31-19

@@ -409,7 +409,8 @@ export function blurSeries(
targetSeriesIndex: number,
focus: InnerFocus,
blurScope: BlurScope,
api: ExtensionAPI
api: ExtensionAPI,
excludedSeriesIndexes?: number[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be indices instead of indexes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

emphasis: coordinateSystemBlurEmphasis,
},
],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems these new cases are mainly target for the hover focus feature. We can append them in hoverFocus.html instead of adding them in the basicChartOptions. Options in basicChartOptions are usually very basic and will be used in tests of many features.

Also, if we want to add a new test case, always adding it at the tail instead of the head. Or it will affect the replay of user interactions in the automatic visual regression testing tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, fixed~

- fix indexed to indices
- move testcase from basicChartsOptions -> hoverFocus.html
@ssthouse ssthouse force-pushed the fix/multiple-series-highlight branch from 3f222af to 9c3a81c Compare June 26, 2021 11:46
@@ -454,7 +457,8 @@ export function blurSeries(
|| blurScope === 'coordinateSystem' && !sameCoordSys
// Not blur self series if focus is series.
|| focus === 'series' && sameSeries
// TODO blurScope: coordinate system
// Not blur other series if focus is self
|| focus === 'self' && !sameSeries
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need to blur other series if blurScope is 'global' and focus is 'self'. You can run visual regression test(VRT in short) on hoverFocus.html, hoverFocus2.html to see if anythings breaks. The command of starting VRT is:

npm run test:visual

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pissang Hi,I found it's complicated to first blur then highlight for each series, like this;

for(const series of seriesList){
    blurNecessaryPart(series);
    highlightCurrent(series);
}

Since the previous highlighted series can be easily blurred by the latter series;
It may be more clear if we first blur all the necessary parts then hight all the necessary parts, like this;

for(const series of seriesList){
    blurNecessaryPart(series);
}
for(const series of seriesList){
    highlightCurrent(series);
}

I modified the current code to this scenario and tested with npm run test:visual, please take a look~

Copy link
Contributor

@pissang pissang Jul 2, 2021

Choose a reason for hiding this comment

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

@ssthouse That's brilliant! It should work well. I can't find other issues. The only thing that needs to be done is recording the user interactions on the new add test case so we can test it automatically.

You can click the Record Interaction on the VRT page button to open the recording page. Then follow the hint on the page and use the shortcut key to start recording. During the recording, you can click buttons, hover elements. Each click will trigger a screenshot to compare, but hover won't. So if you want to compare the current picture, you should at least click or use the shortcut key to trigger the screenshot.

Usually, each action needs to focus on one test case and the interaction count in each action should be as less as possible. Feel free to ask me if you have any problem with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pissang I have recorded the testcases and tried to run them.
Currently, it failed(as expected), is there anything I should do to make it pass?

image

@ssthouse ssthouse force-pushed the fix/multiple-series-highlight branch from bd77c90 to e8a9a0f Compare July 2, 2021 02:42
@pissang pissang merged commit d14ccfc into apache:master Jul 2, 2021
@echarts-bot
Copy link

echarts-bot bot commented Jul 2, 2021

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants