Skip to content

Commit 79f123b

Browse files
authored
Merge pull request #20998 from Justin-ZS/feat/support_reverse_stack_order
feat(stack): able to reverse the stack order
2 parents f4c244c + e223dd8 commit 79f123b

File tree

3 files changed

+306
-5
lines changed

3 files changed

+306
-5
lines changed

src/processor/dataStack.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,34 @@ export default function dataStack(ecModel: GlobalModel) {
6969
return;
7070
}
7171

72-
stackInfoList.length && data.setCalculationInfo(
73-
'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel
74-
);
75-
7672
stackInfoList.push(stackInfo);
7773
}
7874
});
7975

80-
stackInfoMap.each(calculateStack);
76+
// Process each stack group
77+
stackInfoMap.each(function (stackInfoList) {
78+
if (stackInfoList.length === 0) {
79+
return;
80+
}
81+
// Check if stack order needs to be reversed
82+
const firstSeries = stackInfoList[0].seriesModel;
83+
const stackOrder = firstSeries.get('stackOrder') || 'seriesAsc';
84+
85+
if (stackOrder === 'seriesDesc') {
86+
stackInfoList.reverse();
87+
}
88+
89+
// Set stackedOnSeries for each series in the final order
90+
each(stackInfoList, function (stackInfo, index) {
91+
stackInfo.data.setCalculationInfo(
92+
'stackedOnSeries',
93+
index > 0 ? stackInfoList[index - 1].seriesModel : null
94+
);
95+
});
96+
97+
// Calculate stack values
98+
calculateStack(stackInfoList);
99+
});
81100
}
82101

83102
function calculateStack(stackInfoList: StackInfo[]) {

src/util/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@ export interface SeriesLargeOptionMixin {
16881688
export interface SeriesStackOptionMixin {
16891689
stack?: string
16901690
stackStrategy?: 'samesign' | 'all' | 'positive' | 'negative';
1691+
stackOrder?: 'seriesAsc' | 'seriesDesc'; // default: seriesAsc
16911692
}
16921693

16931694
type SamplingFunc = (frame: ArrayLike<number>) => number;

test/bar-stack-reverse.html

Lines changed: 281 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)