Skip to content

Commit

Permalink
fix: adding validation for variable ranges for log scales. Addresses #…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsielicki committed Jul 17, 2024
1 parent dbc15b8 commit 6d5f97b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions web-server/components/VariableRanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export default class VariableRanges extends React.Component {
</div>`,
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");
Expand Down Expand Up @@ -146,7 +147,7 @@ export default class VariableRanges extends React.Component {
oppositeNum,
!min,
oppositeCompare,
index
index,
),
};
};
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class ControlsButtonVarOptions extends React.PureComponent {
clearVariableRange={this.props.clearVariableRange}
inputLabel="Axis"
ref={this.variableRangesRef}
axesVariablesScale={this.props.axes_variables_scale}
/>
<ClearAllButton
label="Clear All Scatterplot Variable Ranges"
Expand Down

0 comments on commit 6d5f97b

Please sign in to comment.