fix: bps改为1000进制

This commit is contained in:
chenjinsong
2022-04-06 14:48:46 +08:00
parent faf176cf27
commit 42d6efa6ee
4 changed files with 21 additions and 10 deletions

View File

@@ -123,6 +123,7 @@ export const unitTypes = {
time: 'time', time: 'time',
number: 'number', number: 'number',
byte: 'byte', byte: 'byte',
bps: 'bps',
string: 'string', string: 'string',
percent: 'percent' percent: 'percent'
} }

View File

@@ -3,6 +3,7 @@ import _ from 'lodash'
const numberUnit = ['', 'K', 'M', 'G', 'T', 'P', 'E'] const numberUnit = ['', 'K', 'M', 'G', 'T', 'P', 'E']
const byteUnit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'] const byteUnit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']
const bpsUnit = ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps']
const timeUnit = [ // 时间单位步进倍数以ms为基数 const timeUnit = [ // 时间单位步进倍数以ms为基数
{ unit: 'ms', step: 1 }, { unit: 'ms', step: 1 },
{ unit: 's', step: 1000 }, { unit: 's', step: 1000 },
@@ -31,7 +32,10 @@ function asciiCompute (num, ascii = 1000, units, dot = 2) {
export function numberUnitConvert (value, sourceUnit, targetUnit, dot = 2) { export function numberUnitConvert (value, sourceUnit, targetUnit, dot = 2) {
return asciiCompute(value, 1000, numberUnit, dot) return asciiCompute(value, 1000, numberUnit, dot)
} }
export function byteUnitConvert (value, sourceUnit = 'B', targetUnit, dot = 2) { export function bpsUnitConvert (value, sourceUnit, targetUnit, dot = 2) {
return asciiCompute(value, 1000, bpsUnit, dot)
}
export function byteUnitConvert (value, unitType, sourceUnit = 'B', targetUnit, dot = 2) {
return asciiCompute(value, 1024, byteUnit, dot) return asciiCompute(value, 1024, byteUnit, dot)
} }
/* 时间单位转换例如将ms转为h */ /* 时间单位转换例如将ms转为h */
@@ -87,13 +91,21 @@ export default function unitConvert (value, unitType, sourceUnit, targetUnit, do
return timeUnitFormatter(value, sourceUnit, targetUnit, dot) return timeUnitFormatter(value, sourceUnit, targetUnit, dot)
} }
case unitTypes.percent: { case unitTypes.percent: {
return [value, '%'] const r = (value * 100).toFixed(dot)
if (_.isNaN(r)) {
return ['-', '']
} else {
return [r, '%']
}
} }
case unitTypes.number: { case unitTypes.number: {
return numberUnitConvert(value, sourceUnit, targetUnit, dot) return numberUnitConvert(value, sourceUnit, targetUnit, dot)
} }
case unitTypes.bps: {
return bpsUnitConvert(value, sourceUnit, targetUnit, dot)
}
case unitTypes.byte: { case unitTypes.byte: {
return byteUnitConvert(value, sourceUnit, targetUnit, dot) return byteUnitConvert(value, unitType, sourceUnit, targetUnit, dot)
} }
} }
} }
@@ -131,7 +143,7 @@ export function valueToRangeValue (value, unitType) {
} }
case unitTypes.percent: { case unitTypes.percent: {
if (values[0] < 0.01) { if (values[0] < 0.01) {
return ['<0.01', ''] return ['<0.01', '%']
} }
break break
} }

View File

@@ -102,11 +102,7 @@ export default {
timeFilter: Object, // 时间范围 timeFilter: Object, // 时间范围
isFullscreen: Boolean, isFullscreen: Boolean,
panelLock: Boolean, panelLock: Boolean,
entity: Object, entity: Object
showHeader: {
type: Boolean,
default: true
}
}, },
data () { data () {
return { return {
@@ -163,6 +159,9 @@ export default {
}, },
headerHPadding () { headerHPadding () {
return this.$store.getters.getHeaderHPadding return this.$store.getters.getHeaderHPadding
},
showHeader () {
return this.chartInfo.params && this.chartInfo.params.showHeader
} }
}, },
methods: { methods: {

View File

@@ -30,7 +30,6 @@
<panel-chart <panel-chart
:ref="'chart' + item.id" :ref="'chart' + item.id"
:chart-info="item" :chart-info="item"
:show-header="true"
:time-filter="timeFilter" :time-filter="timeFilter"
:entity="entity" :entity="entity"
@groupShow="groupShow" @groupShow="groupShow"