forked from github/dataease
fix(图表-词云图): 修复大小配置中最大最小值都为0时无法获取默认值的问题
This commit is contained in:
parent
b77ff3a9ab
commit
d0d4955b9a
@ -630,21 +630,37 @@ export const getMaxAndMinValueByData = (
|
||||
minValue: number,
|
||||
callback: (max: number, min: number) => void
|
||||
) => {
|
||||
if ((minValue === 0 && maxValue === 0) || minValue === null || maxValue === null) {
|
||||
// 定义一个辅助函数来计算最大值或最小值
|
||||
const calculateExtreme = (isMax: boolean) => {
|
||||
return data.reduce(
|
||||
(extreme, current) => {
|
||||
return isMax
|
||||
? current[field] > extreme
|
||||
? current[field]
|
||||
: extreme
|
||||
: current[field] < extreme
|
||||
? current[field]
|
||||
: extreme
|
||||
},
|
||||
isMax ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER
|
||||
)
|
||||
}
|
||||
if (minValue === null || maxValue === null) {
|
||||
let maxResult = maxValue
|
||||
let minResult = minValue
|
||||
if (maxResult === null) {
|
||||
maxResult = data.reduce((max, current) => {
|
||||
return current[field] > max ? current[field] : max
|
||||
}, Number.MIN_SAFE_INTEGER)
|
||||
maxResult = calculateExtreme(true)
|
||||
}
|
||||
if (minResult === null) {
|
||||
minResult = data.reduce((min, current) => {
|
||||
return current[field] < min ? current[field] : min
|
||||
}, Number.MAX_SAFE_INTEGER)
|
||||
minResult = calculateExtreme(false)
|
||||
}
|
||||
callback(maxResult, minResult)
|
||||
}
|
||||
if (minValue === 0 && maxValue === 0) {
|
||||
const maxResult = calculateExtreme(true)
|
||||
const minResult = calculateExtreme(false)
|
||||
callback(maxResult, minResult)
|
||||
}
|
||||
}
|
||||
|
||||
export const stepsColor = (start, end, steps, gamma) => {
|
||||
|
Loading…
Reference in New Issue
Block a user