Commit 4a23926d authored by Jenny's avatar Jenny

feat: 仪表盘进度条重构

parent fc407217
...@@ -43,72 +43,70 @@ ...@@ -43,72 +43,70 @@
devicePixelRatio: canvasDpr devicePixelRatio: canvasDpr
}) })
canvas.setChart(chart) canvas.setChart(chart)
const { endVal } = this.elementData.dataList
const { width: pCanvasWidth, strokeColor, trailColor, titleColor, strokeWidth, gapPosition, gapDegree, strokeLinecap} = this.elementInfo.option.progress
const guageChart = [{ const guageChart = [{
name: "", name: "",
value: this.elementData.dataList.endVal value: endVal
}] }]
const color = [ const color = [
[this.elementData.dataList.endVal / 100, this.elementInfo.option.progress [endVal / 100, strokeColor],
.strokeColor [1, trailColor]
],
[1, this.elementInfo.option.progress.trailColor]
] ]
const strokeWidth = this.$u.common.pxToRpx(this.elementInfo.option.progress.strokeWidth)
var startAngle = 180 var startAngle = 180
var endAngle = 0 var endAngle = 0
switch (this.elementInfo.option.progress.gapPosition) { switch (gapPosition) {
case 'bottom': case 'bottom':
if (this.elementInfo.option.progress.gapDegree > 180) { if (gapDegree > 180) {
startAngle = 90 + (360 - this.elementInfo.option.progress.gapDegree) / 2 startAngle = 45 + (360 - gapDegree) / 2
endAngle = 90 - (360 - this.elementInfo.option.progress.gapDegree) / 2 endAngle = 135 - (360 - gapDegree) / 2
} else { } else {
startAngle = 270 - this.elementInfo.option.progress.gapDegree / 2 startAngle = 225 - gapDegree / 2
endAngle = 0 - (90 - this.elementInfo.option.progress.gapDegree / 2) endAngle = 45 - (90 - gapDegree / 2)
} }
break; break;
case 'top': case 'top':
if (this.elementInfo.option.progress.gapDegree > 180) { if (gapDegree > 180) {
startAngle = 270 + (360 - this.elementInfo.option.progress.gapDegree) / 2 startAngle = 225 + (360 - gapDegree) / 2
endAngle = 270 - (360 - this.elementInfo.option.progress.gapDegree) / 2 endAngle = 315 - (360 - gapDegree) / 2
} else { } else {
startAngle = 360 + (90 - this.elementInfo.option.progress.gapDegree / 2) startAngle = 315 + (90 - gapDegree / 2)
endAngle = 90 + (this.elementInfo.option.progress.gapDegree / 2) endAngle = 135 + (gapDegree / 2)
} }
break; break;
case 'left': case 'left':
if (this.elementInfo.option.progress.gapDegree > 180) { if (gapDegree > 180) {
startAngle = 0 + (360 - this.elementInfo.option.progress.gapDegree) / 2 startAngle = -45 + (360 - gapDegree) / 2
endAngle = 0 - (360 - this.elementInfo.option.progress.gapDegree) / 2 endAngle = 45 - (360 - gapDegree) / 2
} else { } else {
startAngle = 180 - this.elementInfo.option.progress.gapDegree / 2 startAngle = 135 - gapDegree / 2
endAngle = -180 + this.elementInfo.option.progress.gapDegree / 2 endAngle = -135 + gapDegree / 2
} }
break; break;
default: default:
startAngle = 360 - this.elementInfo.option.progress.gapDegree / 2 startAngle = 315 - gapDegree / 2
endAngle = 0 + this.elementInfo.option.progress.gapDegree / 2 endAngle = 45 + gapDegree / 2
break; break;
} }
const axisLineWidth = strokeWidth / 100 * pCanvasWidth
const options = { const options = {
...this.elementInfo.option, ...this.elementInfo.option,
tooltip: { tooltip: {
formatter: '{a} <br/>{b} : {c}%' formatter: '{a} <br/>{b} : {c}%'
}, },
title: [{ title: [{
text: this.elementData.dataList.endVal + '%', text: endVal + '%',
x: 'center', x: 'center',
top: '45%', top: 'middle',
textStyle: { textStyle: {
fontSize: 30, fontSize: Math.max(14 * pCanvasWidth / 132, 14),
color: this.elementInfo.option.progress.titleColor, color: titleColor,
}, },
}], }],
series: [{ series: [{
type: 'gauge', type: 'gauge',
// center: ['50%', '50%'], startAngle: startAngle + 25,
radius: '50%', endAngle: endAngle - 25,
startAngle: startAngle,
endAngle: endAngle,
pointer: { pointer: {
show: false, show: false,
}, },
...@@ -116,12 +114,12 @@ ...@@ -116,12 +114,12 @@
show: true, show: true,
lineStyle: { lineStyle: {
color: color, color: color,
width: strokeWidth, width: axisLineWidth,
shadowOffsetX: 0, shadowOffsetX: 0,
shadowOffsetY: 0, shadowOffsetY: 0,
opacity: 1, opacity: 1,
}, },
roundCap: this.elementInfo.option.progress.strokeLinecap == 'round' ? true : false roundCap: strokeLinecap == 'round' ? true : false
}, },
splitLine: { splitLine: {
show: false show: false
...@@ -132,8 +130,7 @@ ...@@ -132,8 +130,7 @@
axisTick: { axisTick: {
show: false show: false
}, },
radius: pCanvasWidth / 2 - strokeWidth * 2,
radius: '90%',
}] }]
} }
chart.setOption(options) chart.setOption(options)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment