Skip to content

Commit

Permalink
improve rangeAggs step handling to fix fraction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
justincorrigible committed Nov 7, 2024
1 parent be26f75 commit 7b152bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions modules/components/src/Aggs/RangeAgg.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ class RangeAgg extends Component {
return (
formatLabel?.(value, type) ||
formatNumber(
unit && displayUnit
? Math.round(convert(value).from(unit).to(displayUnit) * 100) / 100
unit && displayUnit && unit !== displayUnit
? convert(value).from(unit).to(displayUnit)
: value,
)
);
Expand All @@ -180,9 +180,8 @@ class RangeAgg extends Component {
disabled,
displayName = 'Unnamed Field',
fieldName,
rangeStep,
rangeStep: rangeStepFromProps,
stats: { max, min } = emptyObj,
step,
theme: {
colors,
components: {
Expand Down Expand Up @@ -229,10 +228,19 @@ class RangeAgg extends Component {
...(type && { 'data-type': type }),
};

const maxFractionRemainder = rangeStepFromProps === 0 && max % 1;
const decimalPointsToPad =
maxFractionRemainder && `${maxFractionRemainder}`.replace('0.', '').length - 1;
const calculatedStep = maxFractionRemainder
? parseFloat(`0.${String(1).padStart(decimalPointsToPad, '0')}`)
: 1;

const rangeStep = rangeStepFromProps || calculatedStep;

const minIsMax = min === max;
const unusable = disabled || min + rangeStep === max || minIsMax;

// TODO: implement unit selection disability per fieldname.
// TODO: implement unit selection disabling per fieldname.
// const enableUnitSelection = !themeDisableUnitSelection;

return (
Expand Down Expand Up @@ -370,7 +378,7 @@ class RangeAgg extends Component {
maxValue={max}
onChange={this.setNewValue}
onChangeComplete={this.onChangeComplete}
step={step}
step={rangeStep}
value={currentValues}
/>

Expand Down
2 changes: 1 addition & 1 deletion modules/server/src/mapping/extendMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const extendFields = (
isArray = false,
primaryKey = false,
quickSearchEnabled = false,
rangeStep = type === 'float' || type === 'double' ? 0.01 : 1,
rangeStep = 0,
unit = null,
} = extendedFromFile.find((customData) => customData.fieldName === fieldName) || {};

Expand Down

0 comments on commit 7b152bd

Please sign in to comment.