forked from github/dataease
Merge pull request #8572 from dataease/pr@dev@feat_quick_calc_accumulate
feat(视图): 快速计算支持累加
This commit is contained in:
commit
3baef7ccc4
@ -73,6 +73,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -1447,6 +1448,78 @@ public class ChartViewService {
|
||||
.divide(sum, 8, RoundingMode.HALF_UP)
|
||||
.toString();
|
||||
}
|
||||
} else if (StringUtils.equalsAnyIgnoreCase(compareCalc.getType(), "accumulate")) {
|
||||
// 累加
|
||||
if (data.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
if (StringUtils.containsAny(view.getType(), "group", "stack")) {
|
||||
if (xAxisBase.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "stack") && extStack.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "group") && xAxisExt.isEmpty() ) {
|
||||
break;
|
||||
}
|
||||
final Map<String, Integer> mainIndexMap = new HashMap<>();
|
||||
final List<List<String[]>> mainMatrix = new ArrayList<>();
|
||||
List<ChartViewFieldDTO> finalXAxisBase = xAxisBase;
|
||||
data.forEach(item -> {
|
||||
String[] mainAxisArr = Arrays.copyOfRange(item, 0, finalXAxisBase.size());
|
||||
String mainAxis = StringUtils.join(mainAxisArr, '-');
|
||||
Integer index = mainIndexMap.get(mainAxis);
|
||||
if (index == null) {
|
||||
mainIndexMap.put(mainAxis, mainMatrix.size());
|
||||
List<String[]> tmp = new ArrayList<>();
|
||||
tmp.add(item);
|
||||
mainMatrix.add(tmp);
|
||||
} else {
|
||||
List<String[]> tmp = mainMatrix.get(index);
|
||||
tmp.add(item);
|
||||
}
|
||||
});
|
||||
int finalDataIndex = dataIndex;
|
||||
int subEndIndex = finalXAxisBase.size();
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "group")) {
|
||||
subEndIndex += xAxisExt.size();
|
||||
}
|
||||
if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
|
||||
subEndIndex += extStack.size();
|
||||
}
|
||||
int finalSubEndIndex = subEndIndex;
|
||||
//滑动累加
|
||||
for (int k = 1; k < mainMatrix.size(); k++) {
|
||||
List<String[]> preDataItems = mainMatrix.get(k - 1);
|
||||
List<String[]> curDataItems = mainMatrix.get(k);
|
||||
Map<String, BigDecimal> preDataMap = new HashMap<>();
|
||||
preDataItems.forEach(preDataItem -> {
|
||||
String[] groupStackAxisArr = Arrays.copyOfRange(preDataItem, finalXAxisBase.size(), finalSubEndIndex);
|
||||
String groupStackAxis = StringUtils.join(groupStackAxisArr, '-');
|
||||
preDataMap.put(groupStackAxis, new BigDecimal(preDataItem[finalDataIndex]));
|
||||
});
|
||||
curDataItems.forEach(curDataItem -> {
|
||||
String[] groupStackAxisArr = Arrays.copyOfRange(curDataItem, finalXAxisBase.size(), finalSubEndIndex);
|
||||
String groupStackAxis = StringUtils.join(groupStackAxisArr, '-');
|
||||
BigDecimal preValue = preDataMap.get(groupStackAxis);
|
||||
if (preValue != null) {
|
||||
curDataItem[finalDataIndex] = new BigDecimal(curDataItem[finalDataIndex])
|
||||
.add(preValue)
|
||||
.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
final int index = dataIndex;
|
||||
final AtomicReference<BigDecimal> accumValue = new AtomicReference<>(new BigDecimal(0));
|
||||
data.forEach(item -> {
|
||||
BigDecimal curVal = new BigDecimal(item[index]);
|
||||
BigDecimal curAccumValue = accumValue.get().add(curVal);
|
||||
item[index] = curAccumValue.toString();
|
||||
accumValue.set(curAccumValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1373,6 +1373,7 @@ export default {
|
||||
select_chart_type: 'Select Chart Type',
|
||||
recover: 'Reset',
|
||||
yoy_label: 'YOY/MOM',
|
||||
accumulate: 'Accumulate',
|
||||
yoy_setting: 'Setting',
|
||||
pls_select_field: 'Select Field',
|
||||
compare_date: 'Compare Date',
|
||||
|
@ -1371,6 +1371,7 @@ export default {
|
||||
select_chart_type: '選擇圖表類型',
|
||||
recover: '重置',
|
||||
yoy_label: '同比/環比',
|
||||
accumulate: '累加',
|
||||
yoy_setting: '同環比設置',
|
||||
pls_select_field: '請選擇字段',
|
||||
compare_date: '對比日期',
|
||||
|
@ -1372,6 +1372,7 @@ export default {
|
||||
recover: '重置',
|
||||
yoy_label: '同比/环比',
|
||||
yoy_setting: '同环比设置',
|
||||
accumulate: '累加',
|
||||
pls_select_field: '请选择字段',
|
||||
compare_date: '对比日期',
|
||||
compare_type: '对比类型',
|
||||
|
@ -3657,7 +3657,7 @@ export function getColors(chart, colors, reset) {
|
||||
if (chart.data) {
|
||||
const data = chart.data.data
|
||||
const s = []
|
||||
data.forEach((cur) => {
|
||||
data?.forEach((cur) => {
|
||||
if (s.indexOf(cur.category) < 0) {
|
||||
s.push(cur.category)
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
myChart: null,
|
||||
chartId: uuid.v1(),
|
||||
showTrackBar: true,
|
||||
trackBarStyle: {
|
||||
|
@ -175,7 +175,6 @@ export default {
|
||||
},
|
||||
tableData: [],
|
||||
showPage: false,
|
||||
scrollTimer: null,
|
||||
scrollTop: 0,
|
||||
remarkCfg: {
|
||||
show: false,
|
||||
@ -239,7 +238,6 @@ export default {
|
||||
this.preDraw()
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearInterval(this.scrollTimer)
|
||||
window.removeEventListener('resize', this.chartResize)
|
||||
this.myChart?.facet.timer?.stop()
|
||||
this.myChart?.destroy?.()
|
||||
@ -524,7 +522,6 @@ export default {
|
||||
},
|
||||
|
||||
initScroll() {
|
||||
clearTimeout(this.scrollTimer)
|
||||
const customAttr = JSON.parse(this.chart.customAttr)
|
||||
const senior = JSON.parse(this.chart.senior)
|
||||
if (senior?.scrollCfg?.open && (this.chart.type === 'table-normal' || (this.chart.type === 'table-info' && !this.showPage))) {
|
||||
|
@ -179,6 +179,10 @@
|
||||
:disabled="quotaViews.indexOf(chart.type) > -1"
|
||||
:command="beforeQuickCalc('percent')"
|
||||
>{{ $t('chart.percent') }}</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:disabled="quotaViews.indexOf(chart.type) > -1"
|
||||
:command="beforeQuickCalc('accumulate')"
|
||||
>{{ $t('chart.accumulate') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-dropdown-item>
|
||||
@ -418,6 +422,10 @@ export default {
|
||||
this.item.compareCalc.type = 'percent'
|
||||
this.$emit('onQuotaItemChange', this.item)
|
||||
break
|
||||
case 'accumulate':
|
||||
this.item.compareCalc.type = 'accumulate'
|
||||
this.$emit('onQuotaItemChange', this.item)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user