(min?: number, max?: number, step?: number | null)
| 119 | * Calculate default step if not defined |
| 120 | */ |
| 121 | export const calcStep = (min?: number, max?: number, step?: number | null) => { |
| 122 | if (step) { |
| 123 | return step; |
| 124 | } |
| 125 | |
| 126 | if (isNil(min) || isNil(max)) { |
| 127 | return 1; |
| 128 | } |
| 129 | |
| 130 | const diff = max > min ? max - min : min - max; |
| 131 | |
| 132 | const v = (Math.abs(diff) + Number.EPSILON) / 100; |
| 133 | const N = Math.floor(Math.log10(v)); |
| 134 | return [ |
| 135 | Number(Math.pow(10, N)), |
| 136 | 2 * Math.pow(10, N), |
| 137 | 5 * Math.pow(10, N), |
| 138 | ].sort((a, b) => Math.abs(a - v) - Math.abs(b - v))[0]; |
| 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * Set min and max if they are undefined and marks are defined |
no test coverage detected
searching dependent graphs…