From 6d5f97be66fdfd5f244f23eae1840e913c46249d Mon Sep 17 00:00:00 2001 From: "Alex M. Sielicki" Date: Wed, 17 Jul 2024 21:30:19 +0200 Subject: [PATCH] fix: adding validation for variable ranges for log scales. Addresses #960 --- web-server/components/VariableRanges.js | 15 +++++++++++---- .../js/Components/ControlsButtonVarOptions.js | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/web-server/components/VariableRanges.js b/web-server/components/VariableRanges.js index 603b46a76..0a57dcd44 100644 --- a/web-server/components/VariableRanges.js +++ b/web-server/components/VariableRanges.js @@ -82,7 +82,8 @@ export default class VariableRanges extends React.Component { `, placement: "bottom", trigger: "hover", - content: "Axis Min must be less than Axis Max.", + content: + "Axis Min must be less than Axis Max. Both must be greater than 0 if this variable is using a log axis scale.", }); // Disabling popover tooltips for valid input fields. $(`.${this.class} .validationPopover.valid`).popover("disable"); @@ -146,7 +147,7 @@ export default class VariableRanges extends React.Component { oppositeNum, !min, oppositeCompare, - index + index, ), }; }; @@ -161,9 +162,15 @@ export default class VariableRanges extends React.Component { return true; } // NaNs are invalid - else if (Number.isNaN(inputNum)) { + if (Number.isNaN(inputNum)) { return false; - } else if (min ? inputNum < compare : inputNum > compare) { + } + // Zero and negative values are invalid for log scales + if (this.props.axesVariablesScale?.[key] === "Log" && inputNum <= 0) { + return false; + } + // Validate if not empty and not NaN and not 0 or less for log scale + if (min ? inputNum < compare : inputNum > compare) { // Save min or max to redux store since it's valid this.props.setVariableRange(key, inputNum, min ? "min" : "max"); return true; diff --git a/web-server/plugins/slycat-parameter-image/js/Components/ControlsButtonVarOptions.js b/web-server/plugins/slycat-parameter-image/js/Components/ControlsButtonVarOptions.js index b3d8183e6..d8c709184 100644 --- a/web-server/plugins/slycat-parameter-image/js/Components/ControlsButtonVarOptions.js +++ b/web-server/plugins/slycat-parameter-image/js/Components/ControlsButtonVarOptions.js @@ -310,6 +310,7 @@ class ControlsButtonVarOptions extends React.PureComponent { clearVariableRange={this.props.clearVariableRange} inputLabel="Axis" ref={this.variableRangesRef} + axesVariablesScale={this.props.axes_variables_scale} />