CN-197 perf: 调整地图的tooltip

This commit is contained in:
chenjinsong
2021-10-11 19:12:52 +08:00
parent 747a7ecd7c
commit 14a8365e20
6 changed files with 87 additions and 80 deletions

View File

@@ -62,7 +62,7 @@ export function timeUnitFormatter (time, sourceUnit = 'ms', targetUnit, dot = 2)
}
/* 单位转换,返回转换后的[value, unit] */
// unitType = time / number / byte
// unitType = time / number / byte / percent
export default function unitConvert (value, unitType, sourceUnit, targetUnit, dot = 2) {
if (unitType === unitTypes.string) {
if (value) {
@@ -111,3 +111,26 @@ export function getUnitType (column) {
return unitTypes.number
}
}
/* 单位转换,返回转换后的[value, unit]type=time时若value<1ms返回<1mstype=percent时若value<0.01%,返回<0.01% */
export function valueToRangeValue (value, unitType) {
const values = unitConvert(value, unitType)
if (values[0] || values[0] === 0) {
switch (unitType) {
case unitTypes.time: {
if (values[0] < 1) {
return ['<1', 'ms']
}
break
}
case unitTypes.percent: {
if (values[0] < 0.01) {
return ['<0.01', '']
}
break
}
default: break
}
}
return values
}