Skip to content

Commit

Permalink
Converted to double-slider
Browse files Browse the repository at this point in the history
  • Loading branch information
christof-wittreich committed Aug 8, 2023
1 parent 789d1bf commit 4913fef
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 28 deletions.
80 changes: 53 additions & 27 deletions web/js/components/layer/settings/palette-threshold.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
checkTemperatureUnitConversion, convertPaletteValue,
} from '../../../modules/settings/util';

const sliderWidth = 264;
const thumbsize = 22;

class PaletteThreshold extends React.Component {
constructor(props) {
super(props);
Expand All @@ -14,12 +17,24 @@ class PaletteThreshold extends React.Component {
start,
end,
squashed,
avg: 0,
};
this.debounceSetRange = lodashDebounce(props.setRange, 300);
this.updateSquash = this.updateSquash.bind(this);
this.updateThreshold = this.updateThreshold.bind(this);
}

componentDidUpdate() {
const {
start, end, avg,
} = this.state;
if (avg !== Math.round((start + end) / 2)) {
this.setState({
avg: Math.round((start + end) / 2),
});
}
}

updateSquash() {
const {
setRange, layerId, index, groupName, palette, legend,
Expand Down Expand Up @@ -100,11 +115,12 @@ class PaletteThreshold extends React.Component {

render() {
const {
start, end, squashed,
start, end, squashed, avg,
} = this.state;
const {
index, min, max, legend, globalTemperatureUnit,
} = this.props;

const units = legend.units || '';
const { needsConversion, legendTempUnit } = checkTemperatureUnitConversion(units, globalTemperatureUnit);
let startLabel = start === 0 && legend.minLabel
Expand All @@ -124,8 +140,22 @@ class PaletteThreshold extends React.Component {
endLabel += ` ${units}`;
}

const startPercent = ((start - min) / (max - min)) * 100;
const endPercent = ((end - min) / (max - min)) * 100;
const minWidth = thumbsize + ((avg - min) / (max - min)) * (sliderWidth - (2 * thumbsize));
const maxWidth = thumbsize + ((max - avg) / (max - min)) * (sliderWidth - (2 * thumbsize));
const minPercent = ((start - min) / (avg - min)) * 100;
const maxPercent = ((end - avg) / (max - avg)) * 100;
const styles = {
min: {
width: minWidth,
left: 0,
'--min-range-percent': `${minPercent}%`,
},
max: {
width: maxWidth,
left: minWidth,
'--max-range-percent': `${maxPercent}%`,
},
};

return (
<div className="layer-threshold-select settings-component">
Expand All @@ -145,30 +175,26 @@ class PaletteThreshold extends React.Component {
id={`wv-layer-options-threshold${index}`}
className="wv-layer-options-threshold"
>
<div className="flex align-items-center">
<span className="me-2">MIN:</span>
<input
type="range"
className="form-range start-range palette-threshold-range"
value={start}
min={min}
max={max}
onChange={(e) => this.updateStartThreshold(parseInt(e.target.value, 10))}
style={{ '--value-percent': `${startPercent}%` }}
/>
</div>
<div className="flex align-items-center mt-2">
<span className="me-2">MAX:</span>
<input
type="range"
className="form-range end-range palette-threshold-range"
value={end}
min={min}
max={max}
onChange={(e) => this.updateEndThreshold(parseInt(e.target.value, 10))}
style={{ '--value-percent': `${endPercent}%` }}
/>
</div>
<input
className="double-range form-range start-range palette-threshold-range"
style={styles.min}
name="min"
type="range"
min={min}
max={avg}
value={start}
onChange={(e) => this.updateStartThreshold(Math.ceil(parseFloat(e.target.value, 10)))}
/>
<input
className="double-range form-range end-range palette-threshold-range"
style={styles.max}
name="max"
type="range"
min={avg}
max={max}
value={end}
onChange={(e) => this.updateEndThreshold(Math.ceil(parseFloat(e.target.value, 10)))}
/>
<div className="wv-label mt-3">
<span className="wv-label-range-min wv-label-range">
{startLabel}
Expand Down
28 changes: 27 additions & 1 deletion web/scss/components/range.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,30 @@
.palette-threshold-range {
width: 85% ;
padding-top: 8px;
}
}

.double-range {
&.start-range::-webkit-slider-runnable-track {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
background: linear-gradient(
to right,
#ccc 0%,
#ccc var(--min-range-percent),
#ABE2FB var(--min-range-percent),
#ABE2FB 100%
);
}

&.end-range::-webkit-slider-runnable-track {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
background: linear-gradient(
to right,
#ABE2FB 0%,
#ABE2FB var(--max-range-percent),
#ccc var(--max-range-percent),
#ccc 100%
);
}
}

0 comments on commit 4913fef

Please sign in to comment.