(ecModel: GlobalModel)
| 45 | // (2) Only register once when import repeatedly. |
| 46 | // Should be executed after series is filtered and before stack calculation. |
| 47 | function dataStack(ecModel: GlobalModel) { |
| 48 | const stackInfoMap = createHashMap<StackInfo[]>(); |
| 49 | ecModel.eachSeries(function (seriesModel: SeriesModel<SeriesOption & SeriesStackOptionMixin>) { |
| 50 | const stack = seriesModel.get('stack'); |
| 51 | // Compatible: when `stack` is set as '', do not stack. |
| 52 | if (stack) { |
| 53 | const stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []); |
| 54 | const data = seriesModel.getData(); |
| 55 | |
| 56 | const stackInfo: StackInfo = { |
| 57 | // Used for calculate axis extent automatically. |
| 58 | // TODO: Type getCalculationInfo return more specific type? |
| 59 | stackResultDimension: data.getCalculationInfo('stackResultDimension'), |
| 60 | stackedOverDimension: data.getCalculationInfo('stackedOverDimension'), |
| 61 | stackedDimension: data.getCalculationInfo('stackedDimension'), |
| 62 | stackedByDimension: data.getCalculationInfo('stackedByDimension'), |
| 63 | isStackedByIndex: data.getCalculationInfo('isStackedByIndex'), |
| 64 | data: data, |
| 65 | seriesModel: seriesModel |
| 66 | }; |
| 67 | |
| 68 | // If stacked on axis that do not support data stack. |
| 69 | if (!stackInfo.stackedDimension |
| 70 | || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension) |
| 71 | ) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | stackInfoList.push(stackInfo); |
| 76 | } |
| 77 | }); |
| 78 | |
| 79 | // Process each stack group |
| 80 | stackInfoMap.each(function (stackInfoList) { |
| 81 | if (stackInfoList.length === 0) { |
| 82 | return; |
| 83 | } |
| 84 | // Check if stack order needs to be reversed |
| 85 | const firstSeries = stackInfoList[0].seriesModel; |
| 86 | const stackOrder = firstSeries.get('stackOrder') || 'seriesAsc'; |
| 87 | |
| 88 | if (stackOrder === 'seriesDesc') { |
| 89 | stackInfoList.reverse(); |
| 90 | } |
| 91 | |
| 92 | // Set stackedOnSeries for each series in the final order |
| 93 | each(stackInfoList, function (stackInfo, index) { |
| 94 | stackInfo.data.setCalculationInfo( |
| 95 | 'stackedOnSeries', |
| 96 | index > 0 ? stackInfoList[index - 1].seriesModel : null |
| 97 | ); |
| 98 | }); |
| 99 | |
| 100 | // Calculate stack values |
| 101 | calculateStack(stackInfoList); |
| 102 | }); |
| 103 | } |
| 104 |
nothing calls this directly
no test coverage detected
searching dependent graphs…