Skip to content

feat(visualMap): add seriesTargets option for multiple series-dimension mappings#20703

Merged
plainheart merged 6 commits intoapache:masterfrom
Justin-ZS:fix/20662
Oct 31, 2025
Merged

feat(visualMap): add seriesTargets option for multiple series-dimension mappings#20703
plainheart merged 6 commits intoapache:masterfrom
Justin-ZS:fix/20662

Conversation

@Justin-ZS
Copy link
Copy Markdown
Contributor

@Justin-ZS Justin-ZS commented Jan 20, 2025

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

official demo

option =  {
    visualMap: {   
        // Introduce a new option `target`.
        // When `target` is provided, `visualMap.seriesIndex`, `visualMap.seriesId`, `visualMap.dimension`
        // are ignored.
        target: [{
            seriesIndex: 3,
            dimension: 2,
        }, {
            seriesId: 'xxx', // either seriesId or seriesIndex
            dimension: 1,
        },
        ...
        ]
    }
};
截屏2025-09-28 18 16 34

Fixed issues

#20662
#14346
Also fix #20347:
截屏2025-01-23 11 08 53

Details

Before: What was the problem?

Single visualMap cannot be used for 2d dataset.

After: How does it behave after the fixing?

mapping series to dimension by seriesTargets

Document Info

One of the following should be checked.

Misc

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

N.A.

Others

Merging options

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

Other information

@echarts-bot echarts-bot Bot added PR: awaiting doc Document changes is required for this PR. PR: awaiting review labels Jan 20, 2025
@echarts-bot
Copy link
Copy Markdown

echarts-bot Bot commented Jan 20, 2025

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.

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 PR: awaiting doc label.

Copy link
Copy Markdown
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

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

I don't think it's intuitive to use dimension: [1,2] to represent seriesIndex: 0 -> 1, 1 -> 2, 2 -> 2. Instead, it's more like using both dimension 1 and 2.

I think the problem of #20662 should be best solved using the third demo @MatthiasMert gave. I would suggest closing this PR unless a more solid reason is given. Thanks for your contribution anyway.

@Justin-ZS
Copy link
Copy Markdown
Contributor Author

I don't think it's intuitive to use dimension: [1,2] to represent seriesIndex: 0 -> 1, 1 -> 2, 2 -> 2. Instead, it's more like using both dimension 1 and 2.

I think the problem of #20662 should be best solved using the third demo @MatthiasMert gave. I would suggest closing this PR unless a more solid reason is given. Thanks for your contribution anyway.

Using the same visualMap on 2d dataset requires the dataset to be splitted looks overkill.
dimension: [1,2] cannot be explained as using both dimension 1 and 2 since one series can use only one dimension
using both dimension 1 and 2 is technically impossible, unless you choose to provide a function to aggreagte multiple values

@Justin-ZS Justin-ZS requested a review from Ovilia January 21, 2025 09:34
Copy link
Copy Markdown
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

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

It's true that using both dimension 1 and 2 is technically impossible. Even though, it's misleading to provide such API design. Again, I would suggest using the 3rd solution or avoid using dataset in your case. Adding a new feature should take a lot of things into consideration so I would say it's not quite a good design of API unless a better plan is proposed.

@Justin-ZS
Copy link
Copy Markdown
Contributor Author

Justin-ZS commented Jan 22, 2025

It's true that using both dimension 1 and 2 is technically impossible. Even though, it's misleading to provide such API design. Again, I would suggest using the 3rd solution or avoid using dataset in your case. Adding a new feature should take a lot of things into consideration so I would say it's not quite a good design of API unless a better plan is proposed.

Again, the suggested workaround (splitting the dataset) is unacceptable in my use case.

I understand your concerns about the API design.
I do think this PR is a simple and clear solution for similar cases.
We can provide detailed document to clarify the correct uasge.

Even if user is misled into thinking it as using both dimension 1 and 2, user will still use the numeric dimension unless they want to map multiple dimensions.
Then, they will find the correct usage through document or just a few attempts.

if you insist, I will keep this PR open until a better solutiion is proposed.

@Ovilia
Copy link
Copy Markdown
Contributor

Ovilia commented Jan 22, 2025

Why is the suggested workaround (splitting the dataset) unacceptable?

@Justin-ZS
Copy link
Copy Markdown
Contributor Author

Why is the suggested workaround (splitting the dataset) unacceptable?

It requires huge refactoring (tooltip, axis. series and so on) and maintaining two implementations.
And the splitted datasets may cause other limitations or bugs.
As a workaround for now, I added the same visualmap for each series and only show the first controller.
When selection changes, use setOption to sync the state cross all visualMaps.
But the hoverLink interaction cannot be synced.

@Ovilia
Copy link
Copy Markdown
Contributor

Ovilia commented Jan 22, 2025

I don't think it should require huge work to refactor from dataset to not. And besides, you can try with AI to help.

@100pah
Copy link
Copy Markdown
Member

100pah commented Sep 28, 2025

I think the basic requirement is reasonable. A visualMap component should be able to control multiple series, and the dimension for each series should be able to configured.

But I'm afraid the current proposed API is not intuitive and seems hard to understand.
I also believe that complicated default value strategies (e.g., if no seriesIndex provided, then xxx) should not be introduced unless necessary, as it may cause unexpected behavior and confuse users.

For this requirement, in my opinion, the API can be designed as:

option =  {
    visualMap: {   
        // Introduce a new option `target`.
        // When `target` is provided, `visualMap.seriesIndex`, `visualMap.seriesId`, `visualMap.dimension`
        // are ignored.
        target: [{
            seriesIndex: 3,
            dimension: 2,
        }, {
            seriesId: 'xxx', // either seriesId or seriesIndex
            dimension: 1,
        },
        ...
        ]
    }
};

@Justin-ZS
Copy link
Copy Markdown
Contributor Author

Justin-ZS commented Sep 28, 2025

I think the basic requirement is reasonable. A visualMap component should be able to control multiple series, and the dimension for each series should be able to configured.

But I'm afraid the current proposed API is not intuitive and seems hard to understand. I also believe that complicated default value strategies (e.g., if no seriesIndex provided, then xxx) should not be introduced unless necessary, as it may cause unexpected behavior and confuse users.

For this requirement, in my opinion, the API can be designed as:

option =  {
    visualMap: {   
        // Introduce a new option `target`.
        // When `target` is provided, `visualMap.seriesIndex`, `visualMap.seriesId`, `visualMap.dimension`
        // are ignored.
        target: [{
            seriesIndex: 3,
            dimension: 2,
        }, {
            seriesId: 'xxx', // either seriesId or seriesIndex
            dimension: 1,
        },
        ...
        ]
    }
};

VisualMap already has a target property.
I will use the name seriesTargets

@Justin-ZS Justin-ZS changed the title feat(visualMap): able to set the 'dimension' to an array feat(visualMap): add seriesTargets to mapping different series -> dimension Sep 29, 2025
@Justin-ZS Justin-ZS requested a review from Ovilia September 29, 2025 01:40
@Justin-ZS
Copy link
Copy Markdown
Contributor Author

@Ovilia @100pah
PR has been updated accordingly.
Could you help to review again? Thanks!

100pah
100pah previously approved these changes Oct 30, 2025
@github-actions
Copy link
Copy Markdown
Contributor

The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-20703@f6f7bdf

Comment thread src/component/visualMap/preprocessor.ts Outdated
if (seriesTargets && zrUtil.isArray(seriesTargets)) {
each(seriesTargets, function (target) {
if (!zrUtil.isObject(target) || target.dimension == null) {
if (__DEV__) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed that this validation only outputs warnings during the development process. How about moving the __DEV__ check outside? - This helps reduce the distribution file size.

if (__DEV__) {
    const seriesTargets = opt.seriesTargets;
    if (seriesTargets && zrUtil.isArray(seriesTargets)) {
        each(seriesTargets, function (target) {
            if (!zrUtil.isObject(target) || target.dimension == null) {
                console.warn('Each seriesTarget should have a dimension property');
            }
            if (target.seriesIndex == null && target.seriesId == null) {
                console.warn('Each seriesTarget should have either seriesIndex or seriesId');
            }
        });
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (seriesTargets) {
// When seriesTargets is provided, collect all target series indices
const indices: number[] = [];
for (const target of seriesTargets) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There seems to be no const of usage for the array iteration in the codebase. As the current coding style, maybe the zrUtil.each utility should be used here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Ovilia
Ovilia previously approved these changes Oct 31, 2025
Copy link
Copy Markdown
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

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

LGTM

@plainheart plainheart merged commit 7a39313 into apache:master Oct 31, 2025
@echarts-bot
Copy link
Copy Markdown

echarts-bot Bot commented Oct 31, 2025

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

@plainheart plainheart added this to the 6.0.1 milestone Oct 31, 2025
@plainheart plainheart changed the title feat(visualMap): add seriesTargets to mapping different series -> dimension feat(visualMap): add seriesTargets option for multiple series-dimension mappings Dec 16, 2025
@echarts-bot echarts-bot Bot added PR: doc ready and removed PR: awaiting doc Document changes is required for this PR. labels Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to apply a single visual map configuration to multiple series in charts when using the dataset approach.

4 participants