Ovilia commented on code in PR #21410:
URL: https://github.com/apache/echarts/pull/21410#discussion_r2605353793


##########
src/component/matrix/MatrixView.ts:
##########
@@ -289,12 +290,33 @@ function createMatrixCell(
     let cellText: Text | NullUndefined;
 
     if (textValue != null) {
-        const text = textValue + '';
+        let text = textValue + '';
         _tmpCellLabelModel.option = cellOption ? cellOption.label : null;
         _tmpCellLabelModel.parentModel = parentLabelModel;
         // This is to accept `option.textStyle` as the default.
         _tmpCellLabelModel.ecModel = ecModel;
 
+        const formatter = _tmpCellLabelModel.getShallow('formatter');
+        if (formatter) {
+            const params = {
+                componentType: 'matrix' as const,
+                componentIndex: matrixModel.componentIndex,
+                name: text,
+                value: textValue as unknown,
+                xyLocator: xyLocator.slice() as MatrixXYLocator[],
+                $vars: ['name', 'value', 'xyLocator'] as const

Review Comment:
   I would suggest using `'coord'` instead of `'xyLocatoer'` to align with 
[MatrixBodyCornerCellOption.coord](https://github.com/apache/echarts/blob/9cbbe57a00aabbe2a5fd30e0d74bf172a318e196/src/coord/matrix/MatrixModel.ts#L142).



##########
src/coord/matrix/MatrixModel.ts:
##########
@@ -195,6 +195,19 @@ export interface MatrixDimensionLevelOption {
 export interface MatrixDimensionModel extends Model<MatrixDimensionOption> {
 }
 
+export interface MatrixLabelOption extends LabelOption {
+    formatter?: string | ((params: MatrixLabelFormatterParams) => string);
+}
+
+export interface MatrixLabelFormatterParams {
+    componentType: 'matrix';
+    componentIndex: number;
+    name: string;
+    value: unknown;
+    xyLocator: MatrixXYLocator[];
+    $vars: readonly ['name', 'value', 'xyLocator'];

Review Comment:
   I see other places using `readonly`, although not `$vars`, and it's 
reasonable to use it here. 



##########
src/component/matrix/MatrixView.ts:
##########
@@ -289,12 +290,33 @@ function createMatrixCell(
     let cellText: Text | NullUndefined;
 
     if (textValue != null) {
-        const text = textValue + '';
+        let text = textValue + '';
         _tmpCellLabelModel.option = cellOption ? cellOption.label : null;
         _tmpCellLabelModel.parentModel = parentLabelModel;
         // This is to accept `option.textStyle` as the default.
         _tmpCellLabelModel.ecModel = ecModel;
 
+        const formatter = _tmpCellLabelModel.getShallow('formatter');
+        if (formatter) {
+            const params = {
+                componentType: 'matrix' as const,
+                componentIndex: matrixModel.componentIndex,
+                name: text,
+                value: textValue as unknown,
+                xyLocator: xyLocator.slice() as MatrixXYLocator[],
+                $vars: ['name', 'value', 'xyLocator'] as const
+            };
+            if (isFunction(formatter)) {
+                const formattedText = formatter(params);
+                if (formattedText != null) {
+                    text = formattedText + '';
+                }
+            }
+            else if (isString(formatter)) {
+                text = formatTplSimple(formatter, params);
+            }

Review Comment:
   A nice-to-have suggestion. Not a must.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to