Skip to content

Commit

Permalink
Merge pull request #3362 from parca-dev/flamegraph-crash-fix
Browse files Browse the repository at this point in the history
ui: Flamegraph crash fix
  • Loading branch information
brancz authored Jun 26, 2023
2 parents 23121da + ae57551 commit 194305d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ui/packages/shared/utilities/src/bigint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ describe('bigint scaleLinear', () => {
expect(scale(0n)).toBe(0);
expect(scale(20n)).toBe(10);
});

it('scale works with decimal values to range', () => {
const scale = scaleLinear([0n, 100n], [0, 51.5]);
expect(scale(50n)).toBe(25.5);
expect(scale(100n)).toBe(51);
expect(scale(0n)).toBe(0);
expect(scale(20n)).toBe(10.2);
});
});
2 changes: 1 addition & 1 deletion ui/packages/shared/utilities/src/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const scaleLinear = (
const [domainMin, domainMax] = domain;
const [rangeMin, rangeMax] = range;
const domainRange = domainMax - domainMin;
const rangeRange = BigInt(rangeMax - rangeMin);
const rangeRange = BigInt(Math.floor(rangeMax - rangeMin));

// rate * 100000 to retain the decimal places in BigInt format, then divide by 100000 to get the final result
const multiple = 100000;
Expand Down

0 comments on commit 194305d

Please sign in to comment.