diff --git a/web/js/components/layer/settings/palette-threshold.js b/web/js/components/layer/settings/palette-threshold.js index a26de128d1..2100a25d65 100644 --- a/web/js/components/layer/settings/palette-threshold.js +++ b/web/js/components/layer/settings/palette-threshold.js @@ -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); @@ -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, @@ -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 @@ -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 (