Skip to content

feat(matrix): add new option triggerEvent to support triggering event on matrix cells - #21390

Merged
100pah merged 8 commits into
apache:releasefrom
natsuokawai:fix/matrix-click-event
Jan 8, 2026
Merged

feat(matrix): add new option triggerEvent to support triggering event on matrix cells#21390
100pah merged 8 commits into
apache:releasefrom
natsuokawai:fix/matrix-click-event

Conversation

@natsuokawai

@natsuokawai natsuokawai commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Fixes an issue where click events were not triggered on matrix component cells.

Fixed issues

Details

Before: What was the problem?

Even when matrix.body.silent was set to false (and the cell was made hit-testable, e.g., by setting itemStyle.color to 'transparent'), click events on matrix cells were not being emitted by the ECharts instance. This was because the underlying graphic elements (rects and texts) created in MatrixView lacked the necessary eventData (ECData) to identify them as part of the matrix component.

After: How does it behave after the fixing?

Click events are now correctly triggered when clicking on matrix cells. The event parameters include componentType: 'matrix', componentIndex, and the cell's name.

This is achieved by:

  1. Importing getECData in src/component/matrix/MatrixView.ts.
  2. Attaching eventData to the cell's text elements during creation in createMatrixCell.
events-on-matrix-cell-text.mov

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

Added a new test case in test/ut/spec/component/matrix/event.test.ts to verify the fix.

Merging options

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

Other information

@echarts-bot

echarts-bot Bot commented Nov 26, 2025

Copy link
Copy Markdown

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.

@Ovilia Ovilia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Matrix is a layout so its text in the header or body should not trigger 'click' event by default. If you need this information, you need to add a new option matrix.triggerEvent (default false) like https://echarts.apache.org/en/option.html#yAxis.triggerEvent.

@natsuokawai

Copy link
Copy Markdown
Contributor Author

@Ovilia
Thank you for your review and the helpful feedback!

I've updated the implementation to add the triggerEvent option (default: false) following the same pattern as yAxis.triggerEvent.

I would appreciate it if you could take another look.

@natsuokawai
natsuokawai requested a review from Ovilia November 30, 2025 05:14

@Ovilia Ovilia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also add test cases in test/matrix.html.

name: textValue != null ? textValue + '' : null,
coord: xyLocator.slice()
};
getECData(cellRect).eventData = eventData;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems that events only trigger when there is text, correct me if I'm wrong. So what's the meaning of setting eventData of cellRect here?

@natsuokawai natsuokawai Dec 7, 2025

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.

@Ovilia
Sorry, you're right. I've removed the eventData from cellRect. Fixed in 1a12a50

Copilot AI left a comment

Copy link
Copy Markdown

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 click events were not being triggered on matrix component cells. It adds a triggerEvent option to the matrix component (defaulting to false) and implements the necessary eventData attachment to enable click event propagation when enabled.

Key Changes:

  • Adds triggerEvent boolean option to MatrixOption interface with a default value of false
  • Updates createMatrixCell function to attach eventData to cell text elements when triggerEvent is enabled
  • Adjusts silent property logic to account for both triggerEvent and tooltip interactions

Reviewed changes

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

File Description
src/coord/matrix/MatrixModel.ts Adds triggerEvent option to MatrixOption interface and sets default to false
src/component/matrix/MatrixView.ts Imports getECData, adds targetType parameter to createMatrixCell, attaches eventData to cellText when triggerEvent is enabled, and updates silent property logic
test/ut/spec/component/matrix/event.test.ts Adds comprehensive unit tests for verifying click events work when triggerEvent is true and eventData is not attached when false
test/matrix.html Adds interactive demo showing click events on matrix cells with visual feedback

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

Comment thread src/component/matrix/MatrixView.ts Outdated
Comment on lines +368 to +378
if (triggerEvent && cellText) {
const eventData = {
componentType: 'matrix' as const,
componentIndex: matrixModel.componentIndex,
matrixIndex: matrixModel.componentIndex,
targetType: targetType,
name: textValue != null ? textValue + '' : null,
coord: xyLocator.slice()
};
getECData(cellText).eventData = eventData;
}

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

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

The eventData is only attached to cellText, which means cells without text values (where textValue is null/undefined) won't trigger click events even when triggerEvent is true. Consider whether eventData should also be attached to cellRect for cells without text to ensure consistent event handling across all matrix cells.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also have this doubt. @natsuokawai Do you think it be useful to cells without text to trigger events?

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.

@Ovilia
I figured that cells without text (so, no actual data) probably don't need to trigger events.
The way I see it, ECharts events are mainly for when you want to do something with the data shown at a particular point.

Comment on lines +35 to +91
it('should trigger click event on matrix cell when triggerEvent is true', function () {
const option = {
matrix: {
triggerEvent: true,
x: {
data: ['A', 'B']
},
y: {
data: ['Y']
},
body: {
data: [
{ coord: [0, 0], value: 'Cell A' }
]
}
}
};

chart.setOption(option);

let clickedParams: any = null;

chart.on('click', function (params) {
clickedParams = params;
});

// Find the matrix cell element
const zr = chart.getZr();
const displayList = zr.storage.getDisplayList();

let targetEl;
for (let i = 0; i < displayList.length; i++) {
const el = displayList[i];
const ecData = getECData(el);
if (ecData && ecData.eventData && ecData.eventData.name === 'Cell A') {
// Find the cell with the specific name
targetEl = el;
break;
}
}

expect(targetEl).toBeDefined();

// Trigger click
zr.trigger('click', {
target: targetEl,
offsetX: 10, // Dummy
offsetY: 10 // Dummy
});

expect(clickedParams).not.toBeNull();
expect(clickedParams.componentType).toEqual('matrix');
expect(clickedParams.matrixIndex).toEqual(0);
expect(clickedParams.targetType).toEqual('body');
expect(clickedParams.name).toEqual('Cell A');
expect(clickedParams.coord).toEqual([0, 0]);
});

Copilot AI Dec 10, 2025

Copy link

Choose a reason for hiding this comment

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

Consider adding test coverage for cells without text values to verify whether click events should (or should not) be triggered on cells that only have background styling but no text content. This would help clarify the intended API behavior.

Copilot uses AI. Check for mistakes.

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.

Fixed in 5530423

@natsuokawai
natsuokawai force-pushed the fix/matrix-click-event branch from 5530423 to 6609e32 Compare December 15, 2025 08:05
@natsuokawai

Copy link
Copy Markdown
Contributor Author

@Ovilia
Just checking in on this. Let me know if you need any more time or if there's anything else I can do.

@Ovilia

Ovilia commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Sorry for the late reply. I will have @100pah for a closer look. Thanks!

@github-actions

github-actions Bot commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

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

…` may trigger events, depending on both `matrix.triggerEvent`, `matrix.xxx.silent` and `matrix.xxx.label.silent` settings. By default (`matrix.triggerEvent:true`, `matrix.xxx.silent` and `matrix.xxx.label.silent` is undefined) cell text and non-transparent cell bg trigger event. (2) Modify event param: `name` is the final rendered text, `value` is the original input cell value in option. (3) Add visual test cases for `matrix.html`.
@100pah
100pah changed the base branch from master to release January 7, 2026 17:20
@100pah

100pah commented Jan 7, 2026

Copy link
Copy Markdown
Member

@natsuokawai @Ovilia

I made a commit and modified:

  • Both cellRect (typically non-transparent) and cellText may trigger events, depending on both matrix.triggerEvent, matrix.xxx.silent and matrix.xxx.label.silent settings.
    • If set matrix.triggerEvent:true, matrix.xxx.silent and matrix.xxx.label.silent is not specified or null/undefined, cell text and non-transparent cell background trigger events.
    • If intending to disable cell background triggering, set matrix.xxx.silent: true in the above case.
    • [NOTE]: matrix.xxx.silent and matrix.xxx.label.silent (missing in doc) have been used to control the interactive of cellRect and cellText separately since v6.0.0. Therefore I think the new triggerEvent can follow this pattern, as long as it is not inappropriate.
  • Modify event param:
    • name is the final rendered text
    • value is the original input cell value in option.
  • Add visual test cases for matrix.html.

And I've changed the merge target to "release" for the upcoming v6.1.0.

v6.1.0 is in testing, so I modify the code directly; sorry for that.
If any of the change is inappropriate, we can discuss them further.

@100pah
100pah merged commit e770604 into apache:release Jan 8, 2026
@echarts-bot

echarts-bot Bot commented Jan 8, 2026

Copy link
Copy Markdown

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

@plainheart plainheart changed the title fix(matrix): trigger click event on matrix cells Jan 10, 2026
@plainheart plainheart changed the title fix(matrix): fix matrix cells do not trigger event Jan 10, 2026
@plainheart plainheart added this to the 6.1.0 milestone Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment