add option change order of magnitude

This commit is contained in:
Alfred Melch 2019-08-06 17:50:07 +02:00
parent 4f3a2c0c5f
commit 4d29b6914e
2 changed files with 24 additions and 3 deletions

View File

@ -11,7 +11,7 @@ main {
#status { #status {
background-color: bisque; background-color: bisque;
} }
form { .form {
display: grid; display: grid;
grid-template-columns: auto auto; grid-template-columns: auto auto;
grid-gap: 10px; grid-gap: 10px;

View File

@ -47,11 +47,26 @@ export class Form extends Component {
this.props.onFormChange({ ...this.state, tolRange }) this.props.onFormChange({ ...this.state, tolRange })
} }
/** changes order of magnitude for all tolerance values */
changeOOM(mode) {
let maxPrecision = 6
let p = Math.pow(10, maxPrecision)
let mod = mode === 'increase' ? 10 : 0.1
let { tolStart, tolStep, tolEnd } = this.state
const round = val => Math.round(val * p) / p
const modify = val => (round(val * mod) === 0 ? val : round(val * mod))
this.setState({
tolStart: modify(tolStart),
tolStep: modify(tolStep),
tolEnd: modify(tolEnd)
})
}
render() { render() {
return ( return (
<div className="component"> <div className="component">
<h2>Settings</h2> <h2>Settings</h2>
<form> <div className="form">
<label>Dataset</label> <label>Dataset</label>
<select <select
name="dataset" name="dataset"
@ -65,6 +80,12 @@ export class Form extends Component {
))} ))}
</select> </select>
<label>Tolerance order of magnitude</label>
<div>
<button onClick={() => this.changeOOM('increase')}>+</button>
<button onClick={() => this.changeOOM('decrease')}>-</button>
</div>
<label>Tolerance start: </label> <label>Tolerance start: </label>
<input <input
name="tolStart" name="tolStart"
@ -169,7 +190,7 @@ export class Form extends Component {
checked={this.state.debouncedChart} checked={this.state.debouncedChart}
onChange={this.handleInputChange} onChange={this.handleInputChange}
/> />
</form> </div>
</div> </div>
) )
} }