This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch fix/matrix-label-api in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 3a509ea77ad96805625b8a8ea6947c48a763a0f4 Author: 100pah <[email protected]> AuthorDate: Tue Jul 15 21:13:01 2025 +0800 feat(matrix): support `option.textStyle` as the default. --- src/component/matrix/MatrixView.ts | 25 +++++++++++++++++++------ src/util/model.ts | 6 ++++++ test/matrix.html | 6 +++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/component/matrix/MatrixView.ts b/src/component/matrix/MatrixView.ts index 8f3405234..4c236cc0f 100644 --- a/src/component/matrix/MatrixView.ts +++ b/src/component/matrix/MatrixView.ts @@ -30,11 +30,12 @@ import { LineStyleProps } from '../../model/mixin/lineStyle'; 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 { ListIterator } from '../../util/model'; +import { clearTmpModel, ListIterator } from '../../util/model'; import { clone, retrieve2 } from 'zrender/src/core/util'; import { invert } from 'zrender/src/core/matrix'; import { MatrixBodyCorner, MatrixBodyOrCornerKind } from '../../coord/matrix/MatrixBodyCorner'; import { setLabelStyle } from '../../label/labelStyle'; +import GlobalModel from '../../model/Global'; const round = Math.round; @@ -51,7 +52,7 @@ class MatrixView extends ComponentView { static type = 'matrix'; type = MatrixView.type; - render(matrixModel: MatrixModel) { + render(matrixModel: MatrixModel, ecModel: GlobalModel) { this.group.removeAll(); @@ -68,14 +69,16 @@ class MatrixView extends ComponentView { renderDimensionCells( group, - matrixModel + matrixModel, + ecModel ); createBodyAndCorner( group, matrixModel, xDim, - yDim + yDim, + ecModel ); const borderZ2Option = matrixModel.getShallow('borderZ2', true); @@ -134,7 +137,7 @@ class MatrixView extends ComponentView { } } -function renderDimensionCells(group: Group, matrixModel: MatrixModel) { +function renderDimensionCells(group: Group, matrixModel: MatrixModel, ecModel: GlobalModel): void { renderOnDimension(0); renderOnDimension(1); @@ -163,6 +166,7 @@ function renderDimensionCells(group: Group, matrixModel: MatrixModel) { xyLocator, matrixModel, group, + ecModel, dimCell.option, thisDimBgStyleModel, thisDimLabelModel, @@ -180,7 +184,8 @@ function createBodyAndCorner( group: Group, matrixModel: MatrixModel, xDim: MatrixDim, - yDim: MatrixDim + yDim: MatrixDim, + ecModel: GlobalModel ): void { createBodyOrCornerCells('body', matrixModel.getBody(), xDim, yDim); @@ -232,6 +237,7 @@ function createBodyAndCorner( xyLocator, matrixModel, group, + ecModel, bodyCornerCellOption, parentItemStyleModel, parentLabelModel, @@ -250,6 +256,7 @@ function createMatrixCell( xyLocator: MatrixXYLocator[], matrixModel: MatrixModel, group: Group, + ecModel: GlobalModel, cellOption: MatrixBaseCellOption | NullUndefined, parentItemStyleModel: Model<MatrixCellStyleOption['itemStyle']>, parentLabelModel: Model<MatrixCellStyleOption['label']>, @@ -285,6 +292,8 @@ function createMatrixCell( const text = textValue + ''; _tmpCellLabelModel.option = cellOption ? cellOption.label : null; _tmpCellLabelModel.parentModel = parentLabelModel; + // This is to accept `option.textStyle` as the default. + _tmpCellLabelModel.ecModel = ecModel; setLabelStyle( cellRect, @@ -349,6 +358,10 @@ function createMatrixCell( ); } cellRect.silent = rectSilent; + + clearTmpModel(_tmpCellModel); + clearTmpModel(_tmpCellItemStyleModel); + clearTmpModel(_tmpCellLabelModel); } const _tmpCellModel = new Model<MatrixCellStyleOption>(); const _tmpCellItemStyleModel = new Model<MatrixCellStyleOption['itemStyle']>(); diff --git a/src/util/model.ts b/src/util/model.ts index 298363cc9..ee7637bda 100644 --- a/src/util/model.ts +++ b/src/util/model.ts @@ -54,6 +54,7 @@ import CartesianAxisModel from '../coord/cartesian/AxisModel'; import GridModel from '../coord/cartesian/GridModel'; import { isNumeric, getRandomIdBase, getPrecision, round } from './number'; import { error, warn } from './log'; +import type Model from '../model/Model'; function interpolateNumber(p0: number, p1: number, percent: number): number { return (p1 - p0) * percent + p0; @@ -1167,3 +1168,8 @@ export class ListIterator<TItem> { return false; } } + +export function clearTmpModel(model: Model): void { + // Clear to avoid memory leak. + model.option = model.parentModel = model.ecModel = null; +} diff --git a/test/matrix.html b/test/matrix.html index 6915087ad..c588c4d0c 100644 --- a/test/matrix.html +++ b/test/matrix.html @@ -66,7 +66,7 @@ under the License. value: 'A3', children: ['A31', 'A32'] }] - }] + }], }, y: { data: ['U', 'V'] @@ -77,6 +77,10 @@ under the License. }, } }, + textStyle: { + fontSize: 25, + color: 'red' + }, visualMap: { type: 'continuous', min: 0, --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
