MCPcopy Index your code
hub / github.com/apache/echarts / calculateStack

Function calculateStack

src/processor/dataStack.ts:105–175  ·  view source on GitHub ↗
(stackInfoList: StackInfo[])

Source from the content-addressed store, hash-verified

103}
104
105function calculateStack(stackInfoList: StackInfo[]) {
106 each(stackInfoList, function (targetStackInfo, idxInStack) {
107 const resultVal: number[] = [];
108 const resultNaN = [NaN, NaN];
109 const dims: [string, string] = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
110 const targetData = targetStackInfo.data;
111 const isStackedByIndex = targetStackInfo.isStackedByIndex;
112 const stackStrategy = targetStackInfo.seriesModel.get('stackStrategy') || 'samesign';
113
114 // Should not write on raw data, because stack series model list changes
115 // depending on legend selection.
116 targetData.modify(dims, function (v0, v1, dataIndex) {
117 let sum = targetData.get(targetStackInfo.stackedDimension, dataIndex) as number;
118
119 // Consider `connectNulls` of line area, if value is NaN, stackedOver
120 // should also be NaN, to draw a appropriate belt area.
121 if (isNaN(sum)) {
122 return resultNaN;
123 }
124
125 let byValue: number;
126 let stackedDataRawIndex;
127
128 if (isStackedByIndex) {
129 stackedDataRawIndex = targetData.getRawIndex(dataIndex);
130 }
131 else {
132 byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex) as number;
133 }
134
135 // If stackOver is NaN, chart view will render point on value start.
136 let stackedOver = NaN;
137
138 for (let j = idxInStack - 1; j >= 0; j--) {
139 const stackInfo = stackInfoList[j];
140
141 // Has been optimized by inverted indices on `stackedByDimension`.
142 if (!isStackedByIndex) {
143 stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
144 }
145
146 if (stackedDataRawIndex >= 0) {
147 const val = stackInfo.data.getByRawIndex(
148 stackInfo.stackResultDimension, stackedDataRawIndex
149 ) as number;
150
151 // Considering positive stack, negative stack and empty data
152 if (
153 stackStrategy === 'all' // single stack group
154 || (stackStrategy === 'positive' && val > 0)
155 || (stackStrategy === 'negative' && val < 0)
156 || (stackStrategy === 'samesign' && sum >= 0 && val > 0) // All positive stack
157 || (stackStrategy === 'samesign' && sum <= 0 && val < 0) // All negative stack
158 ) {
159 // The sum has to be very small to be affected by the
160 // floating arithmetic problem. An incorrect result will probably
161 // cause axis min/max to be filtered incorrectly.
162 sum = addSafe(sum, val);

Callers 1

dataStackFunction · 0.85

Calls 7

addSafeFunction · 0.90
rawIndexOfMethod · 0.80
getRawIndexMethod · 0.65
eachFunction · 0.50
getMethod · 0.45
modifyMethod · 0.45
getByRawIndexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…