This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
The following commit(s) were added to refs/heads/dev by this push:
new 61f9e32b (infra): fix that dat.GUI always convert values to string in
selection-option case - we convert it back to the original type, especially for
`true`/`false`, `10`/`20` case.
61f9e32b is described below
commit 61f9e32b75aa143f09065e5561fc86876865ad08
Author: 100pah <[email protected]>
AuthorDate: Thu Jul 3 01:17:24 2025 +0800
(infra): fix that dat.GUI always convert values to string in
selection-option case - we convert it back to the original type, especially for
`true`/`false`, `10`/`20` case.
---
src/editor/sandbox/setup.js | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/src/editor/sandbox/setup.js b/src/editor/sandbox/setup.js
index ecabd9c0..968c7ca2 100644
--- a/src/editor/sandbox/setup.js
+++ b/src/editor/sandbox/setup.js
@@ -370,6 +370,38 @@ function setup(isShared) {
const configParams = appEnv.configParameters || {};
const config = appEnv.config;
+
+ // If using seletion/options, dat.GUI always convert value into
string. e.g., convert
+ // `true`, `false` to `'true'`, `'false'`, or convert `10`, `20` to
`'10'`, `'20'`.
+ // This probably bothers users. Therefore, we need to convert it back
to the raw value type.
+ function revertToRawValueForOptions(datGUIController, datGUINewValue) {
+ var name = datGUIController.property;
+ var configVal = configParams[name];
+ if (!configVal || !configVal.options ||
!config.hasOwnProperty(name)) {
+ return;
+ }
+ // Considered `configVal.options` can be either
+ // `[value1, value2, ...]` or `{key1: value2, key2: value2, ...}`.
+ echarts.util.each(configVal.options, function (rawVal) {
+ if ('' + rawVal === datGUINewValue) {
+ config[name] = rawVal;
+ }
+ });
+ }
+
+ const onChange = config.onChange
+ ? function (newValue) {
+ revertToRawValueForOptions(this, newValue);
+ config.onChange();
+ }
+ : null;
+ const onFinishChange = config.onFinishChange
+ ? function (newValue) {
+ revertToRawValueForOptions(this, newValue);
+ config.onFinishChange();
+ }
+ : null;
+
for (const name in config) {
const value = config[name];
if (name !== 'onChange' && name !== 'onFinishChange') {
@@ -399,11 +431,10 @@ function setup(isShared) {
if (!controller) {
controller = gui[isColor ? 'addColor' : 'add'](config, name);
}
- config.onChange && controller.onChange(config.onChange);
- config.onFinishChange &&
- controller.onFinishChange(config.onFinishChange);
+ onChange && controller.onChange(onChange);
+ onFinishChange && controller.onFinishChange(onFinishChange);
}
- }
+ } // End of `for (const name in config)`
}
}
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]