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 e0bfd3f16730ab472bc21650dfb23aaad717f30d
Author: 100pah <[email protected]>
AuthorDate: Wed Jul 16 16:27:50 2025 +0800

    feat(matrix): (1) Tolerate coord input like [['x1', 'x2', 'x3'], ...], 
where 'x1' and 'x3' is considered the range boundary. (2) Disable the default 
clamp in `matrix.body/corner.data[i].coord`, because it consider the illegal 
input as "refer to the entire row/column", which is more likely to mislead 
users and no error message. Introduce option 
`matrix.body/corner.data[i].coordClamp` to enable it.
---
 src/coord/matrix/MatrixBodyCorner.ts  |  2 +-
 src/coord/matrix/MatrixModel.ts       | 16 +++++++++++++---
 src/coord/matrix/matrixCoordHelper.ts | 26 ++++++++++++++++++--------
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/coord/matrix/MatrixBodyCorner.ts 
b/src/coord/matrix/MatrixBodyCorner.ts
index 3d372c26b..ddaad0d47 100644
--- a/src/coord/matrix/MatrixBodyCorner.ts
+++ b/src/coord/matrix/MatrixBodyCorner.ts
@@ -142,7 +142,7 @@ export class MatrixBodyCorner<TKind extends 
MatrixBodyOrCornerKind> {
                 }
                 parseCoordRangeOption(
                     locatorRange, reasonArr, option.coord, self._dims,
-                    option.clamp ? MatrixClampOption[self._kind] : 
MatrixClampOption.none
+                    option.coordClamp ? MatrixClampOption[self._kind] : 
MatrixClampOption.none
                 );
                 if (isXYLocatorRangeInvalidOnDim(locatorRange, 0) || 
isXYLocatorRangeInvalidOnDim(locatorRange, 1)) {
                     if (__DEV__) {
diff --git a/src/coord/matrix/MatrixModel.ts b/src/coord/matrix/MatrixModel.ts
index 411f1d2f9..bcaae24bb 100644
--- a/src/coord/matrix/MatrixModel.ts
+++ b/src/coord/matrix/MatrixModel.ts
@@ -116,10 +116,10 @@ export interface MatrixCornerOption extends 
MatrixBodyCornerBaseOption {
  * Commonly used as `MatrixCoordRangeOption[]`
  * Can locate a cell or a rect range of cells.
  * `[2, 8]` indicates a cell.
- * `[2, null/undefined/NaN]` means y is the entire column.
- * `[null/undefined/NaN, 8]` is the opposite.
+ * `[2, null/undefined/NaN]` means y is not relevant.
+ * `[null/undefined/NaN, 8]` means x is not relevant.
  * `[[2, 5], 8]` indicates a rect of cells in x range of `2~5` and y `8`.
- * `[[2, 5], null/undefined/NaN]` indicates a x range of `2~5` and y is the 
entire column.
+ * `[[2, 5], null/undefined/NaN]` indicates a x range of `2~5` and y is not 
relevant.
  * `[[2, 5], [7, 8]]` indicates a rect of cells in x range of `2~5` and y 
range of `7~8`.
  * `['aNonLeaf', 8]` indicates a rect of cells in x range of `aNonLeaf` and y 
`8`.
  * @see {parseCoordRangeOption}
@@ -140,6 +140,16 @@ export interface MatrixBodyCornerCellOption extends 
MatrixBaseCellOption {
     value?: string;
     // Use it to reference a coord in matrix.
     coord?: MatrixCoordRangeOption[];
+    // If true, null/undefined/NaN/invalid_coord_part in `coord` means the 
entire column/row.
+    // `false` by default, because:
+    //  - Pros:
+    //    - If the `coord` is incorrect and unintentional, the entire 
column/row will be referred,
+    //      and no error message.
+    //    - Inconsistent with `dataToLayout`, which is no clamp by default.
+    //  - Cons:
+    //    - `coord: ['x1', null]` or `coord: ['x1', ['y1', 
'y999_may_out_of_range']]` is supported
+    //      to refer to a entire column, which brings convenience to users and 
may intuitive.
+    coordClamp?: boolean;
     // Merge cells determined by `coord`.
     mergeCells?: boolean;
 }
diff --git a/src/coord/matrix/matrixCoordHelper.ts 
b/src/coord/matrix/matrixCoordHelper.ts
index 0344bd3a7..db308afb3 100644
--- a/src/coord/matrix/matrixCoordHelper.ts
+++ b/src/coord/matrix/matrixCoordHelper.ts
@@ -86,7 +86,7 @@ export function resetXYLocatorRange(out: unknown[] | 
NullUndefined): MatrixXYLoc
 }
 
 /**
- * If illegal or out of boundary, set NaN to `locOut`. (See 
`isLocatorRangeInvalidOnDim`)
+ * If illegal or out of boundary, set NaN to `locOut`. See 
`isXYLocatorRangeInvalidOnDim`.
  * x dimension and y dimension are calculated separately.
  */
 export function parseCoordRangeOption(
@@ -120,15 +120,23 @@ function parseCoordRangeOptionOnOneDim(
     const len = coordValArr.length;
     const hasClamp = !!clamp;
 
-    if (len === 1 || len === 2) {
-        parseCoordRangeOptionOnOneDimOnePart(locDimOut, reasonOut, 
coordValArr, hasClamp, dims, dimIdx, 0);
+    if (len >= 1) {
+        parseCoordRangeOptionOnOneDimOnePart(
+            locDimOut, reasonOut, coordValArr, hasClamp, dims, dimIdx, 0
+        );
         if (len > 1) {
-            parseCoordRangeOptionOnOneDimOnePart(locDimOut, reasonOut, 
coordValArr, hasClamp, dims, dimIdx, 1);
+            // Users may intuitively input the coords like `[[x1, x2, x3], 
...]`;
+            // consider the range as `[x1, x3]` in this case.
+            parseCoordRangeOptionOnOneDimOnePart(
+                locDimOut, reasonOut, coordValArr, hasClamp, dims, dimIdx, len 
- 1
+            );
         }
     }
     else {
-        if (reasonOut) {
-            reasonOut.push(`Can only contain 1 or 2 coords, rather than 
${len}.`);
+        if (__DEV__) {
+            if (reasonOut) {
+                reasonOut.push('Should be like [["x1", "x2"], ["y1", "y2"]], 
or ["x1", "y1"], rather than empty.');
+            }
         }
         locDimOut[0] = locDimOut[1] = NaN;
     }
@@ -173,8 +181,10 @@ function parseCoordRangeOptionOnOneDimOnePart(
 ): void {
     const layout = coordDataToAllCellLevelLayout(coordValArr[partIdx], dims, 
dimIdx);
     if (!layout) {
-        if (!hasClamp && reasonOut) {
-            reasonOut.push(`Can not find layout by 
coord[${dimIdx}][${partIdx}].`);
+        if (__DEV__) {
+            if (!hasClamp && reasonOut) {
+                reasonOut.push(`Can not find cell by 
coord[${dimIdx}][${partIdx}].`);
+            }
         }
         locDimOut[0] = locDimOut[1] = NaN;
         return;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to