From 5e54f9db1739446bb205aac403fdde76b275c7d5 Mon Sep 17 00:00:00 2001 From: 100pah Date: Fri, 8 Aug 2025 17:50:33 +0800 Subject: [PATCH] feat(matrix): Support matrix.x/y.length for conveniently create a headless matrix without composing an array. --- src/coord/matrix/MatrixDim.ts | 8 ++++++ src/coord/matrix/MatrixModel.ts | 3 +++ test/matrix.html | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/src/coord/matrix/MatrixDim.ts b/src/coord/matrix/MatrixDim.ts index 764d762c50..ed407bf0c0 100644 --- a/src/coord/matrix/MatrixDim.ts +++ b/src/coord/matrix/MatrixDim.ts @@ -149,6 +149,7 @@ export class MatrixDim { this._uniqueValueGen = createUniqueValueGenerator(dim); let dimModelData = dimModel.get('data', true); + const length = dimModel.get('length', true); if (dimModelData != null && !isArray(dimModelData)) { if (__DEV__) { error(`Illegal echarts option - matrix.${this.dim}.data must be an array if specified.`); @@ -158,6 +159,13 @@ export class MatrixDim { if (dimModelData) { this._initByDimModelData(dimModelData); } + else if (length != null) { + dimModelData = Array(length); + for (let i = 0; i < length; i++) { + dimModelData[i] = null; + } + this._initByDimModelData(dimModelData); + } else { this._initBySeriesData(); } diff --git a/src/coord/matrix/MatrixModel.ts b/src/coord/matrix/MatrixModel.ts index bcaae24bb0..93737a7c70 100644 --- a/src/coord/matrix/MatrixModel.ts +++ b/src/coord/matrix/MatrixModel.ts @@ -158,6 +158,9 @@ interface MatrixDimensionOption extends MatrixCellStyleOption, MatrixDimensionLe type?: 'category'; // For internal usage; force be 'category'. show?: boolean; data?: MatrixDimensionCellLooseOption[]; + // A simple way to provide column/row count if no need to compose a `data`. + // Note: `length` is ignored if `data` is specified. + length?: number; // `levels[0]`: the topmost (for x dimension) or leftmost (for y dimension) level. // If not specified, use null/undefined, such as `levels: [null, null, {levelSize: 10}]` levels?: (MatrixDimensionLevelOption | NullUndefined)[]; diff --git a/test/matrix.html b/test/matrix.html index 66bd853224..7fffee5e03 100644 --- a/test/matrix.html +++ b/test/matrix.html @@ -46,6 +46,7 @@
+
@@ -664,6 +665,49 @@ + + + + + +