forked from ddrilling/asb_cloud_front
Улучшено отображение автоопределяемых диапазонов
This commit is contained in:
parent
bd81aa0401
commit
e39ce8d410
@ -35,13 +35,14 @@ const roundTo = (v: number, to: number = 50) => {
|
|||||||
return (v > 0 ? Math.ceil : Math.round)(v / to) * to
|
return (v > 0 ? Math.ceil : Math.round)(v / to) * to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getNear = (n: number) => {
|
||||||
|
let k = 0
|
||||||
|
for (let c = Math.abs(n); c >= 1; c /= 10) k++
|
||||||
|
return Math.pow(10, k) * Math.sign(n)
|
||||||
|
}
|
||||||
|
|
||||||
const calculateDomain = (mm: MinMax): Required<MinMax> => {
|
const calculateDomain = (mm: MinMax): Required<MinMax> => {
|
||||||
let round = Math.abs((mm.max ?? 0) - (mm.min ?? 0))
|
const round = getNear(Math.abs((mm.max ?? 0) - (mm.min ?? 0))) || 10
|
||||||
if (round < 10) round = 10
|
|
||||||
else if (round < 100) round = roundTo(round, 10)
|
|
||||||
else if (round < 1000) round = roundTo(round, 100)
|
|
||||||
else if (round < 10000) round = roundTo(round, 1000)
|
|
||||||
else round = 0
|
|
||||||
let min = roundTo(mm.min ?? 0, round)
|
let min = roundTo(mm.min ?? 0, round)
|
||||||
let max = roundTo(mm.max ?? round, round)
|
let max = roundTo(mm.max ?? round, round)
|
||||||
if (round && Math.abs(min - max) < round) {
|
if (round && Math.abs(min - max) < round) {
|
||||||
|
Loading…
Reference in New Issue
Block a user