forked from github/dataease
Merge pull request #1426 from dataease/pr@dev@feat_compare
feat(视图): 同比环比
This commit is contained in:
commit
94ad20200e
@ -478,28 +478,31 @@ public class ChartViewService {
|
|||||||
// 1,处理当期数据;2,根据type计算上一期数据;3,根据resultData计算结果
|
// 1,处理当期数据;2,根据type计算上一期数据;3,根据resultData计算结果
|
||||||
Map<String, String> currentMap = new LinkedHashMap<>();
|
Map<String, String> currentMap = new LinkedHashMap<>();
|
||||||
for (String[] item : data) {
|
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();
|
for (int index = 0; index < data.size(); index++) {
|
||||||
int index = 0;
|
String[] item = data.get(index);
|
||||||
while (iterator.hasNext()) {
|
String cTime = item[timeIndex];
|
||||||
Map.Entry<String, String> next = iterator.next();
|
String cValue = item[dataIndex];
|
||||||
String cTime = next.getKey();
|
|
||||||
String cValue = next.getValue();
|
|
||||||
|
|
||||||
|
// 获取计算后的时间,并且与所有维度拼接
|
||||||
String lastTime = calcLastTime(cTime, compareCalc.getType(), timeField.getDateStyle());
|
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)) {
|
if (StringUtils.isEmpty(cValue) || StringUtils.isEmpty(lastValue)) {
|
||||||
data.get(index)[dataIndex] = null;
|
item[dataIndex] = null;
|
||||||
} else {
|
} else {
|
||||||
if (StringUtils.equalsIgnoreCase(resultData, "sub")) {
|
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")) {
|
} else if (StringUtils.equalsIgnoreCase(resultData, "percent")) {
|
||||||
if (StringUtils.isEmpty(lastValue)) {
|
if (Integer.parseInt(lastValue) == 0) {
|
||||||
data.get(index)[dataIndex] = null;
|
item[dataIndex] = null;
|
||||||
} else {
|
} else {
|
||||||
data.get(index)[dataIndex] = new BigDecimal(cValue)
|
item[dataIndex] = new BigDecimal(cValue)
|
||||||
.divide(new BigDecimal(lastValue), 2, RoundingMode.HALF_UP)
|
.divide(new BigDecimal(lastValue), 2, RoundingMode.HALF_UP)
|
||||||
.subtract(new BigDecimal(1))
|
.subtract(new BigDecimal(1))
|
||||||
.setScale(2, RoundingMode.HALF_UP)
|
.setScale(2, RoundingMode.HALF_UP)
|
||||||
@ -507,9 +510,7 @@ public class ChartViewService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,8 @@ export default {
|
|||||||
// 过滤xaxis,extStack所有日期字段
|
// 过滤xaxis,extStack所有日期字段
|
||||||
initFieldList() {
|
initFieldList() {
|
||||||
const xAxis = JSON.parse(this.chart.xaxis)
|
const xAxis = JSON.parse(this.chart.xaxis)
|
||||||
const extStack = JSON.parse(this.chart.extStack)
|
|
||||||
const t1 = xAxis.filter(ele => { return ele.deType === 1 })
|
const t1 = xAxis.filter(ele => { return ele.deType === 1 })
|
||||||
const t2 = extStack.filter(ele => { return ele.deType === 1 })
|
this.fieldList = t1
|
||||||
this.fieldList = t1.concat(t2)
|
|
||||||
// 如果没有选中字段,则默认选中第一个
|
// 如果没有选中字段,则默认选中第一个
|
||||||
if ((!this.compareItem.compareCalc.field || this.compareItem.compareCalc.field === '') && this.fieldList.length > 0) {
|
if ((!this.compareItem.compareCalc.field || this.compareItem.compareCalc.field === '') && this.fieldList.length > 0) {
|
||||||
this.compareItem.compareCalc.field = this.fieldList[0].id
|
this.compareItem.compareCalc.field = this.fieldList[0].id
|
||||||
|
@ -97,15 +97,15 @@
|
|||||||
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="quickCalc">
|
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="quickCalc">
|
||||||
<span class="el-dropdown-link inner-dropdown-menu">
|
<span class="el-dropdown-link inner-dropdown-menu">
|
||||||
<span>
|
<span>
|
||||||
<i class="el-icon-crop" />
|
<i class="el-icon-s-grid" />
|
||||||
<span>{{ $t('chart.yoy_label') }}</span>
|
<span>{{ $t('chart.quick_calc') }}</span>
|
||||||
<span class="summary-span-item">({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }})</span>
|
<span class="summary-span-item">({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }})</span>
|
||||||
</span>
|
</span>
|
||||||
<i class="el-icon-arrow-right el-icon--right" />
|
<i class="el-icon-arrow-right el-icon--right" />
|
||||||
</span>
|
</span>
|
||||||
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-menu slot="dropdown">
|
||||||
<el-dropdown-item :command="beforeQuickCalc('none')">{{ $t('chart.none') }}</el-dropdown-item>
|
<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-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@ -191,14 +191,10 @@ export default {
|
|||||||
},
|
},
|
||||||
isEnableCompare() {
|
isEnableCompare() {
|
||||||
const xAxis = JSON.parse(this.chart.xaxis)
|
const xAxis = JSON.parse(this.chart.xaxis)
|
||||||
const extStack = JSON.parse(this.chart.extStack)
|
|
||||||
const t1 = xAxis.filter(ele => {
|
const t1 = xAxis.filter(ele => {
|
||||||
return ele.deType === 1
|
return ele.deType === 1
|
||||||
})
|
})
|
||||||
const t2 = extStack.filter(ele => {
|
if (t1.length > 0 && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') {
|
||||||
return ele.deType === 1
|
|
||||||
})
|
|
||||||
if (t1.length > 0 || t2.length > 0) {
|
|
||||||
this.disableEditCompare = false
|
this.disableEditCompare = false
|
||||||
} else {
|
} else {
|
||||||
this.disableEditCompare = true
|
this.disableEditCompare = true
|
||||||
|
@ -97,15 +97,15 @@
|
|||||||
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="quickCalc">
|
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="quickCalc">
|
||||||
<span class="el-dropdown-link inner-dropdown-menu">
|
<span class="el-dropdown-link inner-dropdown-menu">
|
||||||
<span>
|
<span>
|
||||||
<i class="el-icon-crop" />
|
<i class="el-icon-s-grid" />
|
||||||
<span>{{ $t('chart.yoy_label') }}</span>
|
<span>{{ $t('chart.quick_calc') }}</span>
|
||||||
<span class="summary-span-item">({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }})</span>
|
<span class="summary-span-item">({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }})</span>
|
||||||
</span>
|
</span>
|
||||||
<i class="el-icon-arrow-right el-icon--right" />
|
<i class="el-icon-arrow-right el-icon--right" />
|
||||||
</span>
|
</span>
|
||||||
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-menu slot="dropdown">
|
||||||
<el-dropdown-item :command="beforeQuickCalc('none')">{{ $t('chart.none') }}</el-dropdown-item>
|
<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-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@ -188,14 +188,10 @@ export default {
|
|||||||
},
|
},
|
||||||
isEnableCompare() {
|
isEnableCompare() {
|
||||||
const xAxis = JSON.parse(this.chart.xaxis)
|
const xAxis = JSON.parse(this.chart.xaxis)
|
||||||
const extStack = JSON.parse(this.chart.extStack)
|
|
||||||
const t1 = xAxis.filter(ele => {
|
const t1 = xAxis.filter(ele => {
|
||||||
return ele.deType === 1
|
return ele.deType === 1
|
||||||
})
|
})
|
||||||
const t2 = extStack.filter(ele => {
|
if (t1.length > 0 && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') {
|
||||||
return ele.deType === 1
|
|
||||||
})
|
|
||||||
if ((t1.length + t2.length === 1) && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') {
|
|
||||||
this.disableEditCompare = false
|
this.disableEditCompare = false
|
||||||
} else {
|
} else {
|
||||||
this.disableEditCompare = true
|
this.disableEditCompare = true
|
||||||
|
Loading…
Reference in New Issue
Block a user