Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Adityakashyap1011
Copy link

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Fixes visualMap to respect the series encode.value configuration when determining which dimension to use for visual mapping.

Fixed issues

  • Resolves issue where heatmap with multiple value columns ignores encode.value and uses the last column instead

Details

Before: What was the problem?

When a series (e.g., heatmap with matrix coordinate system) has multiple value columns in the dataset and uses encode to specify which dimension should be mapped as 'value', the visualMap component was ignoring this configuration. Instead, it used a backward search algorithm that always picked the last non-coordinate dimension.

Example:

dataset: {
source: [
['x', 'y', 'value1', 'value2', 'value3'],
['A', 'X', 0.1, 0.5, 0.9],
['A', 'Y', 0.2, 0.6, 0.8],
['B', 'X', 0.3, 0.7, 0.7],
['B', 'Y', 0.4, 0.8, 0.6]
]
},
series: [{
type: 'heatmap',
coordinateSystem: 'matrix',
encode: {
x: 'x',
y: 'y',
value: 'value1'
}
}]

The visualMap would incorrectly use 'value3' (last column) instead of 'value1' for color mapping, producing an inverted gradient.

After: How does it behave after the fixing?

Modified getDataDimensionIndex() in src/component/visualMap/VisualMapModel.ts to:

  1. First check for explicit dimension option (existing behavior)
  2. Respect the series encode configuration by using data.mapDimension('value')
  3. Fall back to backward search only if no encoded 'value' dimension exists

Now when encode: { value: 'value1' } is specified, the visualMap correctly uses 'value1' for color mapping, producing the expected visual gradient.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

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

Related test cases or examples to use the new APIs

Test file: test/heatmap-encode-value-fix.html demonstrates the fix with a heatmap using matrix coordinate system and multiple value columns.

Merging options

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

Other information

Files modified:

  • src/component/visualMap/VisualMapModel.ts - Modified getDataDimensionIndex() to respect encode configuration
  • test/heatmap-encode-value-fix.html - Added test/verification file

@echarts-bot
Copy link

echarts-bot bot commented Dec 3, 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.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

@Justin-ZS
Copy link
Contributor

Thanks for the PR!
This use case can be solved with the existing visualMap.dimension config.

A few concerns:

  1. Increases coupling between visualMap and series

    • visualMap is designed as an independent component that specifies the target dimension via dimension option
    • This change makes visualMap implicitly depend on series encode config
  2. encode.value is not a general encode

    • value is used only by specific charts (pie, funnel, heatmap, map)
    • Line/bar charts use encode.x/y, they don't have encode.value

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where visualMap ignored the series encode.value configuration when working with datasets containing multiple value columns. Previously, visualMap used a backward search algorithm that always selected the last non-coordinate dimension, regardless of the encode.value setting. The fix modifies the dimension resolution logic to respect the encoded value dimension before falling back to the original behavior.

Key Changes:

  • Modified getDataDimensionIndex() to check for encoded 'value' dimension using data.mapDimension('value') before performing backward search
  • Added test case demonstrating the fix with a heatmap using multiple value columns

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/component/visualMap/VisualMapModel.ts Added logic to respect series encode configuration by checking data.mapDimension('value') before falling back to backward dimension search
test/heatmap-encode-value-fix.html Added test case demonstrating the fix with a heatmap that has multiple value columns and uses encode.value to specify which column to use for visual mapping

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants