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 (
@@ -145,30 +175,26 @@ class PaletteThreshold extends React.Component { id={`wv-layer-options-threshold${index}`} className="wv-layer-options-threshold" > -
- MIN: - this.updateStartThreshold(parseInt(e.target.value, 10))} - style={{ '--value-percent': `${startPercent}%` }} - /> -
-
- MAX: - this.updateEndThreshold(parseInt(e.target.value, 10))} - style={{ '--value-percent': `${endPercent}%` }} - /> -
+ this.updateStartThreshold(Math.ceil(parseFloat(e.target.value, 10)))} + /> + this.updateEndThreshold(Math.ceil(parseFloat(e.target.value, 10)))} + />
{startLabel} diff --git a/web/scss/components/range.scss b/web/scss/components/range.scss index b7f81c3100..6b825455c9 100644 --- a/web/scss/components/range.scss +++ b/web/scss/components/range.scss @@ -102,4 +102,30 @@ .palette-threshold-range { width: 85% ; padding-top: 8px; - } \ No newline at end of file + } + +.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% + ); + } +}