Skip to content

Commit

Permalink
feat(app): get data for chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool committed Jul 2, 2024
1 parent f68c91e commit 40b12ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
15 changes: 15 additions & 0 deletions app/src/lib/queries/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createQuery } from "@tanstack/svelte-query";
import { transferCountQueryDocument, transfersPerDayQueryDocument } from "$lib/graphql/documents/stats.ts";

import { request } from "graphql-request"
import { URLS } from "$lib/constants"

export const transferPerDayQuery = () =>
createQuery({
queryKey: ["transfers"],
queryFn: async () => (await request(URLS.GRAPHQL, transfersPerDayQueryDocument, { limit: 24 })).v0_daily_transfers
,
enabled: true,
refetchInterval: 6_000,
refetchOnWindowFocus: false
})
50 changes: 28 additions & 22 deletions app/src/routes/explorer/(components)/pixel-graph.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<script lang="ts">
import * as Tooltip from "$lib/components/ui/tooltip"
export let data: Array<{ value: number; date: Date }>
const minValue = Math.min(...data.map(d => d.value))
const maxValue = Math.max(...data.map(d => d.value))
function normalize(
value: number,
min: number,
max: number,
newMin: number,
newMax: number
): number {
return ((value - min) / (max - min)) * (newMax - newMin) + newMin
}
const normalizedData = data.map(d => ({
...d,
normalizedValue: Math.floor(normalize(d.value, minValue, maxValue, 0, 9))
}))
import * as Tooltip from "$lib/components/ui/tooltip"
export let data: Array<{ count: number; day: Date }>
const minValue = Math.min(...data.map(d => d.count))
const maxValue = Math.max(...data.map(d => d.count))
function normalize(
value: number,
min: number,
max: number,
newMin: number,
newMax: number
): number {
return ((value - min) / (max - min)) * (newMax - newMin) + newMin
}
const normalizedData = data.map(d => ({
...d,
normalizedValue: Math.floor(normalize(d.count, minValue, maxValue, 0, 9))
}))
</script>

<div class="flex items-end gap-[2.5px] p-5">
Expand All @@ -34,7 +36,11 @@ const normalizedData = data.map(d => ({
</div>
</Tooltip.Trigger>
<Tooltip.Content>
{data.normalizedValue}
{#if data.day && data.count}
{new Date(data.day).toISOString().slice(0, 10)}
<br/>
{data.count}
{/if}
</Tooltip.Content>
</Tooltip.Root>
{/each}
Expand Down

0 comments on commit 40b12ac

Please sign in to comment.