Skip to content

Commit

Permalink
Fix bugs in 'step' scale & color max label (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisvasq committed Dec 11, 2024
1 parent 6b6f1bf commit 723ba1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/ui/views/map/ColorLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const NumericalColorLegend = ({
? `[${getFormattedValue(index - 1)}, ${getFormattedValue(index)}) "${getLabel(index)}"`
: `"${getLabel(index)}"`
: isStepScale
? `${index < 1 ? `(-\u221E, ${getFormattedValue(index)})` : `[${getFormattedValue(index)}, \u221E)`}`
? `${index < 1 ? `(-\u221E, ${getFormattedValue(index)})` : `[${getFormattedValue(index - 1)}, \u221E)`}`
: `${index < 1 ? 'Min' : 'Max'}`,
[getFormattedValue, getLabel, isStepScale, values]
)
Expand Down Expand Up @@ -226,16 +226,15 @@ const NumericalColorLegend = ({

{showColorPickers &&
(values.length < 3 ? (
// BUG: For some reason the `sx` prop doesn't work here
<Stack direction="row" spacing={1} style={{ marginTop: 0 }}>
<ColorPicker
colorLabel="Min"
colorLabel={getColorLabel(0)}
value={colors[0]}
onChange={handleChangeColorByIndex(0)}
onClose={handleClose}
/>
<ColorPicker
colorLabel="Max"
colorLabel={getColorLabel(1)}
value={colors[1]}
onChange={handleChangeColorByIndex(1)}
onClose={handleClose}
Expand Down
12 changes: 6 additions & 6 deletions src/utils/scales.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export const getScaledValueAlt = R.curry(
: () => {
throw new Error(`Invalid scale "${scale}"`)
}
const scaleFunc = scaleBuilder
.domain(domain)
.range(range)
.unknown(fallback)
?.clamp(true) // Clamp whenever the scaling function supports it
return scaleFunc(value) // Return the scaled value or the fallback
const scaleFunc = scaleBuilder.domain(domain).range(range).unknown(fallback)
// Return the scaled value or the fallback
return scale === scaleId.STEP
? scaleFunc(value)
: // Clamp for all scales except the step function
scaleFunc.clamp(true)(value)
}
)

0 comments on commit 723ba1e

Please sign in to comment.