mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-24 00:09:32 +00:00
[Refactor] useFloatWidget composable (#2504)
This commit is contained in:
32
src/utils/mathUtil.ts
Normal file
32
src/utils/mathUtil.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { InputSpec } from '@/types/apiTypes'
|
||||
|
||||
export function getNumberDefaults(
|
||||
inputOptions: InputSpec[1],
|
||||
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, step: 10.0 * step, round, precision }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user