aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AuctionPriceScatterplot.svelte
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-18 16:16:43 +0000
committermat <github@matdoes.dev>2022-05-18 16:16:43 +0000
commit96ba69c37b55b5fc056db997b68b92a208ace66d (patch)
treed0dd599703d71bc6a4d93a3e5017f5a14a5a0bb9 /src/lib/AuctionPriceScatterplot.svelte
parent5fd8b696b9b9e76785817075cacdec58a900f388 (diff)
downloadskyblock-stats-96ba69c37b55b5fc056db997b68b92a208ace66d.tar.gz
skyblock-stats-96ba69c37b55b5fc056db997b68b92a208ace66d.tar.bz2
skyblock-stats-96ba69c37b55b5fc056db997b68b92a208ace66d.zip
add coin units to auction graphs
Diffstat (limited to 'src/lib/AuctionPriceScatterplot.svelte')
-rw-r--r--src/lib/AuctionPriceScatterplot.svelte19
1 files changed, 18 insertions, 1 deletions
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'
+ }
</script>
{#if item.auctions.length > 0}
@@ -73,6 +81,15 @@
/>
</pattern>
</defs>
+ {#each new Array(Math.floor(maxCoins / heightCoinInterval) + 1) as _, intervalIndex}
+ <text
+ x="-1"
+ y={Math.max(5, 100 - intervalIndex * gridHeight + 2)}
+ fill="var(--theme-darker-text)"
+ font-size="6px"
+ text-anchor="end">{shortenBigNumber(heightCoinInterval * intervalIndex)}</text
+ >
+ {/each}
<rect
width="100%"
height="100%"