Merge pull request #1426 from dataease/pr@dev@feat_compare

feat(视图): 同比环比
This commit is contained in:
XiaJunjie2020 2021-12-10 10:44:41 +08:00 committed by GitHub
commit 94ad20200e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 34 deletions

View File

@ -478,28 +478,31 @@ public class ChartViewService {
// 1处理当期数据2根据type计算上一期数据3根据resultData计算结果
Map<String, String> currentMap = new LinkedHashMap<>();
for (String[] item : data) {
currentMap.put(item[timeIndex], item[dataIndex]);
String[] dimension = Arrays.copyOfRange(item, 0, checkedField.size());
currentMap.put(StringUtils.join(dimension, "-"), item[dataIndex]);
}
Iterator<Map.Entry<String, String>> iterator = currentMap.entrySet().iterator();
int index = 0;
while (iterator.hasNext()) {
Map.Entry<String, String> next = iterator.next();
String cTime = next.getKey();
String cValue = next.getValue();
for (int index = 0; index < data.size(); index++) {
String[] item = data.get(index);
String cTime = item[timeIndex];
String cValue = item[dataIndex];
// 获取计算后的时间并且与所有维度拼接
String lastTime = calcLastTime(cTime, compareCalc.getType(), timeField.getDateStyle());
String lastValue = currentMap.get(lastTime);
String[] dimension = Arrays.copyOfRange(item, 0, checkedField.size());
dimension[timeIndex] = lastTime;
String lastValue = currentMap.get(StringUtils.join(dimension, "-"));
if (StringUtils.isEmpty(cValue) || StringUtils.isEmpty(lastValue)) {
data.get(index)[dataIndex] = null;
item[dataIndex] = null;
} else {
if (StringUtils.equalsIgnoreCase(resultData, "sub")) {
data.get(index)[dataIndex] = new BigDecimal(cValue).subtract(new BigDecimal(lastValue)).toString();
item[dataIndex] = new BigDecimal(cValue).subtract(new BigDecimal(lastValue)).toString();
} else if (StringUtils.equalsIgnoreCase(resultData, "percent")) {
if (StringUtils.isEmpty(lastValue)) {
data.get(index)[dataIndex] = null;
if (Integer.parseInt(lastValue) == 0) {
item[dataIndex] = null;
} else {
data.get(index)[dataIndex] = new BigDecimal(cValue)
item[dataIndex] = new BigDecimal(cValue)
.divide(new BigDecimal(lastValue), 2, RoundingMode.HALF_UP)
.subtract(new BigDecimal(1))
.setScale(2, RoundingMode.HALF_UP)
@ -507,9 +510,7 @@ public class ChartViewService {
}
}
}
index++;
}
}
}
}

View File

@ -63,10 +63,8 @@ export default {
// xaxisextStack
initFieldList() {
const xAxis = JSON.parse(this.chart.xaxis)
const extStack = JSON.parse(this.chart.extStack)
const t1 = xAxis.filter(ele => { return ele.deType === 1 })
const t2 = extStack.filter(ele => { return ele.deType === 1 })
this.fieldList = t1.concat(t2)
this.fieldList = t1
//
if ((!this.compareItem.compareCalc.field || this.compareItem.compareCalc.field === '') && this.fieldList.length > 0) {
this.compareItem.compareCalc.field = this.fieldList[0].id

View File

@ -97,15 +97,15 @@
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="quickCalc">
<span class="el-dropdown-link inner-dropdown-menu">
<span>
<i class="el-icon-crop" />
<span>{{ $t('chart.yoy_label') }}</span>
<i class="el-icon-s-grid" />
<span>{{ $t('chart.quick_calc') }}</span>
<span class="summary-span-item">({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }})</span>
</span>
<i class="el-icon-arrow-right el-icon--right" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="beforeQuickCalc('none')">{{ $t('chart.none') }}</el-dropdown-item>
<el-dropdown-item :disabled="disableEditCompare" :command="beforeQuickCalc('setting')">{{ $t('commons.setting') }}...</el-dropdown-item>
<el-dropdown-item :disabled="disableEditCompare" :command="beforeQuickCalc('setting')">{{ $t('chart.yoy_label') }}...</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>
@ -191,14 +191,10 @@ export default {
},
isEnableCompare() {
const xAxis = JSON.parse(this.chart.xaxis)
const extStack = JSON.parse(this.chart.extStack)
const t1 = xAxis.filter(ele => {
return ele.deType === 1
})
const t2 = extStack.filter(ele => {
return ele.deType === 1
})
if (t1.length > 0 || t2.length > 0) {
if (t1.length > 0 && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') {
this.disableEditCompare = false
} else {
this.disableEditCompare = true

View File

@ -97,15 +97,15 @@
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="quickCalc">
<span class="el-dropdown-link inner-dropdown-menu">
<span>
<i class="el-icon-crop" />
<span>{{ $t('chart.yoy_label') }}</span>
<i class="el-icon-s-grid" />
<span>{{ $t('chart.quick_calc') }}</span>
<span class="summary-span-item">({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }})</span>
</span>
<i class="el-icon-arrow-right el-icon--right" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="beforeQuickCalc('none')">{{ $t('chart.none') }}</el-dropdown-item>
<el-dropdown-item :disabled="disableEditCompare" :command="beforeQuickCalc('setting')">{{ $t('commons.setting') }}...</el-dropdown-item>
<el-dropdown-item :disabled="disableEditCompare" :command="beforeQuickCalc('setting')">{{ $t('chart.yoy_label') }}...</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>
@ -188,14 +188,10 @@ export default {
},
isEnableCompare() {
const xAxis = JSON.parse(this.chart.xaxis)
const extStack = JSON.parse(this.chart.extStack)
const t1 = xAxis.filter(ele => {
return ele.deType === 1
})
const t2 = extStack.filter(ele => {
return ele.deType === 1
})
if ((t1.length + t2.length === 1) && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') {
if (t1.length > 0 && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') {
this.disableEditCompare = false
} else {
this.disableEditCompare = true