Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/component/matrix/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { LineShape } from 'zrender/src/graphic/shape/Line';
import { subPixelOptimize } from 'zrender/src/graphic/helper/subPixelOptimize';
import { Group, Text, Rect, Line, XY, setTooltipConfig, expandOrShrinkRect } from '../../util/graphic';
import { clearTmpModel, ListIterator } from '../../util/model';
import { getECData } from '../../util/innerStore';
import { clone, retrieve2, isFunction, isString } from 'zrender/src/core/util';
import { formatTplSimple } from '../../util/format';
import { invert } from 'zrender/src/core/matrix';
Expand Down Expand Up @@ -175,7 +176,8 @@ function renderDimensionCells(group: Group, matrixModel: MatrixModel, ecModel: G
shape,
dimCell.option.value,
Z2_DIMENSION_CELL_DEFAULT,
tooltipOption
tooltipOption,
dimIdx === 0 ? 'x' : 'y'
);
}
}
Expand Down Expand Up @@ -246,13 +248,16 @@ function createBodyAndCorner(
shape,
bodyCornerCellOption ? bodyCornerCellOption.value : null,
Z2_BODY_CORNER_CELL_DEFAULT,
tooltipOption
tooltipOption,
bodyCornerOptionRoot
);
}
}
} // End of createBodyOrCornerCells
}

type MatrixTargetType = 'x' | 'y' | 'body' | 'corner';

function createMatrixCell(
xyLocator: MatrixXYLocator[],
matrixModel: MatrixModel,
Expand All @@ -266,6 +271,7 @@ function createMatrixCell(
textValue: unknown,
zrCellDefault: Z2CellDefault,
tooltipOption: MatrixOption['tooltip'],
targetType: MatrixTargetType
): void {
// Do not use getModel for handy performance optimization.
_tmpCellItemStyleModel.option = cellOption ? cellOption.itemStyle : null;
Expand Down Expand Up @@ -361,12 +367,12 @@ function createMatrixCell(
}

// Set silent
const triggerEvent = matrixModel.get('triggerEvent');
if (cellText) {
let labelSilent = _tmpCellLabelModel.get('silent');
// auto, tooltip of text cells need silient: false, but non-text cells
// do not need a special cursor in most cases.
// By default, silent: false is needed for triggerEvent or tooltip interaction.
if (labelSilent == null) {
labelSilent = !tooltipOptionShow;
labelSilent = !(triggerEvent || tooltipOptionShow);
}
cellText.silent = labelSilent;
cellText.ignoreHostSilent = true;
Expand All @@ -381,6 +387,18 @@ function createMatrixCell(
}
cellRect.silent = rectSilent;

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;
}
Comment on lines +390 to +400
Copy link

Copilot AI Dec 10, 2025

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
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
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.


clearTmpModel(_tmpCellModel);
clearTmpModel(_tmpCellItemStyleModel);
clearTmpModel(_tmpCellLabelModel);
Expand Down
2 changes: 2 additions & 0 deletions src/coord/matrix/MatrixModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface MatrixOption extends ComponentOption, BoxLayoutOptionMixin {
// Used on the outer border and the divider line.
borderZ2?: number;
tooltip?: CommonTooltipOption<MatrixTooltipFormatterParams>;
triggerEvent?: boolean;

// PENDING: do we need to support other states, i.e., `emphasis`, `blur`, `select`?
}
Expand Down Expand Up @@ -292,6 +293,7 @@ const defaultMatrixOption: MatrixOption = {
borderColor: tokens.color.axisLine,
borderWidth: 1,
},
triggerEvent: false,
};


Expand Down
66 changes: 66 additions & 0 deletions test/matrix.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 136 additions & 0 deletions test/ut/spec/component/matrix/event.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.