Skip to content

Commit

Permalink
Avoid showing "NaN%" in the charts when there is no prev data
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jun 5, 2024
1 parent 0ec1962 commit c2b8fb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/1443.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid showing "NaN%" in the charts when there is no prev data
3 changes: 3 additions & 0 deletions src/app/components/PercentageGain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ interface PercentageGainProps {
* Negative percentage shows red box with down arrow.
*/
export const PercentageGain: FC<PercentageGainProps> = ({ earliestValue, latestValue }) => {
// If the previous data was zero, we can't divide with it, it would just get us infinity or Nan...
if (earliestValue === 0) return

const ratio = (latestValue - earliestValue) / earliestValue

return (
Expand Down

0 comments on commit c2b8fb8

Please sign in to comment.