diff --git a/src/utils/constants.js b/src/utils/constants.js index 361e98ad..c9779eae 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -123,6 +123,7 @@ export const unitTypes = { time: 'time', number: 'number', byte: 'byte', + bps: 'bps', string: 'string', percent: 'percent' } diff --git a/src/utils/unit-convert.js b/src/utils/unit-convert.js index 06833dcb..2597ee45 100644 --- a/src/utils/unit-convert.js +++ b/src/utils/unit-convert.js @@ -3,6 +3,7 @@ import _ from 'lodash' const numberUnit = ['', 'K', 'M', 'G', 'T', 'P', 'E'] const byteUnit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'] +const bpsUnit = ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps'] const timeUnit = [ // 时间单位步进倍数,以ms为基数 { unit: 'ms', step: 1 }, { unit: 's', step: 1000 }, @@ -31,7 +32,10 @@ function asciiCompute (num, ascii = 1000, units, dot = 2) { export function numberUnitConvert (value, sourceUnit, targetUnit, dot = 2) { 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) } /* 时间单位转换,例如将ms转为h */ @@ -87,13 +91,21 @@ export default function unitConvert (value, unitType, sourceUnit, targetUnit, do return timeUnitFormatter(value, sourceUnit, targetUnit, dot) } case unitTypes.percent: { - return [value, '%'] + const r = (value * 100).toFixed(dot) + if (_.isNaN(r)) { + return ['-', ''] + } else { + return [r, '%'] + } } case unitTypes.number: { return numberUnitConvert(value, sourceUnit, targetUnit, dot) } + case unitTypes.bps: { + return bpsUnitConvert(value, sourceUnit, targetUnit, dot) + } 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: { if (values[0] < 0.01) { - return ['<0.01', ''] + return ['<0.01', '%'] } break } diff --git a/src/views/charts/PanelChart.vue b/src/views/charts/PanelChart.vue index 93ae1089..55f12ee5 100644 --- a/src/views/charts/PanelChart.vue +++ b/src/views/charts/PanelChart.vue @@ -102,11 +102,7 @@ export default { timeFilter: Object, // 时间范围 isFullscreen: Boolean, panelLock: Boolean, - entity: Object, - showHeader: { - type: Boolean, - default: true - } + entity: Object }, data () { return { @@ -163,6 +159,9 @@ export default { }, headerHPadding () { return this.$store.getters.getHeaderHPadding + }, + showHeader () { + return this.chartInfo.params && this.chartInfo.params.showHeader } }, methods: { diff --git a/src/views/charts/PanelChartList.vue b/src/views/charts/PanelChartList.vue index 1b05f62e..51ae0e68 100644 --- a/src/views/charts/PanelChartList.vue +++ b/src/views/charts/PanelChartList.vue @@ -30,7 +30,6 @@