Skip to content

Commit

Permalink
Remove non-essential 'log' base from scale (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisvasq committed Dec 11, 2024
1 parent 3ed1316 commit 5007bd8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/ui/views/map/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,10 @@ export const ScaleSelector = ({
{...{ onSelect }}
/>
</FormControl>
{scale !== scaleId.LINEAR && scale !== scaleId.STEP && (
{scale === scaleId.POW && (
<NumberInput
sx={{ width: 'auto' }}
label={getScaleParamLabel(scaleParamId)}
min={scale === scaleId.LOG ? 0.0001 : -Infinity}
max={Infinity}
numberFormat={{}}
value={R.propOr(
getScaleParamDefaults(scaleParamId),
Expand Down
2 changes: 0 additions & 2 deletions src/utils/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ export const scaleId = {

export const scaleParamId = {
EXPONENT: 'exponent',
BASE: 'base',
}

export const scaleParamsById = {
[scaleId.LOG]: scaleParamId.BASE,
[scaleId.POW]: scaleParamId.EXPONENT,
}

Expand Down
20 changes: 9 additions & 11 deletions src/utils/scales.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export const scaleIndexedOptions = {
[scaleId.POW]: { label: 'Power', iconName: 'pi/PiArrowBendRightUp' },
}

// eslint-disable-next-line ramda/cond-simplification
export const getScaleParamLabel = R.cond([
[R.equals(scaleParamId.BASE), R.always('Base')],
[R.equals(scaleParamId.EXPONENT), R.always('Exponent')],
[R.T, R.always(null)],
])

// eslint-disable-next-line ramda/cond-simplification
export const getScaleParamDefaults = R.cond([
[R.equals(scaleParamId.BASE), R.always(10)], // Default to a `log10` scale function
[R.equals(scaleParamId.EXPONENT), R.always(1)], // Default exponent to 1 (equivalent to `'linear'`)
[R.T, R.always(null)],
])
Expand All @@ -29,7 +29,7 @@ export const getScaleParamDefaults = R.cond([
* @param {Array<any>} range - The output range corresponding to the domain (e.g., [start, end]).
* @param {number} value - The input value to scale.
* @param {string} [scale='linear'] - The type of scale to apply. Supported values: 'linear', 'pow', 'log', 'step'.
* @param {number|{}} [scaleParams={}] - An optional parameter for 'pow' and 'log' scales (exponent for 'pow', base for 'log').
* @param {number|{}} [scaleParams={}] - An optional parameter for scales (exponent for 'pow').
* @param {any} [fallback=null] - The fallback value to return if the input is invalid or unknown.
* @returns {number|any} - The scaled value within the range, or the fallback if the input is invalid.
*
Expand All @@ -49,14 +49,12 @@ export const getScaledValueAlt = R.curry(
? scaleLinear()
: scale === scaleId.STEP
? scaleThreshold()
: scale === scaleId.POW
? scalePow().exponent(
scaleParams.exponent ||
getScaleParamDefaults(scaleParamId.EXPONENT)
)
: scale === scaleId.LOG
? scaleLog().base(
scaleParams.base || getScaleParamDefaults(scaleParamId.BASE)
: scale === scaleId.LOG
? scaleLog()
: scale === scaleId.POW
? scalePow().exponent(
scaleParams.exponent ||
getScaleParamDefaults(scaleParamId.EXPONENT)
)
: () => {
throw new Error(`Invalid scale "${scale}"`)
Expand Down

0 comments on commit 5007bd8

Please sign in to comment.