Inline numeric widget configurations (#2792)

This commit is contained in:
Chenlei Hu
2025-03-01 18:09:23 -05:00
committed by GitHub
parent e58fab92d1
commit 503341b966
4 changed files with 49 additions and 74 deletions

View File

@@ -1,43 +0,0 @@
import type {
FloatInputOptions,
IntInputOptions
} from '@/schemas/nodeDefSchema'
export function getNumberDefaults(
inputOptions: IntInputOptions | FloatInputOptions,
options: {
defaultStep: number
precision?: number
enableRounding: boolean
}
) {
const { defaultStep } = options
const {
default: defaultVal = 0,
min = 0,
max = 2048,
step = defaultStep
} = inputOptions
// precision is the number of decimal places to show.
// by default, display the the smallest number of decimal places such that changes of size step are visible.
const { precision = Math.max(-Math.floor(Math.log10(step)), 0) } = options
let round = inputOptions.round
if (options.enableRounding && (round == undefined || round === true)) {
// by default, round the value to those decimal places shown.
round = Math.round(1000000 * Math.pow(0.1, precision)) / 1000000
}
return {
val: defaultVal,
config: {
min,
max,
/** @deprecated Use step2 instead. The 10x value is a legacy implementation. */
step: step * 10.0,
step2: step,
round,
precision
}
}
}