Skip to content

Commit

Permalink
Fix decimals in diff. flamegraph tooltips (#178524)
Browse files Browse the repository at this point in the history
In the differential flamegraph tooltips, comparison integer values are
shown with decimal digits. This PR fixes it.
  • Loading branch information
rockdaboot authored Mar 13, 2024
1 parent 0959783 commit b3064ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useCalculateImpactEstimate } from '../../hooks/use_calculate_impact_est
import { asCost } from '../../utils/formatters/as_cost';
import { asPercentage } from '../../utils/formatters/as_percentage';
import { asWeight } from '../../utils/formatters/as_weight';
import { asInteger } from '../../utils/formatters/as_integer';
import { CPULabelWithHint } from '../cpu_label_with_hint';
import { TooltipRow } from './tooltip_row';

Expand Down Expand Up @@ -171,6 +172,7 @@ export function FlameGraphTooltip({
? comparisonCountInclusive * comparisonScaleFactor
: undefined
}
formatValue={asInteger}
showDifference
formatDifferenceAsPercentage={false}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { asInteger } from './as_integer';

describe('asInteger', () => {
it('rounds numbers appropriately', () => {
expect(asInteger(999)).toBe('999');

expect(asInteger(1.11)).toBe('1');

expect(asInteger(1.5)).toBe('2');

expect(asInteger(0.001)).toBe('0');

expect(asInteger(0)).toBe('0');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export function asInteger(value: number) {
return Math.round(value).toString();
}

0 comments on commit b3064ba

Please sign in to comment.