Skip to content

Commit 7b152bd

Browse files
improve rangeAggs step handling to fix fraction handling
1 parent be26f75 commit 7b152bd

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

modules/components/src/Aggs/RangeAgg.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class RangeAgg extends Component {
167167
return (
168168
formatLabel?.(value, type) ||
169169
formatNumber(
170-
unit && displayUnit
171-
? Math.round(convert(value).from(unit).to(displayUnit) * 100) / 100
170+
unit && displayUnit && unit !== displayUnit
171+
? convert(value).from(unit).to(displayUnit)
172172
: value,
173173
)
174174
);
@@ -180,9 +180,8 @@ class RangeAgg extends Component {
180180
disabled,
181181
displayName = 'Unnamed Field',
182182
fieldName,
183-
rangeStep,
183+
rangeStep: rangeStepFromProps,
184184
stats: { max, min } = emptyObj,
185-
step,
186185
theme: {
187186
colors,
188187
components: {
@@ -229,10 +228,19 @@ class RangeAgg extends Component {
229228
...(type && { 'data-type': type }),
230229
};
231230

231+
const maxFractionRemainder = rangeStepFromProps === 0 && max % 1;
232+
const decimalPointsToPad =
233+
maxFractionRemainder && `${maxFractionRemainder}`.replace('0.', '').length - 1;
234+
const calculatedStep = maxFractionRemainder
235+
? parseFloat(`0.${String(1).padStart(decimalPointsToPad, '0')}`)
236+
: 1;
237+
238+
const rangeStep = rangeStepFromProps || calculatedStep;
239+
232240
const minIsMax = min === max;
233241
const unusable = disabled || min + rangeStep === max || minIsMax;
234242

235-
// TODO: implement unit selection disability per fieldname.
243+
// TODO: implement unit selection disabling per fieldname.
236244
// const enableUnitSelection = !themeDisableUnitSelection;
237245

238246
return (
@@ -370,7 +378,7 @@ class RangeAgg extends Component {
370378
maxValue={max}
371379
onChange={this.setNewValue}
372380
onChangeComplete={this.onChangeComplete}
373-
step={step}
381+
step={rangeStep}
374382
value={currentValues}
375383
/>
376384

modules/server/src/mapping/extendMapping.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const extendFields = (
189189
isArray = false,
190190
primaryKey = false,
191191
quickSearchEnabled = false,
192-
rangeStep = type === 'float' || type === 'double' ? 0.01 : 1,
192+
rangeStep = 0,
193193
unit = null,
194194
} = extendedFromFile.find((customData) => customData.fieldName === fieldName) || {};
195195

0 commit comments

Comments
 (0)