refactor: 测试计划报告图表样式

This commit is contained in:
chenjianxing 2021-09-01 18:45:00 +08:00 committed by jianxing
parent e068f96901
commit c5441433b4
4 changed files with 40 additions and 90 deletions

View File

@ -33,7 +33,7 @@ export default {
name: this.name, name: this.name,
type: 'pie', type: 'pie',
left: -150, left: -150,
radius: ['40%', '60%'], radius: ['40%', '50%'],
avoidLabelOverlap: false, avoidLabelOverlap: false,
label: { label: {
// padding: [10, 10, 20, 10], // padding: [10, 10, 20, 10],

View File

@ -68,7 +68,9 @@ export default {
top: 40%; top: 40%;
line-height: 30px; line-height: 30px;
border-radius: 0 15px 15px 0; border-radius: 0 15px 15px 0;
background-color: #acb7c1; /*background-color: #acb7c1;*/
background-color: #783887;
color: white;
display: inline-block; display: inline-block;
position: absolute; position: absolute;
cursor: pointer; cursor: pointer;

View File

@ -5,7 +5,8 @@
<ms-doughnut-pie-chart :name="$t('单接口用例')" :data="caseCharData" ref="functionChar"/> <ms-doughnut-pie-chart :name="$t('单接口用例')" :data="caseCharData" ref="functionChar"/>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<api-scenario-char-result :data="scenarioCharData"/> <api-scenario-char-result :name="'场景用例数'" :data="scenarioCharData"/>
<api-scenario-char-result style="margin-top: -50px;" :name="'步骤用例数'" :data="stepCharData"/>
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
@ -25,12 +26,16 @@ export default {
caseDataMap: new Map([ caseDataMap: new Map([
["success", {name: this.$t('test_track.plan_view.pass'), itemStyle: {color: '#67C23A'}}], ["success", {name: this.$t('test_track.plan_view.pass'), itemStyle: {color: '#67C23A'}}],
["Success", {name: this.$t('test_track.plan_view.pass'), itemStyle: {color: '#67C23A'}}], ["Success", {name: this.$t('test_track.plan_view.pass'), itemStyle: {color: '#67C23A'}}],
["Pass", {name: this.$t('test_track.plan_view.pass'), itemStyle: {color: '#67C23A'}}],
["error", {name: this.$t('test_track.plan_view.failure'), itemStyle: {color: '#F56C6C'}}], ["error", {name: this.$t('test_track.plan_view.failure'), itemStyle: {color: '#F56C6C'}}],
["Fail", {name: this.$t('test_track.plan_view.failure'), itemStyle: {color: '#F56C6C'}}], ["Fail", {name: this.$t('test_track.plan_view.failure'), itemStyle: {color: '#F56C6C'}}],
["Failure", {name: this.$t('test_track.plan_view.failure'), itemStyle: {color: '#F56C6C'}}],
["Prepare", {name: this.$t('api_test.home_page.detail_card.unexecute'), itemStyle: {color: '#909399'}}], ["Prepare", {name: this.$t('api_test.home_page.detail_card.unexecute'), itemStyle: {color: '#909399'}}],
["Underway", {name: this.$t('api_test.home_page.detail_card.unexecute'), itemStyle: {color: '#909399'}}],
]), ]),
caseCharData: [], caseCharData: [],
scenarioCharData: [], scenarioCharData: [],
stepCharData: [],
isShow: true isShow: true
} }
}, },
@ -66,32 +71,20 @@ export default {
let apiScenarioData = []; let apiScenarioData = [];
this.apiResult.apiScenarioData.forEach(item => { this.apiResult.apiScenarioData.forEach(item => {
let data = this.getDataByStatus(item.status); let data = this.getDataByStatus(item.status);
data.data = [item.count]; data.value = item.count;
for (let i = 0; i < this.apiResult.apiScenarioStepData.length; i++) {
let stepItem = this.apiResult.apiScenarioStepData[i];
if (item.status) {
if (item.status === 'Fail' && stepItem.status === 'Failure') {
data.data.push(stepItem.count);
break;
}
if (item.status === 'Success' && stepItem.status === 'Pass') {
data.data.push(stepItem.count);
break;
}
if (item.status === 'Prepare' && stepItem.status === 'Underway') {
data.data.push(stepItem.count);
break;
}
} else {
if (stepItem.status === 'Underway') {
data.data.push(stepItem.count);
break;
}
}
}
apiScenarioData.push(data); apiScenarioData.push(data);
}); });
let stepCharData = [];
for (let i = 0; i < this.apiResult.apiScenarioStepData.length; i++) {
let stepItem = this.apiResult.apiScenarioStepData[i];
let data = this.getDataByStatus(stepItem.status);
data.value = stepItem.count;
stepCharData.push(data);
}
this.scenarioCharData = apiScenarioData; this.scenarioCharData = apiScenarioData;
this.stepCharData = stepCharData;
}, },
getDataByStatus(status) { getDataByStatus(status) {
let tmp = this.caseDataMap.get(status); let tmp = this.caseDataMap.get(status);

View File

@ -1,5 +1,5 @@
<template> <template>
<ms-chart v-if="visible" :options="options"/> <ms-chart style="height: 250px" v-if="visible" :options="options"/>
</template> </template>
<script> <script>
@ -26,24 +26,16 @@ export default {
}, },
legend: { legend: {
data: [], data: [],
// orient: 'vertical',
// right: 0,
// bottom: '40%',
}, },
grid: { grid: {
left: 100 left: 100
}, },
xAxis: { xAxis: {
// type: 'value', type: 'value',
// // name: 'Days',
// axisLabel: {
// formatter: '{value}'
// }
}, },
yAxis: { yAxis: {
type: 'category', type: 'category',
inverse: true, data: [],
data: ['场景用例数', '步骤用例数'],
axisLabel: { axisLabel: {
formatter: function (value) { formatter: function (value) {
}, },
@ -64,30 +56,12 @@ export default {
}, },
series: [ series: [
{ {
name: '未执行', data: [],
type: 'bar', type: 'bar',
data: [165, 170], barWidth: 20,
label: seriesLabel, label: {
itemStyle: { show: true,
color: '#909399' formatter: {}
}
},
{
name: '成功',
type: 'bar',
label: seriesLabel,
data: [150, 105],
itemStyle: {
color: '#F56C6C'
}
},
{
name: '失败',
type: 'bar',
label: seriesLabel,
data: [220, 82],
itemStyle: {
color: '#67C23A'
} }
} }
] ]
@ -123,45 +97,26 @@ export default {
}); });
}, },
setFormatterFunc() { setFormatterFunc() {
let data = this.data;
let caseCount = 0; let dataCount = 0;
let stepCount = 0;
this.data.forEach(item => { this.data.forEach(item => {
caseCount += item.data[0]; dataCount += item.value;
if (item.data[1]) {
stepCount += item.data[1];
}
}); });
let formatterFuc = function (value) { let formatterFuc = function (item) {
let total = 0; return item.data.value + '/' + ((item.data.value / dataCount) * 100).toFixed(0) + '%';
if (value.dataIndex == 0) {
total = caseCount;
} else {
total = stepCount;
}
return value.data + '/' + ((value.data / total) * 100).toFixed(0) + '%';
}; };
this.data.forEach(item => { this.options.series[0].data = this.data;
item.type = 'bar'; this.options.series[0].label.formatter = formatterFuc;
item.label = {
show: true,
formatter: formatterFuc
};
});
this.options.series = data;
let name = this.name;
this.options.yAxis.axisLabel.formatter = function (value) { this.options.yAxis.axisLabel.formatter = function (value) {
if (value === '场景用例数') { return '{name|' + name + '}\n' + '{count| ' + dataCount + '}';
return '{name|场景用例数}\n' + '{count| ' + caseCount + '}';
} else {
return '{name|步骤用例数}\n' + '{count|' + stepCount + '}';
}
}; };
this.options.legend.data = data.map(i => i.name); this.options.legend.data = this.data.map(i => i.name);
this.options.yAxis.data = this.data.map(i => i.name);
}, },
} }
} }