Skip to content

Commit

Permalink
fix: Inoperable dashboard filter slider when range is <= 1 (#27271)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Francos <jfrancos@manifold.ai>
(cherry picked from commit ce9e4b4)
  • Loading branch information
michael-s-molina committed Mar 4, 2024
1 parent 2e80b68 commit 6b82e27
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
}
}, [enableSingleExactValue]);

const MIN_NUM_STEPS = 20;
const stepHeuristic = (min: number, max: number) => {
const maxStepSize = (max - min) / MIN_NUM_STEPS;
// normalizedStepSize: .06 -> .01, .003 -> .001
const normalizedStepSize = `1E${Math.floor(Math.log10(maxStepSize))}`;
return Math.min(1, parseFloat(normalizedStepSize));
};

const step = max - min <= 1 ? stepHeuristic(min, max) : 1;

return (
<FilterPluginStyle height={height} width={width}>
{Number.isNaN(Number(min)) || Number.isNaN(Number(max)) ? (
Expand All @@ -323,6 +333,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
<AntdSlider
min={min}
max={max}
step={step}
value={minMax[maxIndex]}
tipFormatter={tipFormatter}
marks={marks}
Expand All @@ -335,6 +346,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
validateStatus={filterState.validateStatus}
min={min}
max={max}
step={step}
value={minMax[minIndex]}
tipFormatter={tipFormatter}
marks={marks}
Expand All @@ -346,6 +358,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
<AntdSlider
min={min}
max={max}
step={step}
included={false}
value={minMax[minIndex]}
tipFormatter={tipFormatter}
Expand All @@ -359,6 +372,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
range
min={min}
max={max}
step={step}
value={minMax}
onAfterChange={handleAfterChange}
onChange={handleChange}
Expand Down

0 comments on commit 6b82e27

Please sign in to comment.