Spaces:
Runtime error
Runtime error
monthly visualization
Browse files
src/lib/components/result/space/Space.svelte
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
<Author author={data?.author} />
|
21 |
{/if}
|
22 |
{#if data?.likers}
|
23 |
-
<Likers likers={data?.likers} />
|
24 |
{/if}
|
25 |
{#if data?.runtime}
|
26 |
<Runtime runtime={data?.runtime} />
|
|
|
20 |
<Author author={data?.author} />
|
21 |
{/if}
|
22 |
{#if data?.likers}
|
23 |
+
<Likers likers={data?.likers} type={data?.likers_type} />
|
24 |
{/if}
|
25 |
{#if data?.runtime}
|
26 |
<Runtime runtime={data?.runtime} />
|
src/lib/components/result/space/likers/Likers.svelte
CHANGED
@@ -5,6 +5,7 @@
|
|
5 |
import type { Liker } from "$lib/types";
|
6 |
|
7 |
export let likers: Record<string, Array<Liker>>;
|
|
|
8 |
|
9 |
let tab: "data-visualization" | "global" = "global";
|
10 |
const tabs = [{
|
@@ -21,9 +22,17 @@
|
|
21 |
tab = id as "data-visualization" | "global"
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
const options: EChartsOptions = {
|
25 |
xAxis: {
|
26 |
-
data: Object.keys(likers ?? []),
|
27 |
type: 'category',
|
28 |
},
|
29 |
yAxis: {
|
@@ -79,23 +88,31 @@
|
|
79 |
{/each}
|
80 |
</div>
|
81 |
{#if tab === "global"}
|
82 |
-
<div class="">
|
83 |
-
{#each Object.keys(likers ?? []) as
|
84 |
-
<
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
<
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
</div>
|
98 |
-
|
99 |
</div>
|
100 |
{:else}
|
101 |
<div class="h-[380px] -mx-8 -my-8">
|
|
|
5 |
import type { Liker } from "$lib/types";
|
6 |
|
7 |
export let likers: Record<string, Array<Liker>>;
|
8 |
+
export let likers_type: string;
|
9 |
|
10 |
let tab: "data-visualization" | "global" = "global";
|
11 |
const tabs = [{
|
|
|
22 |
tab = id as "data-visualization" | "global"
|
23 |
}
|
24 |
|
25 |
+
const formatNumberMonth = (num: number) => {
|
26 |
+
const months = [
|
27 |
+
"January", "February", "March", "April", "May", "June", "July", "August", "September",
|
28 |
+
"October", "November", "December"
|
29 |
+
];
|
30 |
+
return months[num - 1];
|
31 |
+
}
|
32 |
+
|
33 |
const options: EChartsOptions = {
|
34 |
xAxis: {
|
35 |
+
data: likers_type === 'years' ? Object.keys(likers ?? []) : Object.keys(likers ?? []).map((key) => formatNumberMonth(parseInt(key))),
|
36 |
type: 'category',
|
37 |
},
|
38 |
yAxis: {
|
|
|
88 |
{/each}
|
89 |
</div>
|
90 |
{#if tab === "global"}
|
91 |
+
<div class="grid grid-cols-1 gap-4">
|
92 |
+
{#each Object.keys(likers ?? []) as period}
|
93 |
+
<div>
|
94 |
+
<p class="uppercase text-zinc-600 dark:text-zinc-400 font-semibold font-title text-sm mb-3">
|
95 |
+
{#if likers_type === "year"}
|
96 |
+
{period}
|
97 |
+
{:else}
|
98 |
+
{formatNumberMonth(parseInt(period))}
|
99 |
+
{/if}
|
100 |
+
</p>
|
101 |
+
<div class="flex items-center flex-wrap">
|
102 |
+
{#each likers[period].slice(0, 100) as like}
|
103 |
+
<div class="flex items-center -mr-1.5 -mt-1.5 relative cursor-pointer group">
|
104 |
+
<img src={like.avatarUrl.includes(".svg") ? `https://huggingface.co${like.avatarUrl}` : like.avatarUrl} alt={like.fullname} class="w-8 h-8 rounded-full ring-[1px] ring-white dark:ring-zinc-900" />
|
105 |
+
<p class="font-title absolute left-full top-0 bg-zinc-100 shadow rounded px-2 py-0.5 text-zinc-600 text-xs opacity-0 group-hover:opacity-100 pointer-events-none z-10 whitespace-nowrap translate-y-1/2">{like.fullname}</p>
|
106 |
+
</div>
|
107 |
+
{/each}
|
108 |
+
{#if likers[period].length > 100}
|
109 |
+
<div class="w-8 h-8 flex items-center justify-center border rounded-full border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 z-10">
|
110 |
+
<p class="text-xs font-title text-zinc-700">+{formatBigNumber(likers[period].length - 15)}</p>
|
111 |
+
</div>
|
112 |
+
{/if}
|
113 |
+
</div>
|
114 |
</div>
|
115 |
+
{/each}
|
116 |
</div>
|
117 |
{:else}
|
118 |
<div class="h-[380px] -mx-8 -my-8">
|
src/routes/api/search/+server.ts
CHANGED
@@ -31,6 +31,8 @@ export async function POST({ request }: RequestEvent) {
|
|
31 |
dataAuthor = null
|
32 |
}
|
33 |
|
|
|
|
|
34 |
const responseLikers = await fetch(`${env.PUBLIC_API_URL}/${body.namespace}/${body.repoId}/likers?expand[]=likeAt`, {
|
35 |
method: "GET",
|
36 |
headers: {
|
@@ -43,7 +45,7 @@ export async function POST({ request }: RequestEvent) {
|
|
43 |
throw error(responseLikers.status, dataLikers.error);
|
44 |
}
|
45 |
|
46 |
-
|
47 |
dataLikers.forEach((liker: Liker) => {
|
48 |
const year = liker.likedAt.split("-")[0]
|
49 |
if (!likers[year]) {
|
@@ -52,6 +54,18 @@ export async function POST({ request }: RequestEvent) {
|
|
52 |
likers[year].push(liker)
|
53 |
})
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
const formattedData = {
|
57 |
...data,
|
@@ -67,6 +81,7 @@ export async function POST({ request }: RequestEvent) {
|
|
67 |
bgTo: colors[data?.cardData?.colorTo as keyof typeof colors]?.primary ?? "bg-blue-600",
|
68 |
},
|
69 |
likers,
|
|
|
70 |
}
|
71 |
|
72 |
return json(formattedData);
|
|
|
31 |
dataAuthor = null
|
32 |
}
|
33 |
|
34 |
+
let likers_type = "yearly";
|
35 |
+
|
36 |
const responseLikers = await fetch(`${env.PUBLIC_API_URL}/${body.namespace}/${body.repoId}/likers?expand[]=likeAt`, {
|
37 |
method: "GET",
|
38 |
headers: {
|
|
|
45 |
throw error(responseLikers.status, dataLikers.error);
|
46 |
}
|
47 |
|
48 |
+
let likers: Record<string, Liker[]> = {}
|
49 |
dataLikers.forEach((liker: Liker) => {
|
50 |
const year = liker.likedAt.split("-")[0]
|
51 |
if (!likers[year]) {
|
|
|
54 |
likers[year].push(liker)
|
55 |
})
|
56 |
|
57 |
+
if (Object.keys(likers).length < 2) {
|
58 |
+
likers_type = "monthly";
|
59 |
+
likers = {}
|
60 |
+
dataLikers.forEach((liker: Liker) => {
|
61 |
+
const month = liker.likedAt.split("-")[1]
|
62 |
+
if (!likers[month]) {
|
63 |
+
likers[month] = []
|
64 |
+
}
|
65 |
+
likers[month].push(liker)
|
66 |
+
})
|
67 |
+
}
|
68 |
+
|
69 |
|
70 |
const formattedData = {
|
71 |
...data,
|
|
|
81 |
bgTo: colors[data?.cardData?.colorTo as keyof typeof colors]?.primary ?? "bg-blue-600",
|
82 |
},
|
83 |
likers,
|
84 |
+
likers_type,
|
85 |
}
|
86 |
|
87 |
return json(formattedData);
|