From 96ba69c37b55b5fc056db997b68b92a208ace66d Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 18 May 2022 16:16:43 +0000 Subject: add coin units to auction graphs --- src/lib/AuctionPriceScatterplot.svelte | 19 ++++++++++++++++++- src/lib/api.ts | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/AuctionPriceScatterplot.svelte b/src/lib/AuctionPriceScatterplot.svelte index f430edd..42fb6f1 100644 --- a/src/lib/AuctionPriceScatterplot.svelte +++ b/src/lib/AuctionPriceScatterplot.svelte @@ -12,7 +12,7 @@ let hoursBetween = (currentTimestamp - earliestTimestamp) / (60 * 60) const gridWidth = 100 / hoursBetween - let heightCoinInterval = Math.pow(10, Math.floor(Math.log10(maxCoins / 2))) + let heightCoinInterval = Math.ceil(Math.pow(10, Math.floor(Math.log10(maxCoins / 2)))) const gridHeight = 100 / (maxCoins / heightCoinInterval) @@ -52,6 +52,14 @@ } } else currentlyPreviewedAuction = null } + + function shortenBigNumber(n: number) { + if (n < 1000) return n + if (n < 1_000_000) return parseFloat((n / 1000).toPrecision(2)).toLocaleString() + 'k' + if (n < 1_000_000_000) return parseFloat((n / 1_000_000).toPrecision(2)).toLocaleString() + 'M' + if (n < 1_000_000_000_000) + return parseFloat((n / 1_000_000_000).toPrecision(2)).toLocaleString() + 'B' + } {#if item.auctions.length > 0} @@ -73,6 +81,15 @@ /> + {#each new Array(Math.floor(maxCoins / heightCoinInterval) + 1) as _, intervalIndex} + {shortenBigNumber(heightCoinInterval * intervalIndex)} + {/each}