Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
7c93afd2
Unverified
Commit
7c93afd2
authored
Sep 19, 2023
by
City
Committed by
GitHub
Sep 18, 2023
Browse files
Manual float precision, toggle for old behavior (#1541)
* Add toggle for float rounding * Add manual precision override
parent
26cd8405
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
web/scripts/ui.js
web/scripts/ui.js
+19
-0
web/scripts/widgets.js
web/scripts/widgets.js
+7
-5
No files found.
web/scripts/ui.js
View file @
7c93afd2
...
...
@@ -577,6 +577,25 @@ export class ComfyUI {
defaultValue
:
false
,
});
this
.
settings
.
addSetting
({
id
:
"
Comfy.DisableFloatRounding
"
,
name
:
"
Disable rounding floats (requires page reload).
"
,
type
:
"
boolean
"
,
defaultValue
:
false
,
});
this
.
settings
.
addSetting
({
id
:
"
Comfy.FloatRoundingPrecision
"
,
name
:
"
Decimal places [0 = auto] (requires page reload).
"
,
type
:
"
slider
"
,
attrs
:
{
min
:
0
,
max
:
6
,
step
:
1
,
},
defaultValue
:
0
,
});
const
fileInput
=
$el
(
"
input
"
,
{
id
:
"
comfy-file-input
"
,
type
:
"
file
"
,
...
...
web/scripts/widgets.js
View file @
7c93afd2
import
{
api
}
from
"
./api.js
"
function
getNumberDefaults
(
inputData
,
defaultStep
)
{
function
getNumberDefaults
(
inputData
,
defaultStep
,
app
)
{
let
defaultVal
=
inputData
[
1
][
"
default
"
];
let
{
min
,
max
,
step
,
round
}
=
inputData
[
1
];
...
...
@@ -8,12 +8,14 @@ function getNumberDefaults(inputData, defaultStep) {
if
(
min
==
undefined
)
min
=
0
;
if
(
max
==
undefined
)
max
=
2048
;
if
(
step
==
undefined
)
step
=
defaultStep
;
// 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.
let
precision
=
Math
.
max
(
-
Math
.
floor
(
Math
.
log10
(
step
)),
0
);
if
(
app
.
ui
.
settings
.
getSettingValue
(
"
Comfy.FloatRoundingPrecision
"
)
>
0
)
{
precision
=
app
.
ui
.
settings
.
getSettingValue
(
"
Comfy.FloatRoundingPrecision
"
);
}
if
(
round
==
undefined
||
round
===
true
)
{
if
(
!
app
.
ui
.
settings
.
getSettingValue
(
"
Comfy.DisableFloatRounding
"
)
&&
(
round
==
undefined
||
round
===
true
)
)
{
// by default, round the value to those decimal places shown.
round
=
Math
.
round
(
1000000
*
Math
.
pow
(
0.1
,
precision
))
/
1000000
;
}
...
...
@@ -273,7 +275,7 @@ export const ComfyWidgets = {
"
INT:noise_seed
"
:
seedWidget
,
FLOAT
(
node
,
inputName
,
inputData
,
app
)
{
let
widgetType
=
isSlider
(
inputData
[
1
][
"
display
"
],
app
);
const
{
val
,
config
}
=
getNumberDefaults
(
inputData
,
0.5
);
const
{
val
,
config
}
=
getNumberDefaults
(
inputData
,
0.5
,
app
);
return
{
widget
:
node
.
addWidget
(
widgetType
,
inputName
,
val
,
function
(
v
)
{
if
(
config
.
round
)
{
...
...
@@ -285,7 +287,7 @@ export const ComfyWidgets = {
},
INT
(
node
,
inputName
,
inputData
,
app
)
{
let
widgetType
=
isSlider
(
inputData
[
1
][
"
display
"
],
app
);
const
{
val
,
config
}
=
getNumberDefaults
(
inputData
,
1
);
const
{
val
,
config
}
=
getNumberDefaults
(
inputData
,
1
,
app
);
Object
.
assign
(
config
,
{
precision
:
0
});
return
{
widget
:
node
.
addWidget
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment