diff --git a/src/app/components/SatButtons/index.tsx b/src/app/components/SatButtons/index.tsx index 33e45ecdbc..ca4e68062d 100644 --- a/src/app/components/SatButtons/index.tsx +++ b/src/app/components/SatButtons/index.tsx @@ -10,22 +10,50 @@ type Props = { }; function SatButtons({ onClick, disabled, min, max }: Props) { - const sizes = [1000, 5000, 10000, 25000]; + let sizes; + + const round = (num: number) => { + return Math.round(num * 10) / 10; + }; + + // round & format: 1M, 1k, 100 + const format = (num: number, pos: number): { t: string; n: number } => { + for (let i = 1e6; i > 1; i /= 1e3) { + if (num >= i) { + const n = round(num / i); + const unit = i === 1e3 ? "k" : "M"; + return { + // text + t: n + unit, + // number + n: pos === 1 || pos === 2 ? n * i : num, + }; + } + } + return { + t: num + "", + n: num, + }; + }; + + if (typeof min === "number" && typeof max === "number" && min < max) { + const range = max - min; + const step = range / 3; + sizes = [min, step + min, range - step + min, max]; + } else { + sizes = [1000, 5000, 10000, 25000]; + } return (