Copilot commented on code in PR #21604:
URL: https://github.com/apache/echarts/pull/21604#discussion_r3182114245


##########
src/processor/dataStack.ts:
##########
@@ -95,11 +101,25 @@ export default function dataStack(ecModel: GlobalModel) {
         });
 
         // Calculate stack values
-        calculateStack(stackInfoList);
+        calculateStack(stackInfoList, shouldNormalizeStack(stackInfoList));
     });
 }
 
-function calculateStack(stackInfoList: StackInfo[]) {
+function shouldNormalizeStack(stackInfoList: StackInfo[]) {
+    let hasStackNormalize = false;
+
+    for (let i = 0; i < stackInfoList.length; i++) {
+        const seriesModel = stackInfoList[i].seriesModel;
+        if (seriesModel.type !== 'series.line') {
+            return false;
+        }
+        hasStackNormalize = hasStackNormalize || 
!!seriesModel.get('stackNormalize');
+    }
+
+    return hasStackNormalize;

Review Comment:
   `stackNormalize` currently enables normalization for the entire stack group 
if *any* line series in the group has the flag set. That can unintentionally 
change results for other series sharing the same `stack` key that did not opt 
in. Consider requiring all series in the stack group to enable `stackNormalize` 
(or otherwise make the opt-in semantics explicit and consistent), to avoid 
surprising cross-series behavior.
   



##########
src/processor/dataStack.ts:
##########
@@ -111,7 +131,9 @@ function calculateStack(stackInfoList: StackInfo[]) {
         // Should not write on raw data, because stack series model list 
changes
         // depending on legend selection.
         targetData.modify(dims, function (v0, v1, dataIndex) {
-            let sum = targetData.get(targetStackInfo.stackedDimension, 
dataIndex) as number;
+            let sum = normalizeStack
+                ? normalizeStackValue(stackInfoList, targetStackInfo, 
dataIndex, stackStrategy)
+                : targetData.get(targetStackInfo.stackedDimension, dataIndex) 
as number;

Review Comment:
   When `stackNormalize` is enabled, `normalizeStackValue()`/`getStackTotal()` 
recompute the stack total by iterating over `stackInfoList` for every series 
and every data index, which makes stack calculation potentially O(series^2 × 
points) (and can also repeatedly call `rawIndexOf` for stacked-by-dimension). 
Consider precomputing/caching the per-category totals once per stack group 
(e.g., totals per rawIndex for stackByIndex and totals keyed by 
`stackedByDimension` value for stackByDimension, potentially split by sign for 
`samesign`) and reusing them during `targetData.modify` to keep performance 
closer to the original stack implementation.



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