Skip to content

Commit

Permalink
refactor: remove custom function and use Math.min
Browse files Browse the repository at this point in the history
  • Loading branch information
rmyz committed Sep 4, 2024
1 parent 9930153 commit f9b3a90
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ const getHistogramRangeSteps = (min: number, max: number, steps: number) => {
return [...Array(steps).keys()].map(logFn.invert).map((d) => (isNaN(d) ? 0 : Math.round(d)));
};

const calculateDefaultDuration = (value: number) => {
return value === 0 ? 1 : value;
};

export const fetchDurationHistogramRangeSteps = async ({
chartType,
apmEventClient,
Expand All @@ -52,8 +48,8 @@ export const fetchDurationHistogramRangeSteps = async ({

if (durationMinOverride && durationMaxOverride) {
// these values should never be 0, so if they are we set them to 1
const durationMin = calculateDefaultDuration(durationMinOverride);
const durationMax = calculateDefaultDuration(durationMaxOverride);
const durationMin = Math.min(1, durationMinOverride);
const durationMax = Math.min(1, durationMaxOverride);

return {
durationMin,
Expand Down Expand Up @@ -109,8 +105,8 @@ export const fetchDurationHistogramRangeSteps = async ({
}

// these values should never be 0, so if they are we set them to 1
const durationMin = calculateDefaultDuration(resp.aggregations.duration_min.value);
const durationMax = calculateDefaultDuration(resp.aggregations.duration_max.value * 2);
const durationMin = Math.min(1, resp.aggregations.duration_min.value);
const durationMax = Math.min(1, resp.aggregations.duration_max.value * 2);

return {
durationMin,
Expand Down

0 comments on commit f9b3a90

Please sign in to comment.